2018-06-21 15:11:21 +02:00
|
|
|
zrequire('search_pill');
|
|
|
|
zrequire('util');
|
|
|
|
zrequire('input_pill');
|
|
|
|
zrequire('Filter', 'js/filter');
|
2019-07-12 02:03:55 +02:00
|
|
|
set_global('Handlebars', global.make_handlebars());
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_starred_item = {
|
2018-07-14 16:10:00 +02:00
|
|
|
display_value: 'is:starred',
|
|
|
|
description: 'starred messages',
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_private_item = {
|
2018-07-14 16:10:00 +02:00
|
|
|
display_value: 'is:private',
|
|
|
|
description: 'private messages',
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
run_test('create_item', () => {
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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', () => {
|
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
|
|
|
|
|
|
|
assert(appended);
|
|
|
|
assert(cleared);
|
|
|
|
});
|
|
|
|
|
|
|
|
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 = {
|
2018-06-21 15:11:21 +02:00
|
|
|
items: function () { return items; },
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(search_pill.get_search_string_for_current_filter(pill_widget),
|
2018-07-14 16:10:00 +02:00
|
|
|
is_starred_item.display_value + ' ' + is_private_item.display_value);
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test('create_pills', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let input_pill_create_called = false;
|
2018-06-21 15:11:21 +02:00
|
|
|
|
|
|
|
input_pill.create = function () {
|
|
|
|
input_pill_create_called = true;
|
|
|
|
return {dummy: 'dummy'};
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const pills = search_pill.create_pills({});
|
2018-06-21 15:11:21 +02:00
|
|
|
assert(input_pill_create_called);
|
2019-02-15 23:38:59 +01:00
|
|
|
assert.deepEqual(pills, {dummy: 'dummy'});
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|