From 696ebf0993f1e0efe23275e87fc6060dc08ed9b4 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Thu, 4 Sep 2014 12:26:08 -0400 Subject: [PATCH] Add cohort selector tests in forum NewPostView --- .../discussion/discussion_spec_helper.coffee | 7 +++ .../discussion/view/new_post_view_spec.coffee | 53 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/common/static/coffee/spec/discussion/discussion_spec_helper.coffee b/common/static/coffee/spec/discussion/discussion_spec_helper.coffee index 2863658b9c..75bce04758 100644 --- a/common/static/coffee/spec/discussion/discussion_spec_helper.coffee +++ b/common/static/coffee/spec/discussion/discussion_spec_helper.coffee @@ -9,6 +9,13 @@ class @DiscussionSpecHelper @makeModerator = () -> DiscussionUtil.roleIds["Moderator"].push(parseInt(window.user.id)) + @makeAjaxSpy = (fakeAjax) -> + spyOn($, "ajax").andCallFake( + (params) -> + fakeAjax(params) + {always: ->} + ) + @setUnderscoreFixtures = -> appendSetFixtures("""
diff --git a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee index c7c5044b71..a634221803 100644 --- a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee +++ b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- describe "NewPostView", -> beforeEach -> + DiscussionSpecHelper.setUpGlobals() DiscussionSpecHelper.setUnderscoreFixtures() window.$$course_id = "edX/999/test" spyOn(DiscussionUtil, "makeWmdEditor") @@ -115,6 +116,58 @@ describe "NewPostView", -> @view.$("a.topic-title[data-discussion-id=non-cohorted]").click() 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", -> topicId = "test_topic" spyOn($, "ajax").andCallFake(