2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2019-06-12 16:09:24 +02:00
|
|
|
const noop = () => {};
|
|
|
|
|
2021-02-21 12:18:01 +01:00
|
|
|
set_global("document", {});
|
2017-05-23 01:15:43 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const common = zrequire("common");
|
2018-08-01 21:17:03 +02:00
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("basics", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
common.autofocus("#home");
|
|
|
|
assert($("#home").is_focused());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-06-25 17:14:45 +02:00
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("phrase_match", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
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
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("copy_data_attribute_value", (override) => {
|
2021-02-21 12:18:01 +01:00
|
|
|
const admin_emails_val = "iago@zulip.com";
|
|
|
|
|
|
|
|
const input = $.create("input");
|
|
|
|
|
2021-02-25 16:07:04 +01:00
|
|
|
let removed;
|
|
|
|
input.remove = () => {
|
|
|
|
removed = true;
|
|
|
|
};
|
|
|
|
|
2021-02-21 12:18:01 +01:00
|
|
|
override(document, "createElement", () => input);
|
|
|
|
override(document, "execCommand", noop);
|
|
|
|
|
|
|
|
$("body").append = noop;
|
|
|
|
$(input).val = (arg) => {
|
|
|
|
assert.equal(arg, admin_emails_val);
|
|
|
|
return {
|
|
|
|
trigger: noop,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-09 14:37:01 +01:00
|
|
|
const elem = {};
|
|
|
|
let faded_in = false;
|
|
|
|
let faded_out = false;
|
|
|
|
|
2019-06-12 16:09:24 +02:00
|
|
|
elem.data = (key) => {
|
2021-02-09 14:37:01 +01:00
|
|
|
assert.equal(key, "admin-emails");
|
|
|
|
return admin_emails_val;
|
2019-06-12 16:09:24 +02:00
|
|
|
};
|
|
|
|
elem.fadeOut = (val) => {
|
|
|
|
assert.equal(val, 250);
|
2021-02-09 14:37:01 +01:00
|
|
|
faded_out = true;
|
2019-06-12 16:09:24 +02:00
|
|
|
};
|
|
|
|
elem.fadeIn = (val) => {
|
|
|
|
assert.equal(val, 1000);
|
2021-02-09 14:37:01 +01:00
|
|
|
faded_in = true;
|
2019-06-12 16:09:24 +02:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
common.copy_data_attribute_value(elem, "admin-emails");
|
2021-02-25 16:07:04 +01:00
|
|
|
assert(removed);
|
2021-02-09 14:37:01 +01:00
|
|
|
assert(faded_in);
|
|
|
|
assert(faded_out);
|
2019-06-12 16:09:24 +02:00
|
|
|
});
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2021-03-07 17:01:11 +01:00
|
|
|
run_test("adjust_mac_shortcuts non-mac", (override) => {
|
|
|
|
override(common, "has_mac_keyboard", () => false);
|
2021-02-08 16:51:15 +01:00
|
|
|
|
|
|
|
// The adjust_mac_shortcuts has a really simple guard
|
|
|
|
// at the top, and we just test the early-return behavior
|
|
|
|
// by trying to pass it garbage.
|
|
|
|
common.adjust_mac_shortcuts("selector-that-does-not-exist");
|
|
|
|
});
|
|
|
|
|
2021-03-07 17:01:11 +01:00
|
|
|
run_test("adjust_mac_shortcuts mac", (override) => {
|
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
|
|
|
]);
|
|
|
|
|
2021-03-07 17:01:11 +01:00
|
|
|
override(common, "has_mac_keyboard", () => true);
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2021-02-09 12:12:12 +01:00
|
|
|
const test_items = [];
|
2021-02-08 16:51:15 +01:00
|
|
|
let key_no = 1;
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2021-02-09 12:12:12 +01:00
|
|
|
for (const [old_key, mac_key] of keys_to_test_mac) {
|
|
|
|
const test_item = {};
|
|
|
|
const stub = $.create("hotkey_" + key_no);
|
|
|
|
stub.text(old_key);
|
|
|
|
assert.equal(stub.hasClass("mac-cmd-key"), false);
|
|
|
|
test_item.stub = stub;
|
|
|
|
test_item.mac_key = mac_key;
|
|
|
|
test_item.is_cmd_key = old_key.includes("Ctrl");
|
|
|
|
test_items.push(test_item);
|
2019-06-07 11:03:13 +02:00
|
|
|
key_no += 1;
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2019-06-07 11:03:13 +02:00
|
|
|
|
2021-02-09 12:12:12 +01:00
|
|
|
const children = test_items.map((test_item) => ({to_$: () => test_item.stub}));
|
2019-06-10 09:22:55 +02:00
|
|
|
|
2021-02-09 12:12:12 +01:00
|
|
|
$.create(".markdown_content", {children});
|
|
|
|
|
|
|
|
const require_cmd = true;
|
|
|
|
common.adjust_mac_shortcuts(".markdown_content", require_cmd);
|
|
|
|
|
|
|
|
for (const test_item of test_items) {
|
|
|
|
assert.equal(test_item.stub.hasClass("mac-cmd-key"), test_item.is_cmd_key);
|
|
|
|
assert.equal(test_item.stub.text(), test_item.mac_key);
|
|
|
|
}
|
2019-06-07 11:03:13 +02:00
|
|
|
});
|