From 5cb32fe7337482c88e9d34352911f449cd37a481 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Fri, 29 Mar 2024 17:38:36 -0700 Subject: [PATCH] pill_typeahead: Simplify fake this objects. --- web/tests/pill_typeahead.test.js | 73 ++++++++++++-------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/web/tests/pill_typeahead.test.js b/web/tests/pill_typeahead.test.js index 69b998c3ab..b0535ed649 100644 --- a/web/tests/pill_typeahead.test.js +++ b/web/tests/pill_typeahead.test.js @@ -146,56 +146,35 @@ run_test("set_up", ({mock_template, override}) => { assert.equal(typeof config.updater, "function"); // test queries - const fake_stream_this = { - query: "#Denmark", - }; - const fake_person_this = { - query: "me", - }; - const fake_group_this = { - query: "test", - }; + const stream_query = "#Denmark"; + const person_query = "me"; + const group_query = "test"; (function test_highlighter() { if (opts.stream) { // Test stream highlighter_html for widgets that allow stream pills. - assert.equal( - config.highlighter_html(denmark, fake_stream_this.query), - $fake_rendered_stream, - ); + assert.equal(config.highlighter_html(denmark, stream_query), $fake_rendered_stream); } if (opts.user_group && opts.user) { // If user is also allowed along with user_group // then we should check that each of them rendered correctly. - assert.equal( - config.highlighter_html(testers, fake_group_this.query), - $fake_rendered_group, - ); - assert.equal( - config.highlighter_html(me, fake_person_this.query), - $fake_rendered_person, - ); + assert.equal(config.highlighter_html(testers, group_query), $fake_rendered_group); + assert.equal(config.highlighter_html(me, person_query), $fake_rendered_person); } if (opts.user && !opts.user_group) { - assert.equal( - config.highlighter_html(me, fake_person_this.query), - $fake_rendered_person, - ); + assert.equal(config.highlighter_html(me, person_query), $fake_rendered_person); } if (!opts.user && opts.user_group) { - assert.equal( - config.highlighter_html(testers, fake_group_this.query), - $fake_rendered_group, - ); + assert.equal(config.highlighter_html(testers, group_query), $fake_rendered_group); } })(); (function test_matcher() { let result; if (opts.stream) { - result = config.matcher(denmark, fake_stream_this.query); + result = config.matcher(denmark, stream_query); assert.ok(result); - result = config.matcher(sweden, fake_stream_this.query); + result = config.matcher(sweden, stream_query); assert.ok(!result); } if (opts.user_group && opts.user) { @@ -204,28 +183,28 @@ run_test("set_up", ({mock_template, override}) => { or group is returned. */ // group query, with correct item. - result = config.matcher(testers, fake_group_this.query); + result = config.matcher(testers, group_query); assert.ok(result); // group query, with wrong item. - result = config.matcher(admins, fake_group_this.query); + result = config.matcher(admins, group_query); assert.ok(!result); // person query with correct item. - result = config.matcher(me, fake_person_this.query); + result = config.matcher(me, person_query); assert.ok(result); // person query with wrong item. - result = config.matcher(jill, fake_person_this.query); + result = config.matcher(jill, person_query); assert.ok(!result); } if (opts.user_group && !opts.user) { - result = config.matcher(testers, fake_group_this.query); + result = config.matcher(testers, group_query); assert.ok(result); - result = config.matcher(admins, fake_group_this.query); + result = config.matcher(admins, group_query); assert.ok(!result); } if (opts.user && !opts.user_group) { - result = config.matcher(me, fake_person_this.query); + result = config.matcher(me, person_query); assert.ok(result); - result = config.matcher(jill, fake_person_this.query); + result = config.matcher(jill, person_query); assert.ok(!result); } })(); @@ -233,17 +212,17 @@ run_test("set_up", ({mock_template, override}) => { (function test_sorter() { if (opts.stream) { sort_streams_called = false; - config.sorter([], fake_stream_this.query); + config.sorter([], stream_query); assert.ok(sort_streams_called); } if (opts.user_group) { sort_recipients_called = false; - config.sorter([testers], fake_group_this.query); + config.sorter([testers], group_query); assert.ok(sort_recipients_called); } if (opts.user) { sort_recipients_called = false; - config.sorter([me], fake_person_this.query); + config.sorter([me], person_query); assert.ok(sort_recipients_called); } })(); @@ -251,7 +230,7 @@ run_test("set_up", ({mock_template, override}) => { (function test_source() { let result; if (opts.stream) { - result = config.source(fake_stream_this.query); + result = config.source(stream_query); const stream_ids = result.map((stream) => stream.stream_id); const expected_stream_ids = [denmark.stream_id, sweden.stream_id]; assert.deepEqual(stream_ids, expected_stream_ids); @@ -262,7 +241,7 @@ run_test("set_up", ({mock_template, override}) => { function is_group(item) { return item.members; } - result = config.source(fake_person_this.query); + result = config.source(person_query); actual_result = result .map((item) => { if (is_group(item)) { @@ -305,11 +284,11 @@ run_test("set_up", ({mock_template, override}) => { return pills.length; } assert.equal(number_of_pills(), 0); - config.updater(denmark, fake_stream_this.query); + config.updater(denmark, stream_query); assert.equal(number_of_pills(), 1); - config.updater(me, fake_person_this.query); + config.updater(me, person_query); assert.equal(number_of_pills(), 2); - config.updater(testers, fake_group_this.query); + config.updater(testers, group_query); assert.equal(number_of_pills(), 3); assert.ok(update_func_called);