Commit cb6bc3b0 by jsa Committed by E. Kolpakov

Copied test specs

parent 70067eb6
!view/discussion_thread_edit_view_spec.js
!view/discussion_topic_menu_view_spec.js
...@@ -142,3 +142,18 @@ describe "DiscussionThreadShowView", -> ...@@ -142,3 +142,18 @@ describe "DiscussionThreadShowView", ->
$el = $('#fixture-element').html(@view.getAuthorDisplay()) $el = $('#fixture-element').html(@view.getAuthorDisplay())
expect($el.find('a.username').length).toEqual(0) expect($el.find('a.username').length).toEqual(0)
expect($el.text()).toMatch(/^(\s*)anonymous(\s*)$/) 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.'
)
...@@ -6,10 +6,12 @@ describe "DiscussionThreadView", -> ...@@ -6,10 +6,12 @@ describe "DiscussionThreadView", ->
jasmine.Clock.useMock() jasmine.Clock.useMock()
@threadData = DiscussionViewSpecHelper.makeThreadWithProps({}) @threadData = DiscussionViewSpecHelper.makeThreadWithProps({})
@thread = new Thread(@threadData) @thread = new Thread(@threadData)
@discussion = new Discussion(@thread)
spyOn($, "ajax") spyOn($, "ajax")
# Avoid unnecessary boilerplate # Avoid unnecessary boilerplate
spyOn(DiscussionThreadShowView.prototype, "convertMath") spyOn(DiscussionThreadShowView.prototype, "convertMath")
spyOn(DiscussionContentView.prototype, "makeWmdEditor") spyOn(DiscussionContentView.prototype, "makeWmdEditor")
spyOn(DiscussionUtil, "makeWmdEditor")
spyOn(ThreadResponseView.prototype, "renderShowView") spyOn(ThreadResponseView.prototype, "renderShowView")
renderWithContent = (view, content) -> renderWithContent = (view, content) ->
...@@ -40,9 +42,46 @@ describe "DiscussionThreadView", -> ...@@ -40,9 +42,46 @@ describe "DiscussionThreadView", ->
else else
expect(view.$el.find(".load-response-button").length).toEqual(0) 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", -> describe "tab mode", ->
beforeEach -> 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", -> describe "response count and pagination", ->
it "correctly render for a thread with no responses", -> it "correctly render for a thread with no responses", ->
...@@ -83,7 +122,12 @@ describe "DiscussionThreadView", -> ...@@ -83,7 +122,12 @@ describe "DiscussionThreadView", ->
describe "inline mode", -> describe "inline mode", ->
beforeEach -> 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", -> describe "render", ->
it "shows content that should be visible when collapsed", -> it "shows content that should be visible when collapsed", ->
...@@ -150,11 +194,26 @@ describe "DiscussionThreadView", -> ...@@ -150,11 +194,26 @@ describe "DiscussionThreadView", ->
expect($(".post-body").text()).toEqual(maliciousAbbreviation) expect($(".post-body").text()).toEqual(maliciousAbbreviation)
expect($(".post-body").html()).not.toContain("<script") 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", -> describe "for question threads", ->
beforeEach -> beforeEach ->
@thread.set("thread_type", "question") @thread.set("thread_type", "question")
@view = new DiscussionThreadView( @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) -> renderTestCase = (view, numEndorsed, numNonEndorsed) ->
......
(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);
...@@ -7,6 +7,7 @@ class @DiscussionViewSpecHelper ...@@ -7,6 +7,7 @@ class @DiscussionViewSpecHelper
pinned: false, pinned: false,
endorsed: false, endorsed: false,
votes: {up_count: '0'}, votes: {up_count: '0'},
read: false,
unread_comments_count: 0, unread_comments_count: 0,
comments_count: 0, comments_count: 0,
abuse_flaggers: [], abuse_flaggers: [],
......
...@@ -17,12 +17,10 @@ describe 'ResponseCommentView', -> ...@@ -17,12 +17,10 @@ describe 'ResponseCommentView', ->
spyOn(DiscussionUtil, "makeWmdEditor") spyOn(DiscussionUtil, "makeWmdEditor")
@view.render() @view.render()
makeEventSpy = () -> jasmine.createSpyObj('event', ['preventDefault', 'target'])
describe '_delete', -> describe '_delete', ->
beforeEach -> beforeEach ->
@comment.updateInfo {ability: {can_delete: true}} @comment.updateInfo {ability: {can_delete: true}}
@event = makeEventSpy() @event = DiscussionSpecHelper.makeEventSpy()
spyOn(@comment, "remove") spyOn(@comment, "remove")
spyOn(@view.$el, "remove") spyOn(@view.$el, "remove")
...@@ -81,9 +79,9 @@ describe 'ResponseCommentView', -> ...@@ -81,9 +79,9 @@ describe 'ResponseCommentView', ->
# Without calling renderEditView first, renderShowView is a no-op # Without calling renderEditView first, renderShowView is a no-op
@view.renderEditView() @view.renderEditView()
@view.renderShowView() @view.renderShowView()
@view.showView.trigger "comment:_delete", makeEventSpy() @view.showView.trigger "comment:_delete", DiscussionSpecHelper.makeEventSpy()
expect(@view._delete).toHaveBeenCalled() expect(@view._delete).toHaveBeenCalled()
@view.showView.trigger "comment:edit", makeEventSpy() @view.showView.trigger "comment:edit", DiscussionSpecHelper.makeEventSpy()
expect(@view.edit).toHaveBeenCalled() expect(@view.edit).toHaveBeenCalled()
expect(@view.$(".edit-post-form#comment_#{@comment.id}")).not.toHaveClass("edit-post-form") expect(@view.$(".edit-post-form#comment_#{@comment.id}")).not.toHaveClass("edit-post-form")
...@@ -92,9 +90,9 @@ describe 'ResponseCommentView', -> ...@@ -92,9 +90,9 @@ describe 'ResponseCommentView', ->
spyOn(@view, "update") spyOn(@view, "update")
spyOn(@view, "cancelEdit") spyOn(@view, "cancelEdit")
@view.renderEditView() @view.renderEditView()
@view.editView.trigger "comment:update", makeEventSpy() @view.editView.trigger "comment:update", DiscussionSpecHelper.makeEventSpy()
expect(@view.update).toHaveBeenCalled() 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.cancelEdit).toHaveBeenCalled()
expect(@view.$(".edit-post-form#comment_#{@comment.id}")).toHaveClass("edit-post-form") expect(@view.$(".edit-post-form#comment_#{@comment.id}")).toHaveClass("edit-post-form")
...@@ -138,7 +136,7 @@ describe 'ResponseCommentView', -> ...@@ -138,7 +136,7 @@ describe 'ResponseCommentView', ->
it 'calls the update endpoint correctly and displays the show view on success', -> it 'calls the update endpoint correctly and displays the show view on success', ->
@ajaxSucceed = true @ajaxSucceed = true
@view.update(makeEventSpy()) @view.update(DiscussionSpecHelper.makeEventSpy())
expect($.ajax).toHaveBeenCalled() 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].url._parts.path).toEqual('/courses/edX/999/test/discussion/comments/01234567/update')
expect($.ajax.mostRecentCall.args[0].data.body).toEqual(@updatedBody) expect($.ajax.mostRecentCall.args[0].data.body).toEqual(@updatedBody)
...@@ -148,7 +146,7 @@ describe 'ResponseCommentView', -> ...@@ -148,7 +146,7 @@ describe 'ResponseCommentView', ->
it 'handles AJAX errors', -> it 'handles AJAX errors', ->
originalBody = @comment.get("body") originalBody = @comment.get("body")
@ajaxSucceed = false @ajaxSucceed = false
@view.update(makeEventSpy()) @view.update(DiscussionSpecHelper.makeEventSpy())
expect($.ajax).toHaveBeenCalled() 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].url._parts.path).toEqual('/courses/edX/999/test/discussion/comments/01234567/update')
expect($.ajax.mostRecentCall.args[0].data.body).toEqual(@updatedBody) expect($.ajax.mostRecentCall.args[0].data.body).toEqual(@updatedBody)
......
...@@ -45,6 +45,7 @@ describe "ThreadResponseShowView", -> ...@@ -45,6 +45,7 @@ describe "ThreadResponseShowView", ->
it "renders endorsement correctly for a marked answer in a question thread", -> it "renders endorsement correctly for a marked answer in a question thread", ->
endorsement = { endorsement = {
"username": "test_endorser", "username": "test_endorser",
"user_id": "test_id",
"time": new Date().toISOString() "time": new Date().toISOString()
} }
@thread.set("thread_type", "question") @thread.set("thread_type", "question")
...@@ -56,6 +57,7 @@ describe "ThreadResponseShowView", -> ...@@ -56,6 +57,7 @@ describe "ThreadResponseShowView", ->
expect(@view.$(".posted-details").text().replace(/\s+/g, " ")).toMatch( expect(@view.$(".posted-details").text().replace(/\s+/g, " ")).toMatch(
"marked as answer less than a minute ago by " + endorsement.username "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", -> it "renders anonymous endorsement correctly for a marked answer in a question thread", ->
endorsement = { endorsement = {
...@@ -74,6 +76,7 @@ describe "ThreadResponseShowView", -> ...@@ -74,6 +76,7 @@ describe "ThreadResponseShowView", ->
it "renders endorsement correctly for an endorsed response in a discussion thread", -> it "renders endorsement correctly for an endorsed response in a discussion thread", ->
endorsement = { endorsement = {
"username": "test_endorser", "username": "test_endorser",
"user_id": "test_id",
"time": new Date().toISOString() "time": new Date().toISOString()
} }
@thread.set("thread_type", "discussion") @thread.set("thread_type", "discussion")
...@@ -85,6 +88,7 @@ describe "ThreadResponseShowView", -> ...@@ -85,6 +88,7 @@ describe "ThreadResponseShowView", ->
expect(@view.$(".posted-details").text().replace(/\s+/g, " ")).toMatch( expect(@view.$(".posted-details").text().replace(/\s+/g, " ")).toMatch(
"endorsed less than a minute ago by " + endorsement.username "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", -> it "renders anonymous endorsement correctly for an endorsed response in a discussion thread", ->
endorsement = { endorsement = {
......
...@@ -3,13 +3,42 @@ describe 'ThreadResponseView', -> ...@@ -3,13 +3,42 @@ describe 'ThreadResponseView', ->
DiscussionSpecHelper.setUpGlobals() DiscussionSpecHelper.setUpGlobals()
DiscussionSpecHelper.setUnderscoreFixtures() DiscussionSpecHelper.setUnderscoreFixtures()
@thread = new Thread({"thread_type": "discussion"})
@response = new Comment { @response = new Comment {
children: [{}, {}] children: [{}, {}],
thread: @thread,
} }
@view = new ThreadResponseView({model: @response, el: $("#fixture-element")}) @view = new ThreadResponseView({model: @response, el: $("#fixture-element")})
spyOn(ThreadResponseShowView.prototype, "render") spyOn(ThreadResponseShowView.prototype, "render")
spyOn(ResponseCommentView.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', -> describe 'renderComments', ->
it 'hides "show comments" link if collapseComments is not set', -> it 'hides "show comments" link if collapseComments is not set', ->
@view.render() @view.render()
...@@ -17,7 +46,7 @@ describe 'ThreadResponseView', -> ...@@ -17,7 +46,7 @@ describe 'ThreadResponseView', ->
expect(@view.$(".action-show-comments")).not.toBeVisible() expect(@view.$(".action-show-comments")).not.toBeVisible()
it 'hides "show comments" link if collapseComments is set but response has no comments', -> 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({ @view = new ThreadResponseView({
model: @response, el: $("#fixture-element"), model: @response, el: $("#fixture-element"),
collapseComments: true collapseComments: true
......
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