Commit 696ebf09 by Greg Price

Add cohort selector tests in forum NewPostView

parent 6496963e
...@@ -9,6 +9,13 @@ class @DiscussionSpecHelper ...@@ -9,6 +9,13 @@ class @DiscussionSpecHelper
@makeModerator = () -> @makeModerator = () ->
DiscussionUtil.roleIds["Moderator"].push(parseInt(window.user.id)) DiscussionUtil.roleIds["Moderator"].push(parseInt(window.user.id))
@makeAjaxSpy = (fakeAjax) ->
spyOn($, "ajax").andCallFake(
(params) ->
fakeAjax(params)
{always: ->}
)
@setUnderscoreFixtures = -> @setUnderscoreFixtures = ->
appendSetFixtures(""" appendSetFixtures("""
<div id="fixture-element"></div> <div id="fixture-element"></div>
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
describe "NewPostView", -> describe "NewPostView", ->
beforeEach -> beforeEach ->
DiscussionSpecHelper.setUpGlobals()
DiscussionSpecHelper.setUnderscoreFixtures() DiscussionSpecHelper.setUnderscoreFixtures()
window.$$course_id = "edX/999/test" window.$$course_id = "edX/999/test"
spyOn(DiscussionUtil, "makeWmdEditor") spyOn(DiscussionUtil, "makeWmdEditor")
...@@ -115,6 +116,58 @@ describe "NewPostView", -> ...@@ -115,6 +116,58 @@ describe "NewPostView", ->
@view.$("a.topic-title[data-discussion-id=non-cohorted]").click() @view.$("a.topic-title[data-discussion-id=non-cohorted]").click()
expectCohortSelectorEnabled(@view, false) expectCohortSelectorEnabled(@view, false)
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