// Tests for the debug/testnet banner (issue #375). // // On a testnet the banner is raised even in a release build, but it must not // append the active view's internal id: the user should see "[TESTNET]", never // "[TESTNET] (approve-tx)". The suffix is gated on the compile-time DEBUG // constant, which is false in a plain test load, so this drives exactly the // text a shipped build renders. Revert the gate to the old unconditional // suffix and this fails. // // The banner is created on demand by updateDebugBanner(); the document stub // records what it prepends so the assertion can read the resulting text. function makeBanner() { return { id: "", textContent: "", style: { cssText: "" }, remove() {}, }; } function makeDocument() { let banner = null; return { getElementById(id) { return id === "debug-banner" ? banner : null; }, createElement: () => makeBanner(), body: { prepend(node) { banner = node; }, }, }; } function load() { jest.resetModules(); globalThis.chrome = { storage: { local: { get: async () => ({}), set: async () => {} } }, }; globalThis.document = makeDocument(); const helpers = require("../src/popup/views/helpers"); const { state } = require("../src/shared/state"); return { helpers, state }; } describe("the release banner on a testnet", () => { test("carries no internal view id", () => { const { helpers, state } = load(); state.networkId = "sepolia"; helpers.updateDebugBanner("approve-tx"); expect( globalThis.document.getElementById("debug-banner").textContent, ).toBe("[TESTNET]"); }); });