const test = require("node:test"); const assert = require("node:assert/strict"); const content = require("./content.js"); test("inlineMatchSummary includes username, host, and path context", () => { const summary = content.inlineMatchSummary({ username: "dannyocean", url: "https://vault.example.invalid/login", path: ["Root", "Crew"] }); assert.equal(summary, "dannyocean · vault.example.invalid · Root / Crew"); }); test("domainLabel tolerates invalid URLs", () => { assert.equal(content.domainLabel("https://vault.example.invalid"), "vault.example.invalid"); assert.equal(content.domainLabel("not-a-url"), ""); }); test("describeFieldRole only treats explicit account fields as usernames", () => { const loginField = { autocomplete: "username", labels: [], getAttribute(name) { const attrs = { type: "email", id: "crew-email", name: "email", placeholder: "Email address", "aria-label": "Email address" }; return attrs[name] || ""; } }; const searchField = { autocomplete: "", labels: [], getAttribute(name) { const attrs = { type: "text", id: "site-search", name: "query", placeholder: "Search casino news", "aria-label": "Search" }; return attrs[name] || ""; } }; assert.equal(content.describeFieldRole(loginField), "username"); assert.equal(content.describeFieldRole(searchField), ""); }); test("hasAuthFlowSignals rejects generic password scopes and accepts sign-in scopes", () => { const genericScope = { getAttribute() { return ""; }, querySelectorAll() { return [{ textContent: "Confirm shipment" }]; } }; const signInScope = { getAttribute(name) { const attrs = { id: "signin-panel", name: "signin", action: "/session" }; return attrs[name] || ""; }, querySelectorAll() { return [{ textContent: "Sign in to the Bellagio vault" }]; } }; assert.equal(content.hasAuthFlowSignals(null, genericScope), false); assert.equal(content.hasAuthFlowSignals(null, signInScope), true); assert.equal(content.hasAuthFlowSignals({ id: "danny-ocean" }, genericScope), true); }); test("shouldShowInlineOverlay hides the page overlay after it is suppressed", () => { const state = { pageHasLoginForm: true, configured: true, success: true, status: { locked: false }, matches: [{ id: "vault-console" }], pendingFill: false }; assert.equal(content.shouldShowInlineOverlay(state, true, false), true); assert.equal(content.shouldShowInlineOverlay(state, true, true, false), false); }); test("shouldShowInlineOverlay hides the page overlay after idle expiry", () => { const state = { pageHasLoginForm: true, configured: true, success: true, status: { locked: false }, matches: [{ id: "rusty-ryan" }], pendingFill: false }; assert.equal(content.shouldShowInlineOverlay(state, true, false, false), true); assert.equal(content.shouldShowInlineOverlay(state, true, false, true), false); });