snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
221
web/tests/common.test.cjs
Normal file
221
web/tests/common.test.cjs
Normal file
@@ -0,0 +1,221 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {mock_esm, set_global, zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test, noop} = require("./lib/test.cjs");
|
||||
const blueslip = require("./lib/zblueslip.cjs");
|
||||
const {$} = require("./lib/zjquery.cjs");
|
||||
|
||||
mock_esm("tippy.js", {
|
||||
default(arg) {
|
||||
arg._tippy = {setContent: noop};
|
||||
return arg._tippy;
|
||||
},
|
||||
});
|
||||
|
||||
set_global("document", {});
|
||||
const navigator = set_global("navigator", {});
|
||||
|
||||
const common = zrequire("common");
|
||||
|
||||
run_test("phrase_match", () => {
|
||||
assert.ok(common.phrase_match("tes", "test"));
|
||||
assert.ok(common.phrase_match("Tes", "test"));
|
||||
assert.ok(common.phrase_match("Tes", "Test"));
|
||||
assert.ok(common.phrase_match("tes", "Stream Test"));
|
||||
assert.ok(common.phrase_match("", "test"));
|
||||
|
||||
assert.ok(!common.phrase_match("tests", "test"));
|
||||
assert.ok(!common.phrase_match("tes", "hostess"));
|
||||
});
|
||||
|
||||
run_test("adjust_mac_kbd_tags non-mac", ({override}) => {
|
||||
override(navigator, "platform", "Windows");
|
||||
|
||||
// The adjust_mac_kbd_tags 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_kbd_tags("selector-that-does-not-exist");
|
||||
});
|
||||
|
||||
run_test("adjust_mac_kbd_tags mac", ({override}) => {
|
||||
const keys_to_test_mac = new Map([
|
||||
["Backspace", "Delete"],
|
||||
["Enter", "Return"],
|
||||
["Ctrl", "⌘"],
|
||||
["Alt", "⌥"],
|
||||
["#stream_name", "#stream_name"],
|
||||
["Ctrl+K", "Ctrl+K"],
|
||||
["[", "["],
|
||||
["X", "X"],
|
||||
["data-mac-following-key", "data-mac-following-key"],
|
||||
]);
|
||||
|
||||
override(navigator, "platform", "MacIntel");
|
||||
$("<span>").set_contents($("<contents-stub>"));
|
||||
|
||||
const test_items = [];
|
||||
let key_no = 1;
|
||||
|
||||
for (const [old_key, mac_key] of keys_to_test_mac) {
|
||||
const test_item = {};
|
||||
const $stub = $.create("hotkey_" + key_no);
|
||||
$stub.text(old_key);
|
||||
if (old_key === "data-mac-following-key") {
|
||||
$stub.attr("data-mac-following-key", "⌥");
|
||||
$stub[0].after = (plus, element) => {
|
||||
assert.equal(plus.innerHTML, "<contents-stub>");
|
||||
assert.equal(element.innerHTML, "<kbd>");
|
||||
assert.equal(element.textContent, $stub.attr("data-mac-following-key"));
|
||||
};
|
||||
}
|
||||
test_item.$stub = $stub;
|
||||
test_item.mac_key = mac_key;
|
||||
test_items.push(test_item);
|
||||
key_no += 1;
|
||||
}
|
||||
|
||||
const elements = test_items.map((test_item) => ({to_$: () => test_item.$stub}));
|
||||
|
||||
$.create(".markdown kbd", {elements});
|
||||
|
||||
common.adjust_mac_kbd_tags(".markdown kbd");
|
||||
|
||||
for (const test_item of test_items) {
|
||||
assert.equal(test_item.$stub.text(), test_item.mac_key);
|
||||
}
|
||||
});
|
||||
|
||||
run_test("adjust_mac_hotkey_hints non-mac", ({override}) => {
|
||||
override(navigator, "platform", "Windows");
|
||||
|
||||
// The adjust_mac_hotkey_hints 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_hotkey_hints("not-an-array");
|
||||
});
|
||||
|
||||
// Test default values of adjust_mac_hotkey_hints
|
||||
// Expected values
|
||||
run_test("adjust_mac_hotkey_hints mac expected", ({override}) => {
|
||||
const keys_to_test_mac = new Map([
|
||||
[["Backspace"], ["Delete"]],
|
||||
[["Enter"], ["Return"]],
|
||||
[["Ctrl"], ["⌘"]],
|
||||
]);
|
||||
|
||||
override(navigator, "platform", "MacIntel");
|
||||
|
||||
const test_items = [];
|
||||
|
||||
for (const [old_key, mac_key] of keys_to_test_mac) {
|
||||
const test_item = {};
|
||||
common.adjust_mac_hotkey_hints(old_key);
|
||||
|
||||
test_item.mac_key = mac_key;
|
||||
test_item.adjusted_key = old_key;
|
||||
test_items.push(test_item);
|
||||
}
|
||||
|
||||
for (const test_item of test_items) {
|
||||
assert.deepStrictEqual(test_item.mac_key, test_item.adjusted_key);
|
||||
}
|
||||
});
|
||||
|
||||
// Test non-default values of adjust_mac_hotkey_hints
|
||||
// Random values
|
||||
run_test("adjust_mac_hotkey_hints mac random", ({override}) => {
|
||||
const keys_to_test_mac = new Map([
|
||||
[
|
||||
["Ctrl", "["],
|
||||
["⌘", "["],
|
||||
],
|
||||
[
|
||||
["Ctrl", "K"],
|
||||
["⌘", "K"],
|
||||
],
|
||||
[
|
||||
["Shift", "G"],
|
||||
["Shift", "G"],
|
||||
],
|
||||
[["Space"], ["Space"]],
|
||||
]);
|
||||
|
||||
override(navigator, "platform", "MacIntel");
|
||||
|
||||
const test_items = [];
|
||||
|
||||
for (const [old_key, mac_key] of keys_to_test_mac) {
|
||||
const test_item = {};
|
||||
common.adjust_mac_hotkey_hints(old_key);
|
||||
|
||||
test_item.mac_key = mac_key;
|
||||
test_item.adjusted_key = old_key;
|
||||
test_items.push(test_item);
|
||||
}
|
||||
|
||||
for (const test_item of test_items) {
|
||||
assert.deepStrictEqual(test_item.mac_key, test_item.adjusted_key);
|
||||
}
|
||||
});
|
||||
|
||||
run_test("reset password toggle icons with missing toggle", () => {
|
||||
// Password manager extensions can rearrange the DOM around
|
||||
// password inputs such that the toggle selector matches nothing.
|
||||
const password_selector = "#mangled_password ~ .password_visibility_toggle";
|
||||
$.create(password_selector, {elements: []});
|
||||
|
||||
blueslip.expect("error", "Password visibility toggle not found");
|
||||
common.reset_password_toggle_icons("#mangled_password", password_selector);
|
||||
assert.equal($("#mangled_password").attr("type"), "password");
|
||||
});
|
||||
|
||||
run_test("show password", () => {
|
||||
const password_selector = "#id_password ~ .password_visibility_toggle";
|
||||
|
||||
function set_attribute(type) {
|
||||
$("#id_password").attr("type", type);
|
||||
}
|
||||
|
||||
function check_assertion(type, present_class, absent_class) {
|
||||
assert.equal($("#id_password").attr("type"), type);
|
||||
assert.ok($(password_selector).hasClass(present_class));
|
||||
assert.ok(!$(password_selector).hasClass(absent_class));
|
||||
}
|
||||
|
||||
const click_ev = {
|
||||
preventDefault() {},
|
||||
stopPropagation() {},
|
||||
};
|
||||
|
||||
const key_ev = {
|
||||
key: "Enter",
|
||||
preventDefault() {},
|
||||
stopPropagation() {},
|
||||
};
|
||||
|
||||
set_attribute("password");
|
||||
common.setup_password_visibility_toggle("#id_password", password_selector);
|
||||
|
||||
const click_handler = $(password_selector).get_on_handler("click");
|
||||
|
||||
const key_handler = $(password_selector).get_on_handler("keydown");
|
||||
|
||||
click_handler(click_ev);
|
||||
check_assertion("text", "zulip-icon-show", "zulip-icon-hide");
|
||||
|
||||
click_handler(click_ev);
|
||||
check_assertion("password", "zulip-icon-hide", "zulip-icon-show");
|
||||
|
||||
key_handler(key_ev);
|
||||
check_assertion("text", "zulip-icon-show", "zulip-icon-hide");
|
||||
|
||||
key_handler(key_ev);
|
||||
check_assertion("password", "zulip-icon-hide", "zulip-icon-show");
|
||||
|
||||
click_handler(click_ev);
|
||||
|
||||
common.reset_password_toggle_icons("#id_password", password_selector);
|
||||
check_assertion("password", "zulip-icon-hide", "zulip-icon-show");
|
||||
});
|
||||
Reference in New Issue
Block a user