repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

quickshell/nuguland/privilege-ui.test.mjs

Raw
File outline
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const qml = readFileSync(new URL("./shell.qml", import.meta.url), "utf8");
const privilegeQml = readFileSync(new URL("./Privilege.qml", import.meta.url), "utf8");
const barQml = readFileSync(new URL("./Bar.qml", import.meta.url), "utf8");
const popoutQml = readFileSync(new URL("./PopoutHost.qml", import.meta.url), "utf8");
const start = qml.indexOf("component PrivilegeSurface: Rectangle");
const end = qml.indexOf("component NokoFocusOverlay", start);
assert.notEqual(start, -1, "PrivilegeSurface component exists");
assert.notEqual(end, -1, "PrivilegeSurface end marker exists");
const surface = qml.slice(start, end);

assert.match(surface, /id:\s*commandText/, "privilege surface has dedicated command text");
assert.match(surface, /PrivilegeUi\.commandMarkdown/, "command text uses markdown-style formatter");
assert.match(surface, /textFormat:\s*Text\.RichText/, "command text renders rich text");
assert.match(surface, /elide:\s*Text\.ElideNone/, "command text must not truncate");
assert.match(surface, /property bool secretVisible:\s*false/, "password reveal state exists");
assert.match(surface, /id:\s*revealButton/, "password reveal button exists");
assert.match(surface, /echoMode:\s*root\.secretVisible \|\| root\.request\.responseVisible \? TextInput\.Normal : TextInput\.Password/, "reveal button controls password echo mode");
assert.match(surface, /password rejected/, "wrong password message is human-readable");
assert.match(surface, /secretInput\.forceActiveFocus\(\)/, "password input is explicitly focused");
assert.match(surface, /id:\s*focusRetry/, "focus retry timer exists for map-time focus races");
assert.match(qml, /Variants\s*\{\s*model:\s*shell\.primaryScreens[\s\S]*?objectName:\s*"privilegeSecuritySurface"/, "exactly one primary-screen privilege window is instantiated");
assert.match(qml, /id:\s*privilegeSurface/, "privilege surface instance is addressable from PanelWindow");
assert.match(barQml, /privilegeService:\s*root\.privilegeService/, "bar passes privilege state to its popout host");
assert.match(popoutQml, /root\.visible && !root\.privilegeService\.active \? WlrKeyboardFocus\.Exclusive/, "popout releases exclusive keyboard focus during authentication");
assert.match(qml, /visible:\s*privilege\.active \|\| privilege\.error\.length > 0 \|\| privilege\.confirming/, "privilege window stays up for success confirmation");
assert.match(qml, /onVisibleChanged:\s*if \(visible\)\s*Qt\.callLater\(privilegeSurface\.focusSecret\)/, "PanelWindow asks password input for focus after mapping");
assert.match(privilegeQml, /property bool confirming:\s*false/, "privilege service exposes transient success confirmation state");
assert.match(privilegeQml, /property bool awaitingCompletion:\s*false/, "privilege service tracks submitted flows");
assert.match(privilegeQml, /id:\s*successClose/, "success confirmation auto-closes");
assert.match(privilegeQml, /function onIsCompletedChanged\(\)/, "polkit completed state is handled before flow detaches");
assert.match(privilegeQml, /function onIsActiveChanged\(\)/, "polkit inactive fallback finishes submitted flows");
assert.match(surface, /function onConfirmingChanged\(\)/, "surface refreshes after async success state changes");
assert.match(surface, /id:\s*successBanner/, "success banner exists");
assert.match(surface, /authorization granted/, "success title is rendered");
assert.match(surface, /text:\s*"authorized"/, "success banner text is rendered");
assert.doesNotMatch(surface, /requestIdentityCard/, "debug identity card is not rendered");
assert.doesNotMatch(surface, /actionId/, "debug polkit action id is not rendered");

console.log("privilege-ui.test.mjs: ALL PASS");