From e64277879fa56d1477ff2b5d47b9a58a769a954a Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 9 Aug 2017 13:30:10 -0400 Subject: [PATCH] Use zjquery to test topic_list.js. We no longer use real jQuery to test topic_list. This changes the nature of the tests to be higher level checks on how the DOM is constructed. The actual details of how templates get rendered should be in templates.js. --- frontend_tests/node_tests/topic_list.js | 88 +++++++++++++++++-------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/frontend_tests/node_tests/topic_list.js b/frontend_tests/node_tests/topic_list.js index a5cdb7be74..f259356b3a 100644 --- a/frontend_tests/node_tests/topic_list.js +++ b/frontend_tests/node_tests/topic_list.js @@ -1,23 +1,14 @@ -add_dependencies({ - Handlebars: 'handlebars', - hash_util: 'js/hash_util', - hashchange: 'js/hashchange', - muting: 'js/muting', - narrow: 'js/narrow', - stream_data: 'js/stream_data', - topic_data: 'js/topic_data', - templates: 'js/templates', -}); +set_global('$', global.make_zjquery()); +set_global('stream_data', {}); set_global('unread', {}); +set_global('muting', {}); +set_global('templates', {}); -var jsdom = require("jsdom"); -var window = jsdom.jsdom().defaultView; -global.$ = require('jquery')(window); - -var topic_list = require('js/topic_list.js'); - -global.compile_template('topic_list_item'); +zrequire('hash_util'); +zrequire('narrow'); +zrequire('topic_data'); +zrequire('topic_list'); (function test_topic_list_build_widget() { var stream_id = 555; @@ -31,24 +22,65 @@ global.compile_template('topic_list_item'); message_id: 400, }); - global.unread.num_unread_for_topic = function () { - return 1; + unread.num_unread_for_topic = function () { + return 3; }; - global.stream_data.get_sub_by_id = function (stream_id) { + stream_data.get_sub_by_id = function (stream_id) { assert.equal(stream_id, 555); - return 'devel'; + return { + name: 'devel', + }; + }; + + var checked_mutes; + var rendered; + + templates.render = function (name, info) { + assert.equal(name, 'topic_list_item'); + var expected = { + topic_name: 'coding', + unread: 3, + is_zero: false, + is_muted: false, + url: '#narrow/stream/devel/subject/coding', + }; + assert.deepEqual(info, expected); + rendered = true; + return ''; + }; + + muting.is_topic_muted = function (stream_name, topic_name) { + assert.equal(stream_name, 'devel'); + assert.equal(topic_name, 'coding'); + checked_mutes = true; + return false; + }; + + var ul = $('