Commit ff961923 by Greg Price Committed by Zia Fazal

Add cohort selector tests in forum NewPostView

parent e2aa5ad3
...@@ -38,6 +38,13 @@ class @DiscussionSpecHelper ...@@ -38,6 +38,13 @@ class @DiscussionSpecHelper
is_cohorted: is_cohorted is_cohorted: is_cohorted
) )
@makeAjaxSpy = (fakeAjax) ->
spyOn($, "ajax").andCallFake(
(params) ->
fakeAjax(params)
{always: ->}
)
@setUnderscoreFixtures = -> @setUnderscoreFixtures = ->
for templateName in ['thread-show'] for templateName in ['thread-show']
templateFixture = readFixtures('templates/discussion/' + templateName + '.underscore') templateFixture = readFixtures('templates/discussion/' + templateName + '.underscore')
......
...@@ -204,6 +204,58 @@ describe "NewPostView", -> ...@@ -204,6 +204,58 @@ describe "NewPostView", ->
checkPostCancelReset(mode, @discussion, @course_settings) checkPostCancelReset(mode, @discussion, @course_settings)
) )
describe "cohort selector", ->
beforeEach ->
@course_settings = new DiscussionCourseSettings({
"category_map": {
"children": ["Topic"],
"entries": {"Topic": {"is_cohorted": true, "id": "topic"}}
},
"allow_anonymous": false,
"allow_anonymous_to_peers": false,
"is_cohorted": true,
"cohorts": [
{"id": 1, "name": "Cohort1"},
{"id": 2, "name": "Cohort2"}
]
})
@view = new NewPostView(
el: $("#fixture-element"),
collection: @discussion,
course_settings: @course_settings,
mode: "tab"
)
expectCohortSelectorVisible = (view, visible) ->
expect(view.$(".js-group-select").is(":visible")).toEqual(visible)
it "is not visible to students", ->
@view.render()
expectCohortSelectorVisible(@view, false)
it "allows moderators to select visibility", ->
DiscussionSpecHelper.makeModerator()
@view.render()
expectCohortSelectorVisible(@view, true)
expect(@view.$(".js-group-select").prop("disabled")).toEqual(false)
expectedGroupId = null
DiscussionSpecHelper.makeAjaxSpy(
(params) -> expect(params.data.group_id).toEqual(expectedGroupId)
)
_.each(
["1", "2", ""],
(groupIdStr) =>
expectedGroupId = groupIdStr
@view.$(".js-group-select").val(groupIdStr)
@view.$(".js-post-title").val("dummy title")
@view.$(".js-post-body textarea").val("dummy body")
@view.$(".forum-new-post-form").submit()
expect($.ajax).toHaveBeenCalled()
$.ajax.reset()
)
it "posts to the correct URL", -> it "posts to the correct URL", ->
topicId = "test_topic" topicId = "test_topic"
spyOn($, "ajax").andCallFake( spyOn($, "ajax").andCallFake(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment