Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
cb6bc3b0
Commit
cb6bc3b0
authored
Oct 10, 2014
by
jsa
Committed by
E. Kolpakov
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copied test specs
parent
70067eb6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
247 additions
and
14 deletions
+247
-14
common/static/coffee/spec/discussion/.gitignore
+2
-0
common/static/coffee/spec/discussion/discussion_spec_helper.coffee
+0
-0
common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee
+0
-0
common/static/coffee/spec/discussion/view/discussion_thread_show_view_spec.coffee
+15
-0
common/static/coffee/spec/discussion/view/discussion_thread_view_spec.coffee
+62
-3
common/static/coffee/spec/discussion/view/discussion_topic_menu_view_spec.js
+125
-0
common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee
+1
-0
common/static/coffee/spec/discussion/view/new_post_view_spec.coffee
+0
-0
common/static/coffee/spec/discussion/view/response_comment_view_spec.coffee
+7
-9
common/static/coffee/spec/discussion/view/thread_response_show_view_spec.coffee
+4
-0
common/static/coffee/spec/discussion/view/thread_response_view_spec.coffee
+31
-2
No files found.
common/static/coffee/spec/discussion/.gitignore
0 → 100644
View file @
cb6bc3b0
!view/discussion_thread_edit_view_spec.js
!view/discussion_topic_menu_view_spec.js
common/static/coffee/spec/discussion/discussion_spec_helper.coffee
View file @
cb6bc3b0
This diff is collapsed.
Click to expand it.
common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee
View file @
cb6bc3b0
This diff is collapsed.
Click to expand it.
common/static/coffee/spec/discussion/view/discussion_thread_show_view_spec.coffee
View file @
cb6bc3b0
...
...
@@ -142,3 +142,18 @@ describe "DiscussionThreadShowView", ->
$el
=
$
(
'#fixture-element'
).
html
(
@
view
.
getAuthorDisplay
())
expect
(
$el
.
find
(
'a.username'
).
length
).
toEqual
(
0
)
expect
(
$el
.
text
()).
toMatch
(
/^(\s*)anonymous(\s*)$/
)
describe
"cohorting"
,
->
it
"renders correctly for an uncohorted thread"
,
->
@
view
.
render
()
expect
(
@
view
.
$
(
'.group-visibility-label'
).
text
().
trim
()).
toEqual
(
'This post is visible to everyone.'
)
it
"renders correctly for a cohorted thread"
,
->
@
thread
.
set
(
'group_id'
,
'1'
)
@
thread
.
set
(
'group_name'
,
'Mock Cohort'
)
@
view
.
render
()
expect
(
@
view
.
$
(
'.group-visibility-label'
).
text
().
trim
()).
toEqual
(
'This post is visible only to Mock Cohort.'
)
common/static/coffee/spec/discussion/view/discussion_thread_view_spec.coffee
View file @
cb6bc3b0
...
...
@@ -6,10 +6,12 @@ describe "DiscussionThreadView", ->
jasmine
.
Clock
.
useMock
()
@
threadData
=
DiscussionViewSpecHelper
.
makeThreadWithProps
({})
@
thread
=
new
Thread
(
@
threadData
)
@
discussion
=
new
Discussion
(
@
thread
)
spyOn
(
$
,
"ajax"
)
# Avoid unnecessary boilerplate
spyOn
(
DiscussionThreadShowView
.
prototype
,
"convertMath"
)
spyOn
(
DiscussionContentView
.
prototype
,
"makeWmdEditor"
)
spyOn
(
DiscussionUtil
,
"makeWmdEditor"
)
spyOn
(
ThreadResponseView
.
prototype
,
"renderShowView"
)
renderWithContent
=
(
view
,
content
)
->
...
...
@@ -40,9 +42,46 @@ describe "DiscussionThreadView", ->
else
expect
(
view
.
$el
.
find
(
".load-response-button"
).
length
).
toEqual
(
0
)
describe
"closed and open Threads"
,
->
checkCommentForm
=
(
originallyClosed
,
mode
)
->
threadData
=
DiscussionViewSpecHelper
.
makeThreadWithProps
({
closed
:
originallyClosed
})
thread
=
new
Thread
(
threadData
)
discussion
=
new
Discussion
(
thread
)
view
=
new
DiscussionThreadView
(
model
:
thread
el
:
$
(
"#fixture-element"
)
mode
:
mode
course_settings
:
DiscussionSpecHelper
.
makeCourseSettings
()
)
renderWithContent
(
view
,
{
resp_total
:
1
,
children
:
[{}]})
if
mode
==
"inline"
view
.
expand
()
spyOn
(
DiscussionUtil
,
"updateWithUndo"
).
andCallFake
(
(
model
,
updates
,
safeAjaxParams
,
errorMsg
)
->
model
.
set
(
updates
)
)
expect
(
view
.
$
(
'.comment-form'
).
closest
(
'li'
).
is
(
":visible"
)).
toBe
(
not
originallyClosed
)
expect
(
view
.
$
(
".discussion-reply-new"
).
is
(
":visible"
)).
toBe
(
not
originallyClosed
)
view
.
$
(
".action-close"
).
click
()
expect
(
view
.
$
(
'.comment-form'
).
closest
(
'li'
).
is
(
":visible"
)).
toBe
(
originallyClosed
)
expect
(
view
.
$
(
".discussion-reply-new"
).
is
(
":visible"
)).
toBe
(
originallyClosed
)
_
.
each
([
"tab"
,
"inline"
],
(
mode
)
=>
it
'Test that in #{mode} mode when a closed thread is opened the comment form is displayed'
,
->
checkCommentForm
(
true
,
mode
)
it
'Test that in #{mode} mode when a open thread is closed the comment form is hidden'
,
->
checkCommentForm
(
false
,
mode
)
)
describe
"tab mode"
,
->
beforeEach
->
@
view
=
new
DiscussionThreadView
({
model
:
@
thread
,
el
:
$
(
"#fixture-element"
),
mode
:
"tab"
})
@
view
=
new
DiscussionThreadView
(
model
:
@
thread
el
:
$
(
"#fixture-element"
)
mode
:
"tab"
course_settings
:
DiscussionSpecHelper
.
makeCourseSettings
()
)
describe
"response count and pagination"
,
->
it
"correctly render for a thread with no responses"
,
->
...
...
@@ -83,7 +122,12 @@ describe "DiscussionThreadView", ->
describe
"inline mode"
,
->
beforeEach
->
@
view
=
new
DiscussionThreadView
({
model
:
@
thread
,
el
:
$
(
"#fixture-element"
),
mode
:
"inline"
})
@
view
=
new
DiscussionThreadView
(
model
:
@
thread
el
:
$
(
"#fixture-element"
)
mode
:
"inline"
course_settings
:
DiscussionSpecHelper
.
makeCourseSettings
()
)
describe
"render"
,
->
it
"shows content that should be visible when collapsed"
,
->
...
...
@@ -150,11 +194,26 @@ describe "DiscussionThreadView", ->
expect
(
$
(
".post-body"
).
text
()).
toEqual
(
maliciousAbbreviation
)
expect
(
$
(
".post-body"
).
html
()).
not
.
toContain
(
"<script"
)
it
"re-renders the show view correctly when leaving the edit view"
,
->
DiscussionViewSpecHelper
.
setNextResponseContent
({
resp_total
:
0
,
children
:
[]})
@
view
.
render
()
@
view
.
expand
()
assertExpandedContentVisible
(
@
view
,
true
)
@
view
.
edit
()
assertContentVisible
(
@
view
,
".edit-post-body"
,
true
)
expect
(
@
view
.
$el
.
find
(
".post-actions-list"
).
length
).
toBe
(
0
)
@
view
.
closeEditView
(
DiscussionSpecHelper
.
makeEventSpy
())
expect
(
@
view
.
$el
.
find
(
".edit-post-body"
).
length
).
toBe
(
0
)
assertContentVisible
(
@
view
,
".post-actions-list"
,
true
)
describe
"for question threads"
,
->
beforeEach
->
@
thread
.
set
(
"thread_type"
,
"question"
)
@
view
=
new
DiscussionThreadView
(
{
model
:
@
thread
,
el
:
$
(
"#fixture-element"
),
mode
:
"tab"
}
model
:
@
thread
el
:
$
(
"#fixture-element"
)
mode
:
"tab"
course_settings
:
DiscussionSpecHelper
.
makeCourseSettings
()
)
renderTestCase
=
(
view
,
numEndorsed
,
numNonEndorsed
)
->
...
...
common/static/coffee/spec/discussion/view/discussion_topic_menu_view_spec.js
0 → 100644
View file @
cb6bc3b0
(
function
()
{
'use strict'
;
describe
(
'DiscussionTopicMenuView'
,
function
()
{
beforeEach
(
function
()
{
this
.
createTopicView
=
function
(
options
)
{
options
=
_
.
extend
({
course_settings
:
this
.
course_settings
,
topicId
:
void
0
},
options
);
this
.
view
=
new
DiscussionTopicMenuView
(
options
);
this
.
view
.
render
().
appendTo
(
'#fixture-element'
);
this
.
defaultTextWidth
=
this
.
view
.
getNameWidth
(
this
.
completeText
);
};
this
.
openMenu
=
function
()
{
var
menuWrapper
=
this
.
view
.
$
(
'.topic-menu-wrapper'
);
expect
(
menuWrapper
).
toBeHidden
();
this
.
view
.
$el
.
find
(
'.post-topic-button'
).
first
().
click
();
expect
(
menuWrapper
).
toBeVisible
();
};
this
.
closeMenu
=
function
()
{
var
menuWrapper
=
this
.
view
.
$
(
'.topic-menu-wrapper'
);
expect
(
menuWrapper
).
toBeVisible
();
this
.
view
.
$el
.
find
(
'.post-topic-button'
).
first
().
click
();
expect
(
menuWrapper
).
toBeHidden
();
};
DiscussionSpecHelper
.
setUpGlobals
();
DiscussionSpecHelper
.
setUnderscoreFixtures
();
this
.
course_settings
=
new
DiscussionCourseSettings
({
'category_map'
:
{
'subcategories'
:
{
'Basic Question Types'
:
{
'subcategories'
:
{},
'children'
:
[
'Selection From Options'
,
'Numerical Input'
],
'entries'
:
{
'Selection From Options'
:
{
'sort_key'
:
null
,
'is_cohorted'
:
true
,
'id'
:
'cba3e4cd91d0466b9ac50926e495b76f'
},
'Numerical Input'
:
{
'sort_key'
:
null
,
'is_cohorted'
:
false
,
'id'
:
'c49f0dfb8fc94c9c8d9999cc95190c56'
}
}
}
},
'children'
:
[
'Basic Question Types'
],
'entries'
:
{}
},
'is_cohorted'
:
true
});
this
.
parentCategoryText
=
'Basic Question Types'
;
this
.
selectedOptionText
=
'Selection From Options'
;
this
.
completeText
=
this
.
parentCategoryText
+
' / '
+
this
.
selectedOptionText
;
});
it
(
'completely show parent category and sub-category'
,
function
()
{
var
dropdownText
;
this
.
createTopicView
();
this
.
view
.
maxNameWidth
=
this
.
defaultTextWidth
+
1
;
this
.
view
.
$el
.
find
(
'a.topic-title'
).
first
().
click
();
dropdownText
=
this
.
view
.
$el
.
find
(
'.js-selected-topic'
).
text
();
expect
(
this
.
completeText
).
toEqual
(
dropdownText
);
});
it
(
'completely show just sub-category'
,
function
()
{
var
dropdownText
;
this
.
createTopicView
();
this
.
view
.
maxNameWidth
=
this
.
defaultTextWidth
-
10
;
this
.
view
.
$el
.
find
(
'a.topic-title'
).
first
().
click
();
dropdownText
=
this
.
view
.
$el
.
find
(
'.js-selected-topic'
).
text
();
expect
(
dropdownText
.
indexOf
(
'…'
)).
toEqual
(
0
);
expect
(
dropdownText
).
toContain
(
this
.
selectedOptionText
);
});
it
(
'partially show sub-category'
,
function
()
{
this
.
createTopicView
();
var
parentWidth
=
this
.
view
.
getNameWidth
(
this
.
parentCategoryText
),
dropdownText
;
this
.
view
.
maxNameWidth
=
this
.
defaultTextWidth
-
parentWidth
;
this
.
view
.
$el
.
find
(
'a.topic-title'
).
first
().
click
();
dropdownText
=
this
.
view
.
$el
.
find
(
'.js-selected-topic'
).
text
();
expect
(
dropdownText
.
indexOf
(
'…'
)).
toEqual
(
0
);
expect
(
dropdownText
.
lastIndexOf
(
'…'
)).
toBeGreaterThan
(
0
);
});
it
(
'broken span doesn
\'
t occur'
,
function
()
{
var
dropdownText
;
this
.
createTopicView
();
this
.
view
.
maxNameWidth
=
this
.
view
.
getNameWidth
(
this
.
selectedOptionText
)
+
100
;
this
.
view
.
$el
.
find
(
'a.topic-title'
).
first
().
click
();
dropdownText
=
this
.
view
.
$el
.
find
(
'.js-selected-topic'
).
text
();
expect
(
dropdownText
.
indexOf
(
'/ span>'
)).
toEqual
(
-
1
);
});
it
(
'appropriate topic is selected if `topicId` is passed'
,
function
()
{
var
completeText
=
this
.
parentCategoryText
+
' / Numerical Input'
,
dropdownText
;
this
.
createTopicView
({
topicId
:
'c49f0dfb8fc94c9c8d9999cc95190c56'
});
this
.
view
.
maxNameWidth
=
this
.
defaultTextWidth
+
1
;
this
.
view
.
render
();
dropdownText
=
this
.
view
.
$el
.
find
(
'.js-selected-topic'
).
text
();
expect
(
completeText
).
toEqual
(
dropdownText
);
});
it
(
'click outside of the dropdown close it'
,
function
()
{
this
.
createTopicView
();
this
.
openMenu
();
$
(
document
.
body
).
click
();
expect
(
this
.
view
.
$
(
'.topic-menu-wrapper'
)).
toBeHidden
();
});
it
(
'can toggle the menu'
,
function
()
{
this
.
createTopicView
();
this
.
openMenu
();
this
.
closeMenu
();
});
});
}).
call
(
this
);
common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee
View file @
cb6bc3b0
...
...
@@ -7,6 +7,7 @@ class @DiscussionViewSpecHelper
pinned
:
false
,
endorsed
:
false
,
votes
:
{
up_count
:
'0'
},
read
:
false
,
unread_comments_count
:
0
,
comments_count
:
0
,
abuse_flaggers
:
[],
...
...
common/static/coffee/spec/discussion/view/new_post_view_spec.coffee
View file @
cb6bc3b0
This diff is collapsed.
Click to expand it.
common/static/coffee/spec/discussion/view/response_comment_view_spec.coffee
View file @
cb6bc3b0
...
...
@@ -17,12 +17,10 @@ describe 'ResponseCommentView', ->
spyOn
(
DiscussionUtil
,
"makeWmdEditor"
)
@
view
.
render
()
makeEventSpy
=
()
->
jasmine
.
createSpyObj
(
'event'
,
[
'preventDefault'
,
'target'
])
describe
'_delete'
,
->
beforeEach
->
@
comment
.
updateInfo
{
ability
:
{
can_delete
:
true
}}
@
event
=
makeEventSpy
()
@
event
=
DiscussionSpecHelper
.
makeEventSpy
()
spyOn
(
@
comment
,
"remove"
)
spyOn
(
@
view
.
$el
,
"remove"
)
...
...
@@ -81,9 +79,9 @@ describe 'ResponseCommentView', ->
# Without calling renderEditView first, renderShowView is a no-op
@
view
.
renderEditView
()
@
view
.
renderShowView
()
@
view
.
showView
.
trigger
"comment:_delete"
,
makeEventSpy
()
@
view
.
showView
.
trigger
"comment:_delete"
,
DiscussionSpecHelper
.
makeEventSpy
()
expect
(
@
view
.
_delete
).
toHaveBeenCalled
()
@
view
.
showView
.
trigger
"comment:edit"
,
makeEventSpy
()
@
view
.
showView
.
trigger
"comment:edit"
,
DiscussionSpecHelper
.
makeEventSpy
()
expect
(
@
view
.
edit
).
toHaveBeenCalled
()
expect
(
@
view
.
$
(
".edit-post-form#comment_
#{
@
comment
.
id
}
"
)).
not
.
toHaveClass
(
"edit-post-form"
)
...
...
@@ -92,9 +90,9 @@ describe 'ResponseCommentView', ->
spyOn
(
@
view
,
"update"
)
spyOn
(
@
view
,
"cancelEdit"
)
@
view
.
renderEditView
()
@
view
.
editView
.
trigger
"comment:update"
,
makeEventSpy
()
@
view
.
editView
.
trigger
"comment:update"
,
DiscussionSpecHelper
.
makeEventSpy
()
expect
(
@
view
.
update
).
toHaveBeenCalled
()
@
view
.
editView
.
trigger
"comment:cancel_edit"
,
makeEventSpy
()
@
view
.
editView
.
trigger
"comment:cancel_edit"
,
DiscussionSpecHelper
.
makeEventSpy
()
expect
(
@
view
.
cancelEdit
).
toHaveBeenCalled
()
expect
(
@
view
.
$
(
".edit-post-form#comment_
#{
@
comment
.
id
}
"
)).
toHaveClass
(
"edit-post-form"
)
...
...
@@ -138,7 +136,7 @@ describe 'ResponseCommentView', ->
it
'calls the update endpoint correctly and displays the show view on success'
,
->
@
ajaxSucceed
=
true
@
view
.
update
(
makeEventSpy
())
@
view
.
update
(
DiscussionSpecHelper
.
makeEventSpy
())
expect
(
$
.
ajax
).
toHaveBeenCalled
()
expect
(
$
.
ajax
.
mostRecentCall
.
args
[
0
].
url
.
_parts
.
path
).
toEqual
(
'/courses/edX/999/test/discussion/comments/01234567/update'
)
expect
(
$
.
ajax
.
mostRecentCall
.
args
[
0
].
data
.
body
).
toEqual
(
@
updatedBody
)
...
...
@@ -148,7 +146,7 @@ describe 'ResponseCommentView', ->
it
'handles AJAX errors'
,
->
originalBody
=
@
comment
.
get
(
"body"
)
@
ajaxSucceed
=
false
@
view
.
update
(
makeEventSpy
())
@
view
.
update
(
DiscussionSpecHelper
.
makeEventSpy
())
expect
(
$
.
ajax
).
toHaveBeenCalled
()
expect
(
$
.
ajax
.
mostRecentCall
.
args
[
0
].
url
.
_parts
.
path
).
toEqual
(
'/courses/edX/999/test/discussion/comments/01234567/update'
)
expect
(
$
.
ajax
.
mostRecentCall
.
args
[
0
].
data
.
body
).
toEqual
(
@
updatedBody
)
...
...
common/static/coffee/spec/discussion/view/thread_response_show_view_spec.coffee
View file @
cb6bc3b0
...
...
@@ -45,6 +45,7 @@ describe "ThreadResponseShowView", ->
it
"renders endorsement correctly for a marked answer in a question thread"
,
->
endorsement
=
{
"username"
:
"test_endorser"
,
"user_id"
:
"test_id"
,
"time"
:
new
Date
().
toISOString
()
}
@
thread
.
set
(
"thread_type"
,
"question"
)
...
...
@@ -56,6 +57,7 @@ describe "ThreadResponseShowView", ->
expect
(
@
view
.
$
(
".posted-details"
).
text
().
replace
(
/\s+/g
,
" "
)).
toMatch
(
"marked as answer less than a minute ago by "
+
endorsement
.
username
)
expect
(
@
view
.
$
(
".posted-details > a"
).
attr
(
'href'
)).
toEqual
(
"/courses/edX/999/test/discussion/forum/users/test_id"
)
it
"renders anonymous endorsement correctly for a marked answer in a question thread"
,
->
endorsement
=
{
...
...
@@ -74,6 +76,7 @@ describe "ThreadResponseShowView", ->
it
"renders endorsement correctly for an endorsed response in a discussion thread"
,
->
endorsement
=
{
"username"
:
"test_endorser"
,
"user_id"
:
"test_id"
,
"time"
:
new
Date
().
toISOString
()
}
@
thread
.
set
(
"thread_type"
,
"discussion"
)
...
...
@@ -85,6 +88,7 @@ describe "ThreadResponseShowView", ->
expect
(
@
view
.
$
(
".posted-details"
).
text
().
replace
(
/\s+/g
,
" "
)).
toMatch
(
"endorsed less than a minute ago by "
+
endorsement
.
username
)
expect
(
@
view
.
$
(
".posted-details > a"
).
attr
(
'href'
)).
toEqual
(
"/courses/edX/999/test/discussion/forum/users/test_id"
)
it
"renders anonymous endorsement correctly for an endorsed response in a discussion thread"
,
->
endorsement
=
{
...
...
common/static/coffee/spec/discussion/view/thread_response_view_spec.coffee
View file @
cb6bc3b0
...
...
@@ -3,13 +3,42 @@ describe 'ThreadResponseView', ->
DiscussionSpecHelper
.
setUpGlobals
()
DiscussionSpecHelper
.
setUnderscoreFixtures
()
@
thread
=
new
Thread
({
"thread_type"
:
"discussion"
})
@
response
=
new
Comment
{
children
:
[{},
{}]
children
:
[{},
{}],
thread
:
@
thread
,
}
@
view
=
new
ThreadResponseView
({
model
:
@
response
,
el
:
$
(
"#fixture-element"
)})
spyOn
(
ThreadResponseShowView
.
prototype
,
"render"
)
spyOn
(
ResponseCommentView
.
prototype
,
"render"
)
describe
'closed and open Threads'
,
->
checkCommentForm
=
(
closed
)
->
thread
=
new
Thread
({
"thread_type"
:
"discussion"
,
"closed"
:
closed
})
commentData
=
{
id
:
"dummy"
,
user_id
:
"567"
,
course_id
:
"TestOrg/TestCourse/TestRun"
,
body
:
"this is a comment"
,
created_at
:
"2013-04-03T20:08:39Z"
,
abuse_flaggers
:
[],
type
:
"comment"
,
children
:
[],
thread
:
thread
,
}
comment
=
new
Comment
(
commentData
)
view
=
new
ThreadResponseView
({
model
:
comment
,
el
:
$
(
"#fixture-element"
),
})
view
.
render
()
expect
(
view
.
$
(
'.comment-form'
).
closest
(
'li'
).
is
(
":visible"
)).
toBe
(
not
closed
)
it
'hides comment form when thread is closed'
,
->
checkCommentForm
(
true
)
it
'show comment form when thread is open'
,
->
checkCommentForm
(
false
)
describe
'renderComments'
,
->
it
'hides "show comments" link if collapseComments is not set'
,
->
@
view
.
render
()
...
...
@@ -17,7 +46,7 @@ describe 'ThreadResponseView', ->
expect
(
@
view
.
$
(
".action-show-comments"
)).
not
.
toBeVisible
()
it
'hides "show comments" link if collapseComments is set but response has no comments'
,
->
@
response
=
new
Comment
{
children
:
[]
}
@
response
=
new
Comment
{
children
:
[]
,
thread
:
@
thread
}
@
view
=
new
ThreadResponseView
({
model
:
@
response
,
el
:
$
(
"#fixture-element"
),
collapseComments
:
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment