2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const input_pill = mock_esm("../src/input_pill");
|
2022-07-10 01:06:33 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const search_pill = zrequire("search_pill");
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_starred_item = {
|
2020-07-15 01:29:15 +02:00
|
|
|
display_value: "is:starred",
|
2022-06-19 07:17:16 +02:00
|
|
|
description_html: "starred messages",
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_private_item = {
|
2020-07-15 01:29:15 +02:00
|
|
|
display_value: "is:private",
|
2023-01-24 19:49:56 +01:00
|
|
|
description_html: "direct messages",
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("create_item", () => {
|
2018-06-21 15:11:21 +02:00
|
|
|
function test_create_item(search_string, current_items, expected_item) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const item = search_pill.create_item_from_search_string(search_string, current_items);
|
2018-06-21 15:11:21 +02:00
|
|
|
assert.deepEqual(item, expected_item);
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
test_create_item("is:starred", [], is_starred_item);
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("get_search_string", () => {
|
|
|
|
assert.equal(search_pill.get_search_string_from_item(is_starred_item), "is:starred");
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("append", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended;
|
|
|
|
let cleared;
|
2018-06-21 15:11:21 +02:00
|
|
|
|
|
|
|
function fake_append(search_string) {
|
|
|
|
appended = true;
|
2018-07-14 16:10:00 +02:00
|
|
|
assert.equal(search_string, is_starred_item.display_value);
|
2018-06-21 15:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function fake_clear() {
|
|
|
|
cleared = true;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const pill_widget = {
|
2018-06-21 15:11:21 +02:00
|
|
|
appendValue: fake_append,
|
|
|
|
clear_text: fake_clear,
|
|
|
|
};
|
|
|
|
|
2018-07-14 16:10:00 +02:00
|
|
|
search_pill.append_search_string(is_starred_item.display_value, pill_widget);
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(appended);
|
|
|
|
assert.ok(cleared);
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("get_items", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const items = [is_starred_item, is_private_item];
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const pill_widget = {
|
2020-07-20 22:18:43 +02:00
|
|
|
items() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return items;
|
|
|
|
},
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
search_pill.get_search_string_for_current_filter(pill_widget),
|
|
|
|
is_starred_item.display_value + " " + is_private_item.display_value,
|
|
|
|
);
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test("create_pills", ({override}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let input_pill_create_called = false;
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(input_pill, "create", () => {
|
2018-06-21 15:11:21 +02:00
|
|
|
input_pill_create_called = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
return {dummy: "dummy"};
|
2021-02-28 21:29:50 +01:00
|
|
|
});
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const pills = search_pill.create_pills({});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(input_pill_create_called);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(pills, {dummy: "dummy"});
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|