// The header menus share one popover. Run by `npm test`. Each menu's // stylesheet must pull in `HeaderMenu.css` and keep no popover of its own, so // a fifth menu can't quietly bring back a copy with its own offset or shadow. import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { test } from "node:test"; const read = (rel) => readFileSync(new URL(rel, import.meta.url), "utf8"); const MENUS = [ ["links", "../../shared/src/links-menu/LinksMenu.css"], ["user", "../../shared/src/user-menu/UserMenu.css"], ["settings", "../../shared/src/settings/SettingsMenu.css"], ["alerts", "../src/shell/AlertsMenu.css"], ]; for (const [name, file] of MENUS) { test(`the ${name} menu uses the shared popover`, () => { const css = read(file); assert.match(css, /@import "[^"]*header-menu(\/HeaderMenu)?\.css";/); assert.ok(!/-popover\s*\{/.test(css), `${name}: has its own popover rule`); assert.ok( !/position:\s*absolute;[\s\S]*?z-index/.test( css.replace(/\.alerts-menu-count \{[\s\S]*?\}/, ""), ), ); }); } test("the shared popover is the one that floats", () => { const css = read("../../shared/src/header-menu/HeaderMenu.css"); assert.match(css, /\.header-menu-popover \{[^}]*z-index: var\(--z-popover\)/); assert.match(css, /box-shadow: var\(--shadow-pop\)/); });