mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
For most functions that we were using __Rewire__ for, it's better to just use the override helper, which use __Rewire__ under the hood, but also resets the reference at the end of run_tests. Another nice thing about override() is that it reports when you never actually needed the mock, and this commit fixes the instances found here. I didn't replace every call to __Rewire__. The remaining ones fall under these categories: * I looked for ") =>" in my code sweep, so I missed stuff like "noop" helpers. * Sometimes we directly update something in a module that's not a function. This is generally evil, and we should use setters. * Some tests have setup() helpers or similar that complicated this code sweep, so I simply punted. * Somes modules rely on intra-test leaks. We should fix those, but I just punted for the main code sweep.
85 lines
2.1 KiB
JavaScript
85 lines
2.1 KiB
JavaScript
"use strict";
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
|
const {run_test} = require("../zjsunit/test");
|
|
|
|
const search_pill = zrequire("search_pill");
|
|
const input_pill = zrequire("input_pill");
|
|
|
|
const is_starred_item = {
|
|
display_value: "is:starred",
|
|
description: "starred messages",
|
|
};
|
|
|
|
const is_private_item = {
|
|
display_value: "is:private",
|
|
description: "private messages",
|
|
};
|
|
|
|
run_test("create_item", () => {
|
|
function test_create_item(search_string, current_items, expected_item) {
|
|
const item = search_pill.create_item_from_search_string(search_string, current_items);
|
|
assert.deepEqual(item, expected_item);
|
|
}
|
|
|
|
test_create_item("is:starred", [], is_starred_item);
|
|
});
|
|
|
|
run_test("get_search_string", () => {
|
|
assert.equal(search_pill.get_search_string_from_item(is_starred_item), "is:starred");
|
|
});
|
|
|
|
run_test("append", () => {
|
|
let appended;
|
|
let cleared;
|
|
|
|
function fake_append(search_string) {
|
|
appended = true;
|
|
assert.equal(search_string, is_starred_item.display_value);
|
|
}
|
|
|
|
function fake_clear() {
|
|
cleared = true;
|
|
}
|
|
|
|
const pill_widget = {
|
|
appendValue: fake_append,
|
|
clear_text: fake_clear,
|
|
};
|
|
|
|
search_pill.append_search_string(is_starred_item.display_value, pill_widget);
|
|
|
|
assert(appended);
|
|
assert(cleared);
|
|
});
|
|
|
|
run_test("get_items", () => {
|
|
const items = [is_starred_item, is_private_item];
|
|
|
|
const pill_widget = {
|
|
items() {
|
|
return items;
|
|
},
|
|
};
|
|
|
|
assert.deepEqual(
|
|
search_pill.get_search_string_for_current_filter(pill_widget),
|
|
is_starred_item.display_value + " " + is_private_item.display_value,
|
|
);
|
|
});
|
|
|
|
run_test("create_pills", (override) => {
|
|
let input_pill_create_called = false;
|
|
|
|
override(input_pill, "create", () => {
|
|
input_pill_create_called = true;
|
|
return {dummy: "dummy"};
|
|
});
|
|
|
|
const pills = search_pill.create_pills({});
|
|
assert(input_pill_create_called);
|
|
assert.deepEqual(pills, {dummy: "dummy"});
|
|
});
|