Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/agent/test/screen-keys.test.mjs
iris ff7215a4b1 agent: let the screen page keep reload, the address bar and its own buttons
The page forwarded every key to the remote desktop and cancelled it, so F5 and
Ctrl+R could not reload, though the disconnect message tells the operator to
reload, and Enter or Space on the fit and debug buttons did nothing. F5, F12,
Ctrl/Cmd+R, Ctrl/Cmd+L and any key pressed on a button now go to the browser;
the rest still go to the remote desktop. The filter is a small module with a
test, bundled for the page as static/screen-keys.js, and the agent-page doc
describes it.
2026-11-25 19:50:22 +01:00

40 lines
1.4 KiB
JavaScript

// Which keys the screen page leaves to the browser. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { keepForBrowser } from "../src/screen-keys.js";
const plain = { closest: () => null };
const button = { closest: (sel) => (sel === "button" ? {} : null) };
test("reload, the address bar and the dev tools stay with the browser", () => {
assert.equal(keepForBrowser({ key: "F5", target: plain }), true);
assert.equal(keepForBrowser({ key: "F12", target: plain }), true);
assert.equal(
keepForBrowser({ key: "r", ctrlKey: true, target: plain }),
true,
);
assert.equal(
keepForBrowser({ key: "R", metaKey: true, target: plain }),
true,
);
assert.equal(
keepForBrowser({ key: "l", ctrlKey: true, target: plain }),
true,
);
});
test("a key pressed on a button stays with the button", () => {
assert.equal(keepForBrowser({ key: "Enter", target: button }), true);
assert.equal(keepForBrowser({ key: " ", target: button }), true);
});
test("everything else goes to the remote desktop", () => {
assert.equal(keepForBrowser({ key: "a", target: plain }), false);
assert.equal(keepForBrowser({ key: "r", target: plain }), false);
assert.equal(
keepForBrowser({ key: "c", ctrlKey: true, target: plain }),
false,
);
assert.equal(keepForBrowser({ key: "F4", target: plain }), false);
assert.equal(keepForBrowser({ key: "Enter" }), false);
});