2019-06-12 16:09:24 +02:00
|
|
|
const noop = () => {};
|
|
|
|
|
2017-05-25 01:49:29 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2019-06-12 16:09:24 +02:00
|
|
|
const input = $.create('input');
|
|
|
|
set_global('document', {
|
|
|
|
createElement: () => input,
|
|
|
|
execCommand: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").append = noop;
|
|
|
|
$(input).val = (arg) => {
|
|
|
|
assert.equal(arg, "iago@zulip.com");
|
|
|
|
return {
|
|
|
|
select: noop,
|
|
|
|
};
|
|
|
|
};
|
2017-05-23 01:15:43 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
zrequire('common');
|
|
|
|
|
2019-06-07 11:03:13 +02:00
|
|
|
function get_key_stub_html(key_text, expected_key, obj_name) {
|
|
|
|
const key_stub = $.create(obj_name);
|
|
|
|
key_stub.text(key_text);
|
|
|
|
key_stub.expected_key = function () {
|
|
|
|
return expected_key;
|
|
|
|
};
|
|
|
|
return key_stub;
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basics', () => {
|
2017-05-23 01:15:43 +02:00
|
|
|
common.autofocus('#home');
|
2017-05-24 03:41:47 +02:00
|
|
|
assert($('#home').is_focused());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-06-25 17:14:45 +02:00
|
|
|
|
|
|
|
run_test('phrase_match', () => {
|
|
|
|
assert(common.phrase_match('tes', 'test'));
|
|
|
|
assert(common.phrase_match('Tes', 'test'));
|
|
|
|
assert(common.phrase_match('Tes', 'Test'));
|
|
|
|
assert(common.phrase_match('tes', 'Stream Test'));
|
|
|
|
|
|
|
|
assert(!common.phrase_match('tests', 'test'));
|
|
|
|
assert(!common.phrase_match('tes', 'hostess'));
|
|
|
|
});
|
2019-06-12 16:09:24 +02:00
|
|
|
|
|
|
|
run_test('copy_data_attribute_value', () => {
|
|
|
|
var elem = $.create('.envelope-link');
|
|
|
|
elem.data = (key) => {
|
|
|
|
if (key === "admin-emails") {
|
|
|
|
return "iago@zulip.com";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
elem.fadeOut = (val) => {
|
|
|
|
assert.equal(val, 250);
|
|
|
|
};
|
|
|
|
elem.fadeIn = (val) => {
|
|
|
|
assert.equal(val, 1000);
|
|
|
|
};
|
|
|
|
common.copy_data_attribute_value(elem, 'admin-emails');
|
|
|
|
});
|
2019-06-07 11:03:13 +02:00
|
|
|
|
|
|
|
run_test('adjust_mac_shortcuts', () => {
|
|
|
|
const keys_to_test_mac = new Map([
|
|
|
|
['Backspace', 'Delete'],
|
|
|
|
['Enter', 'Return'],
|
|
|
|
['Home', 'Fn + ←'],
|
|
|
|
['End', 'Fn + →'],
|
|
|
|
['PgUp', 'Fn + ↑'],
|
|
|
|
['PgDn', 'Fn + ↓'],
|
|
|
|
['X + Shift', 'X + Shift'],
|
|
|
|
['⌘ + Return', '⌘ + Return'],
|
|
|
|
['Enter or Backspace', "Return or Delete"],
|
2019-06-10 09:22:55 +02:00
|
|
|
['Ctrl', '⌘'],
|
|
|
|
['Ctrl + Shift', '⌘ + Shift'],
|
|
|
|
['Ctrl + Backspace + End', '⌘ + Delete + Fn + →'],
|
2019-06-07 11:03:13 +02:00
|
|
|
]);
|
|
|
|
const keys_to_test_non_mac = new Map([
|
|
|
|
['Backspace', 'Backspace'],
|
|
|
|
['Enter', 'Enter'],
|
|
|
|
['Home', 'Home'],
|
|
|
|
['End', 'End'],
|
|
|
|
['PgUp', 'PgUp'],
|
|
|
|
['PgDn', 'PgDn'],
|
|
|
|
['X + Shift', 'X + Shift'],
|
|
|
|
['⌘ + Return', '⌘ + Return'],
|
2019-06-10 09:22:55 +02:00
|
|
|
['Ctrl + Shift', 'Ctrl + Shift'],
|
|
|
|
['Ctrl + Backspace + End', 'Ctrl + Backspace + End'],
|
2019-06-07 11:03:13 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
var key_no;
|
|
|
|
var keys_elem_list = [];
|
|
|
|
|
|
|
|
common.has_mac_keyboard = function () { return false; };
|
|
|
|
key_no = 1;
|
|
|
|
keys_to_test_non_mac.forEach(function (value, key) {
|
|
|
|
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_non_mac_" + key_no));
|
|
|
|
key_no += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content");
|
|
|
|
keys_elem_list.forEach(function (key_elem) {
|
|
|
|
assert(key_elem.text(), key_elem.expected_key());
|
|
|
|
});
|
|
|
|
|
|
|
|
keys_elem_list = [];
|
|
|
|
key_no = 1;
|
|
|
|
common.has_mac_keyboard = function () { return true; };
|
|
|
|
keys_to_test_mac.forEach(function (value, key) {
|
|
|
|
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_" + key_no));
|
|
|
|
key_no += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".markdown_content").each = (f) => {
|
|
|
|
for (var key_id = 0; key_id < keys_elem_list.length; key_id += 1) {
|
|
|
|
f.call(keys_elem_list[key_id]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content");
|
|
|
|
keys_elem_list.forEach(function (key_elem) {
|
|
|
|
assert.equal(key_elem.text(), key_elem.expected_key());
|
|
|
|
});
|
2019-06-10 09:22:55 +02:00
|
|
|
|
|
|
|
var markdown_hotkey_1 = get_key_stub_html("Ctrl + Backspace", "⌘ + Delete", "markdown_hotkey_1");
|
|
|
|
$(".markdown_content").each = (f) => {
|
|
|
|
f.call(markdown_hotkey_1);
|
|
|
|
};
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content", true);
|
|
|
|
assert.equal(markdown_hotkey_1.text(), markdown_hotkey_1.expected_key());
|
|
|
|
assert.equal(markdown_hotkey_1.hasClass("mac-cmd-key"), true);
|
2019-06-07 11:03:13 +02:00
|
|
|
});
|