hotkey: Fix "e shortcut works for anonymous users" test.

In f768d3330b, the node test
written was a noop because "e" hotkey is handled by `keypress`
instead of `keydown`. So, the expected codepath was never getting
executed at all.

This commit fixes the test.
This commit is contained in:
Prakhar Pratyush
2025-05-08 16:40:32 +05:30
committed by Tim Abbott
parent 2405bbbe84
commit 6e18aad7a6

View File

@@ -2,8 +2,6 @@
const assert = require("node:assert/strict");
const {process_keydown} = require("../src/hotkey.js");
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace.cjs");
const {make_stub} = require("./lib/stub.cjs");
const {run_test} = require("./lib/test.cjs");
@@ -573,17 +571,22 @@ run_test("test new user input hook called", () => {
assert.ok(hook_called);
});
run_test("e shortcut works for anonymous users", ({override_rewire}) => {
test_while_not_editing_text("e shortcut works for anonymous users", ({override_rewire}) => {
page_params.is_spectator = true;
const stub = make_stub();
override_rewire(spectators, "login_to_access", stub.f);
overlays.any_active = () => false;
overlays.settings_open = () => false;
const e = {
which: "e".codePointAt(0),
};
process_keydown(e);
stubbing(message_edit, "start", (stub) => {
hotkey.process_keypress(e);
assert.equal(stub.num_calls, 1);
});
assert.equal(stub.num_calls, 0, "login_to_access should not be called for 'e' shortcut");
// Fake call to avoid warning about unused stub.
spectators.login_to_access();