From 70407e080d5c50765f298d8b24021a1a2eaa7385 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 8 Jul 2017 08:05:49 -0400 Subject: [PATCH] zjquery: Require explicit set_parent() calls. Before this commit, we were erroneously setting up parents as part of add_child() calls, but it's not necessarily the case that those children are immediate children, and therefore the first object is not necessarily the immediate parent. --- frontend_tests/node_tests/activity.js | 4 ++++ frontend_tests/node_tests/settings_org.js | 10 ++-------- frontend_tests/node_tests/stream_list.js | 3 +++ frontend_tests/zjsunit/zjquery.js | 1 - 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 1f80f18912..46800ef425 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -292,6 +292,7 @@ presence.presence_info[norbert.user_id] = { status: activity.ACTIVE }; var li = $("li.user_sidebar_entry[data-user-id='" + pm_key + "']"); count.add_child('.value', value); li.add_child('.count', count); + count.set_parent(li); var counts = new Dict(); counts.set(pm_key, 5); @@ -316,6 +317,7 @@ presence.presence_info[norbert.user_id] = { status: activity.ACTIVE }; var li = $(li_selector); count.add_child('.value', value); li.add_child('.count', count); + count.set_parent(li); var counts = new Dict(); counts.set(pm_key, 5); @@ -576,6 +578,8 @@ $('.user-list-filter').is = function (sel) { var li = $(li_selector); count.add_child('.value', value); li.add_child('.count', count); + count.set_parent(li); + var real_get_huddles = activity.get_huddles; activity.get_huddles = function () { return ['1,2']; diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 7d402378e9..8a18ab0b81 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -325,10 +325,7 @@ function test_upload_realm_icon(upload_realm_icon) { function test_change_message_editing(change_message_editing) { var parent_elem = $('editing-parent-stub'); - parent_elem.add_child( - 'whatever', - $('#id_realm_message_content_edit_limit_minutes_label') - ); + $('#id_realm_message_content_edit_limit_minutes_label').set_parent(parent_elem); change_message_editing.apply({checked: false}); assert(parent_elem.hasClass('control-label-disabled')); @@ -342,10 +339,7 @@ function test_change_message_editing(change_message_editing) { function test_change_invite_required(change_invite_required) { var parent_elem = $('invite-parent-stub'); - parent_elem.add_child( - 'whatever', - $('#id_realm_invite_by_admins_only_label') - ); + $('#id_realm_invite_by_admins_only_label').set_parent(parent_elem); change_invite_required.apply({checked: false}); assert(parent_elem.hasClass('control-label-disabled')); diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index c39f8a3329..ebe065545e 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -52,6 +52,7 @@ set_global('topic_list', {}); var devel_count = $('devel-count'); $('devel-stub-html').add_child('.count', devel_count); $('devel-count').add_child('.value', devel_value); + devel_count.set_parent($('devel-stub-html')); global.templates.render = function (template_name, data) { assert.equal(template_name, 'stream_sidebar_row'); @@ -68,6 +69,7 @@ set_global('topic_list', {}); var social_count = $('social-count'); $('social-stub-html').add_child('.count', social_count); $('social-count').add_child('.value', social_value); + social_count.set_parent($('social-stub-html')); global.templates.render = function (template_name, data) { assert.equal(template_name, 'stream_sidebar_row'); @@ -362,6 +364,7 @@ function initialize_stream_data() { var value = $(value_selector); elem.add_child('.count', count); count.add_child('.value', value); + count.set_parent(elem); return elem; } diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index dee3eb1de8..30b4517867 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -32,7 +32,6 @@ exports.make_zjquery = function () { var self = { add_child: function (child_selector, child_elem) { - child_elem.set_parent(self); children.set(child_selector, child_elem); }, addClass: function (class_name) {