Commit 57f6103b by E. Kolpakov

Review notes:

 * Extracted common template parts in index.html and discussion_course into standalone template file
 * Improved discussion router test, so now it actually tests loading thread not in collection
parent fe468956
...@@ -132,6 +132,33 @@ describe 'DiscussionRouter', -> ...@@ -132,6 +132,33 @@ describe 'DiscussionRouter', ->
}), }),
] ]
@other_threads = {
'12': DiscussionViewSpecHelper.makeThreadWithProps({
id: "12",
title: "Thread12",
votes: {up_count: '74'},
comments_count: 0,
pinned: false,
created_at: '2015-04-03T20:05:39Z',
}),
'15': DiscussionViewSpecHelper.makeThreadWithProps({
id: "15",
title: "Thread15",
votes: {up_count: '92'},
comments_count: 0,
pinned: true,
created_at: '2015-05-01T19:4:03Z',
}),
'112': DiscussionViewSpecHelper.makeThreadWithProps({
id: "112",
title: "Thread112",
votes: {up_count: '1'},
comments_count: 2,
pinned: false,
created_at: '2015-06-09T20:05:39Z',
})
}
spyOn(DiscussionUtil, 'makeWmdEditor') spyOn(DiscussionUtil, 'makeWmdEditor')
@discussion = new Discussion(_.map(@threads, (thread_spec) -> new Thread(thread_spec)), {pages: 2, sort: 'date'}) @discussion = new Discussion(_.map(@threads, (thread_spec) -> new Thread(thread_spec)), {pages: 2, sort: 'date'})
@course_settings = new DiscussionCourseSettings({ @course_settings = new DiscussionCourseSettings({
...@@ -159,23 +186,27 @@ describe 'DiscussionRouter', -> ...@@ -159,23 +186,27 @@ describe 'DiscussionRouter', ->
spyOn(@router, 'renderThreadView') spyOn(@router, 'renderThreadView')
# precondition check - thread is in router's collection # precondition check - thread is in router's collection
expect(@router.discussion.get(thread_id)).not.toBeUndefined() expect(@router.discussion.get(thread_id)).not.toBeUndefined()
@router.showThread("irrelevant forum name", thread_id) @router.showThread("irrelevant forum name", thread_id)
expect($.ajax).not.toHaveBeenCalled() expect($.ajax).not.toHaveBeenCalled()
expect(@router.renderThreadView).toHaveBeenCalled() expect(@router.renderThreadView).toHaveBeenCalled()
expect(@router.thread.id).toBe(thread_id)
missingCheck = (forum_name, thread_id) -> missingCheck = (forum_name, thread_id) ->
it "requests thread #{thread_id} in forum #{forum_name} if not already in collection", -> it "requests thread #{thread_id} in forum #{forum_name} if not already in collection", ->
DiscussionSpecHelper.makeAjaxSpy( DiscussionSpecHelper.makeAjaxSpy(
(params) -> expect(params.url.path()).toBe(DiscussionUtil.urlFor('retrieve_single_thread', forum_name, thread_id)) (params) =>
expect(params.url.path()).toBe(DiscussionUtil.urlFor('retrieve_single_thread', forum_name, thread_id))
params.success({content: @other_threads[thread_id]})
) )
spyOn(@router, 'renderThreadView') spyOn(@router, 'renderThreadView')
# precondition check - thread is in router's collection # precondition check - thread is not in router's collection
expect(@router.discussion.get(thread_id)).toBeUndefined() expect(@router.discussion.get(thread_id)).toBeUndefined()
@router.showThread(forum_name, thread_id) @router.showThread(forum_name, thread_id)
# in this case showThread makes a hidden async ajax request - it's hard to hook inot it, so it's simpler and expect(@router.renderThreadView).toHaveBeenCalled()
# sufficient to just schedule assertion to run as soon as possible, but not immediately expect(@router.thread.id).toBe(thread_id)
setTimeout (() -> expect(@router.renderThreadView).toHaveBeenCalled()), 0
existingCheck('1') existingCheck('1')
......
<section class="discussion container" id="discussion-container"
data-roles="${roles}"
data-course-id="${course_id}"
data-user-info="${user_info}"
data-threads="${threads}"
data-thread-pages="${thread_pages}"
data-content-info="${annotated_content_info}"
data-sort-preference="${sort_preference}"
data-flag-moderator="${flag_moderator}"
data-user-cohort-id="${user_cohort}"
data-course-settings="${course_settings}">
<div class="discussion-body">
<div class="forum-nav"></div>
<div class="discussion-column">
<article class="new-post-article" style="display: none"></article>
<div class="forum-content"></div>
</div>
</div>
</section>
<%include file="_underscore_templates.html" />
<%include file="_thread_list_template.html" />
\ No newline at end of file
...@@ -21,27 +21,6 @@ ...@@ -21,27 +21,6 @@
<div style="display: block; clear: both; height: 1px;"></div> <div style="display: block; clear: both; height: 1px;"></div>
% endif % endif
<section class="discussion container" id="discussion-container" <%include file="_course_discussion_section.html" />
data-roles="${roles}"
data-course-id="${course_id}"
data-user-info="${user_info}"
data-threads="${threads}"
data-thread-pages="${thread_pages}"
data-content-info="${annotated_content_info}"
data-sort-preference="${sort_preference}"
data-flag-moderator="${flag_moderator}"
data-user-cohort-id="${user_cohort}"
data-course-settings="${course_settings}">
<div class="discussion-body">
<div class="forum-nav"></div>
<div class="discussion-column">
<article class="new-post-article" style="display: none"></article>
<div class="forum-content"></div>
</div>
</div>
</section>
<%include file="_underscore_templates.html" />
<%include file="_thread_list_template.html" />
</div> </div>
...@@ -30,25 +30,4 @@ ...@@ -30,25 +30,4 @@
<%include file="_discussion_course_navigation.html" args="active_page='discussion'" /> <%include file="_discussion_course_navigation.html" args="active_page='discussion'" />
<section class="discussion container" id="discussion-container" <%include file="_course_discussion_section.html" />
data-roles="${roles}"
data-course-id="${course_id | h}"
data-user-info="${user_info}"
data-threads="${threads}"
data-thread-pages="${thread_pages}"
data-content-info="${annotated_content_info}"
data-sort-preference="${sort_preference}"
data-flag-moderator="${flag_moderator}"
data-user-cohort-id="${user_cohort}"
data-course-settings="${course_settings}">
<div class="discussion-body">
<div class="forum-nav"></div>
<div class="discussion-column">
<article class="new-post-article" style="display: none"></article>
<div class="forum-content"></div>
</div>
</div>
</section>
<%include file="_underscore_templates.html" />
<%include file="_thread_list_template.html" />
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