diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 46800ef425..bd85704b7c 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -290,8 +290,8 @@ presence.presence_info[norbert.user_id] = { status: activity.ACTIVE }; var count = $('alice-count'); var pm_key = alice.user_id.toString(); var li = $("li.user_sidebar_entry[data-user-id='" + pm_key + "']"); - count.add_child('.value', value); - li.add_child('.count', count); + count.set_find_results('.value', value); + li.set_find_results('.count', count); count.set_parent(li); var counts = new Dict(); @@ -315,8 +315,8 @@ presence.presence_info[norbert.user_id] = { status: activity.ACTIVE }; var pm_key = alice.user_id.toString() + "," + fred.user_id.toString(); var li_selector = "li.group-pms-sidebar-entry[data-user-ids='" + pm_key + "']"; var li = $(li_selector); - count.add_child('.value', value); - li.add_child('.count', count); + count.set_find_results('.value', value); + li.set_find_results('.count', count); count.set_parent(li); var counts = new Dict(); @@ -416,7 +416,7 @@ presence.presence_info[jill.user_id] = { status: activity.ACTIVE }; var alice_li = $('alice-li'); // These selectors are here to avoid some short-circuit logic. - $('#user_presences').add_child('[data-user-id="1"]', alice_li); + $('#user_presences').set_find_results('[data-user-id="1"]', alice_li); var appended_html; $('#user_presences').append = function (html) { @@ -437,7 +437,7 @@ presence.presence_info[jill.user_id] = { status: activity.ACTIVE }; var fred_li = $('fred-li'); // These selectors are here to avoid some short-circuit logic. - $('#user_presences').add_child('[data-user-id="2"]', fred_li); + $('#user_presences').set_find_results('[data-user-id="2"]', fred_li); var appended_html; $('#user_presences').append = function (html) { @@ -466,7 +466,7 @@ presence.presence_info[jill.user_id] = { status: activity.ACTIVE }; var fred_li = $('fred-li'); // These selectors are here to avoid some short-circuit logic. - $('#user_presences').add_child('[data-user-id="2"]', fred_li); + $('#user_presences').set_find_results('[data-user-id="2"]', fred_li); $('fake-dom-for-jill').attr = function (attr_name) { assert.equal(attr_name, 'data-user-id'); @@ -576,8 +576,8 @@ $('.user-list-filter').is = function (sel) { var pm_key = alice.user_id.toString() + "," + fred.user_id.toString(); var li_selector = "li.group-pms-sidebar-entry[data-user-ids='" + pm_key + "']"; var li = $(li_selector); - count.add_child('.value', value); - li.add_child('.count', count); + count.set_find_results('.value', value); + li.set_find_results('.count', count); count.set_parent(li); var real_get_huddles = activity.get_huddles; @@ -609,7 +609,7 @@ $('.user-list-filter').is = function (sel) { }; var alice_li = $('alice-li'); - $('#user_presences').add_child('[data-user-id="1"]', alice_li); + $('#user_presences').set_find_results('[data-user-id="1"]', alice_li); $('#user_presences').append = function () {}; diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index a46089052b..6e64199f66 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -146,8 +146,8 @@ global.people.initialize_current_user(me.user_id); var alice_li = $('alice-li-stub'); var bob_li = $('bob-li-stub'); - private_li.add_child("li[data-user-ids-string='101']", alice_li); - private_li.add_child("li[data-user-ids-string='102']", bob_li); + private_li.set_find_results("li[data-user-ids-string='101']", alice_li); + private_li.set_find_results("li[data-user-ids-string='102']", bob_li); var dom; private_li.append = function (html) { @@ -237,15 +237,15 @@ global.people.initialize_current_user(me.user_id); var total_value = $('total-value-stub'); var total_count = $('total-count-stub'); var private_li = $("#global_filters > li[data-name='private']"); - private_li.add_child('.count', total_count); - total_count.add_child('.value', total_value); + private_li.set_find_results('.count', total_count); + total_count.set_find_results('.value', total_value); var child_value = $('child-value-stub'); var child_count = $('child-count-stub'); var child_li = $('child-li-stub'); - private_li.add_child("li[data-user-ids-string='101,102']", child_li); - child_li.add_child('.private_message_count', child_count); - child_count.add_child('.value', child_value); + private_li.set_find_results("li[data-user-ids-string='101,102']", child_li); + child_li.set_find_results('.private_message_count', child_count); + child_count.set_find_results('.value', child_value); var pm_count = new Dict(); var user_ids_string = '101,102'; diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index 071f3b5d45..08e0ef669a 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -146,7 +146,7 @@ set_global('message_store', { var count_element = $('count-stub'); var reaction_element = $('reaction-stub'); - reaction_element.add_child('.message_reaction_count', count_element); + reaction_element.set_find_results('.message_reaction_count', count_element); reactions.set_reaction_count(reaction_element, 5); @@ -158,8 +158,8 @@ set_global('message_store', { var message_row = $('some-message-row'); var message_reactions = $('our-reactions-section'); - message_table.add_child("[zid='555']", message_row); - message_row.add_child('.message_reactions', message_reactions); + message_table.set_find_results("[zid='555']", message_row); + message_row.set_find_results('.message_reactions', message_reactions); var section = reactions.get_reaction_section(555); @@ -222,7 +222,7 @@ set_global('message_store', { var count_element = $('count-element'); var reaction_element = $('reaction-element'); - reaction_element.add_child('.message_reaction_count', count_element); + reaction_element.set_find_results('.message_reaction_count', count_element); var title_set; reaction_element.prop = function (prop_name, value) { diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 8a18ab0b81..b9400385b5 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -69,14 +69,14 @@ set_global('ui_report', { }); function simulate_auth_methods() { - $('#admin_auth_methods_table').add_child( + $('#admin_auth_methods_table').set_find_results( 'tr.method_row', $('admin-tr-stub') ); var controls = $('auth-methods-controls-stub'); - $(".organization-box [data-name='auth-methods']").add_child( + $(".organization-box [data-name='auth-methods']").set_find_results( 'input, button, select, checked', controls ); @@ -87,7 +87,7 @@ function simulate_auth_methods() { }; var non_editables = $('auth-methods-not-edit-stub'); - $('.organization-box').add_child( + $('.organization-box').set_find_results( '.settings-section:not(.can-edit)', non_editables ); @@ -96,7 +96,7 @@ function simulate_auth_methods() { } function simulate_realm_domains_table() { - $('#realm_domains_table tbody').add_child( + $('#realm_domains_table tbody').set_find_results( 'tr', $('realm-tr-stub') ); @@ -115,17 +115,17 @@ function simulate_realm_domains_table() { function test_realms_domain_modal(add_realm_domain) { var info = $('domains-info-stub'); - $('#realm_domains_modal').add_child( + $('#realm_domains_modal').set_find_results( '.realm_domains_info', info ); - $('#add-realm-domain-widget').add_child( + $('#add-realm-domain-widget').set_find_results( '.new-realm-domain', $('new-realm-domain-stub') ); - $('#add-realm-domain-widget').add_child( + $('#add-realm-domain-widget').set_find_results( '.new-realm-domain-allow-subdomains', $('new-realm-domain-allow-subdomains-stub') ); @@ -393,7 +393,7 @@ function test_change_allow_subdomains(change_allow_subdomains) { error_callback = req.error; }; - $('#realm_domains_modal').add_child( + $('#realm_domains_modal').set_find_results( '.realm_domains_info', info ); @@ -402,7 +402,7 @@ function test_change_allow_subdomains(change_allow_subdomains) { $('elem-stub').parents = function () { return $('parents-stub'); }; - $('parents-stub').add_child('.domain', $('domain-stub')); + $('parents-stub').set_find_results('.domain', $('domain-stub')); $('elem-stub').prop('checked', allow); change_allow_subdomains.apply('elem-stub', [ev]); diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index ebe065545e..e4614941ae 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -50,8 +50,8 @@ set_global('topic_list', {}); (function create_devel_sidebar_row() { var devel_value = $('devel-value'); var devel_count = $('devel-count'); - $('devel-stub-html').add_child('.count', devel_count); - $('devel-count').add_child('.value', devel_value); + $('devel-stub-html').set_find_results('.count', devel_count); + $('devel-count').set_find_results('.value', devel_value); devel_count.set_parent($('devel-stub-html')); global.templates.render = function (template_name, data) { @@ -67,8 +67,8 @@ set_global('topic_list', {}); (function create_social_sidebar_row() { var social_value = $('social-value'); var social_count = $('social-count'); - $('social-stub-html').add_child('.count', social_count); - $('social-count').add_child('.value', social_value); + $('social-stub-html').set_find_results('.count', social_count); + $('social-count').set_find_results('.value', social_value); social_count.set_parent($('social-stub-html')); global.templates.render = function (template_name, data) { @@ -111,7 +111,7 @@ set_global('topic_list', {}); var stream_id = social.stream_id; var privacy_elem = $('privacy-stub'); - social_li.add_child('.stream-privacy', privacy_elem); + social_li.set_find_results('.stream-privacy', privacy_elem); social.invite_only = true; social.color = '#222222'; @@ -362,8 +362,8 @@ function initialize_stream_data() { var elem = $(elem_selector); var count = $(count_selector); var value = $(value_selector); - elem.add_child('.count', count); - count.add_child('.value', value); + elem.set_find_results('.count', count); + count.set_find_results('.value', value); count.set_parent(elem); return elem; diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js index 9907c2413a..8988d3bb44 100644 --- a/frontend_tests/node_tests/zjquery.js +++ b/frontend_tests/node_tests/zjquery.js @@ -58,7 +58,7 @@ set_global('$', global.make_zjquery()); assert.equal(widget.val(), '42'); }()); -(function test_parent_child_stuff() { +(function test_finding_child_objects() { // Let's say you have a function like the following: function update_message_emoji(emoji_src) { $('#my-message').find('.emoji').attr('src', emoji_src); @@ -72,9 +72,9 @@ set_global('$', global.make_zjquery()); // But you can set up your tests to simulate DOM relationships. // - // We will use add_child(), which is a special zjquery helper. + // We will use set_find_results(), which is a special zjquery helper. var emoji = $('emoji-stub'); - $('#my-message').add_child('.emoji', emoji); + $('#my-message').set_find_results('.emoji', emoji); // And then calling the function produces the desired effect: update_message_emoji('foo.png'); diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 30b4517867..028428083b 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -12,7 +12,7 @@ exports.make_zjquery = function () { var value; var shown = false; var focused = false; - var children = new Dict(); + var find_results = new Dict(); var my_parent; var properties = new Dict(); var attrs = new Dict(); @@ -31,8 +31,10 @@ exports.make_zjquery = function () { } var self = { - add_child: function (child_selector, child_elem) { - children.set(child_selector, child_elem); + add_child: function () { + // TODO: Remove this once some in-flight PRs + // get merged. + assert(false, 'Use set_find_results instead.'); }, addClass: function (class_name) { classes.set(class_name, true); @@ -69,7 +71,7 @@ exports.make_zjquery = function () { }, fadeTo: noop, find: function (child_selector) { - var child = children.get(child_selector); + var child = find_results.get(child_selector); if (child) { return child; } @@ -187,6 +189,9 @@ exports.make_zjquery = function () { generic_event('select', arg); return self.wrapper; }, + set_find_results: function (find_selector, jquery_object) { + find_results.set(find_selector, jquery_object); + }, show: function () { shown = true; return self.wrapper;