2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-06-12 16:09:24 +02:00
|
|
|
const noop = () => {};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
|
|
|
const input = $.create("input");
|
|
|
|
set_global("document", {
|
2019-06-12 16:09:24 +02:00
|
|
|
createElement: () => input,
|
|
|
|
execCommand: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").append = noop;
|
|
|
|
$(input).val = (arg) => {
|
|
|
|
assert.equal(arg, "iago@zulip.com");
|
|
|
|
return {
|
2020-07-20 21:24:26 +02:00
|
|
|
trigger: noop,
|
2019-06-12 16:09:24 +02:00
|
|
|
};
|
|
|
|
};
|
2017-05-23 01:15:43 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("common");
|
2018-08-01 21:17:03 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
|
|
|
common.autofocus("#home");
|
|
|
|
assert($("#home").is_focused());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-06-25 17:14:45 +02:00
|
|
|
|
2020-07-15 01:29:15 +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"));
|
2018-06-25 17:14:45 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(!common.phrase_match("tests", "test"));
|
|
|
|
assert(!common.phrase_match("tes", "hostess"));
|
2018-06-25 17:14:45 +02:00
|
|
|
});
|
2019-06-12 16:09:24 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("copy_data_attribute_value", () => {
|
|
|
|
const elem = $.create(".envelope-link");
|
2019-06-12 16:09:24 +02:00
|
|
|
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);
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
common.copy_data_attribute_value(elem, "admin-emails");
|
2019-06-12 16:09:24 +02:00
|
|
|
});
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("adjust_mac_shortcuts", () => {
|
2019-06-07 11:03:13 +02:00
|
|
|
const keys_to_test_mac = new Map([
|
2020-07-15 01:29:15 +02:00
|
|
|
["Backspace", "Delete"],
|
|
|
|
["Enter", "Return"],
|
|
|
|
["Home", "Fn + ←"],
|
|
|
|
["End", "Fn + →"],
|
|
|
|
["PgUp", "Fn + ↑"],
|
|
|
|
["PgDn", "Fn + ↓"],
|
|
|
|
["X + Shift", "X + Shift"],
|
|
|
|
["⌘ + Return", "⌘ + Return"],
|
|
|
|
["Enter or Backspace", "Return or Delete"],
|
|
|
|
["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([
|
2020-07-15 01:29:15 +02:00
|
|
|
["Backspace", "Backspace"],
|
|
|
|
["Enter", "Enter"],
|
|
|
|
["Home", "Home"],
|
|
|
|
["End", "End"],
|
|
|
|
["PgUp", "PgUp"],
|
|
|
|
["PgDn", "PgDn"],
|
|
|
|
["X + Shift", "X + Shift"],
|
|
|
|
["⌘ + Return", "⌘ + Return"],
|
|
|
|
["Ctrl + Shift", "Ctrl + Shift"],
|
|
|
|
["Ctrl + Backspace + End", "Ctrl + Backspace + End"],
|
2019-06-07 11:03:13 +02:00
|
|
|
]);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let key_no;
|
|
|
|
let keys_elem_list = [];
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
common.has_mac_keyboard = function () {
|
|
|
|
return false;
|
|
|
|
};
|
2019-06-07 11:03:13 +02:00
|
|
|
key_no = 1;
|
2020-07-02 01:45:54 +02:00
|
|
|
keys_to_test_non_mac.forEach((value, key) => {
|
2019-06-07 11:03:13 +02:00
|
|
|
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_non_mac_" + key_no));
|
|
|
|
key_no += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content");
|
2020-07-02 01:45:54 +02:00
|
|
|
keys_elem_list.forEach((key_elem) => {
|
2019-06-07 11:03:13 +02:00
|
|
|
assert(key_elem.text(), key_elem.expected_key());
|
|
|
|
});
|
|
|
|
|
|
|
|
keys_elem_list = [];
|
|
|
|
key_no = 1;
|
2020-07-15 00:34:28 +02:00
|
|
|
common.has_mac_keyboard = function () {
|
|
|
|
return true;
|
|
|
|
};
|
2020-07-02 01:45:54 +02:00
|
|
|
keys_to_test_mac.forEach((value, key) => {
|
2019-06-07 11:03:13 +02:00
|
|
|
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_" + key_no));
|
|
|
|
key_no += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".markdown_content").each = (f) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
for (let key_id = 0; key_id < keys_elem_list.length; key_id += 1) {
|
2019-06-07 11:03:13 +02:00
|
|
|
f.call(keys_elem_list[key_id]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content");
|
2020-07-02 01:45:54 +02:00
|
|
|
keys_elem_list.forEach((key_elem) => {
|
2019-06-07 11:03:13 +02:00
|
|
|
assert.equal(key_elem.text(), key_elem.expected_key());
|
|
|
|
});
|
2019-06-10 09:22:55 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const markdown_hotkey_1 = get_key_stub_html(
|
|
|
|
"Ctrl + Backspace",
|
|
|
|
"⌘ + Delete",
|
|
|
|
"markdown_hotkey_1",
|
|
|
|
);
|
2019-06-10 09:22:55 +02:00
|
|
|
$(".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
|
|
|
});
|