import assert from 'node:assert/strict' import fs from 'node:fs' import path from 'node:path' import test from 'node:test' import { fileURLToPath } from 'node:url' import { loadTestModule } from './load-test-module.mjs' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const appCSSPath = path.resolve(__dirname, '../src/styles/app.css') const { hasVisibleDialog, isDialogElementVisible } = await loadTestModule(`export * from './lib/dialogState'`) const { resolvePluginApprovalNotice } = await loadTestModule(`export { resolvePluginApprovalNotice } from './components/PluginParts'`) function fakeDialog({ display = 'block', visibility = 'visible', ariaHidden = null, hidden = false, inert = false, dataState = null, parentElement = null, } = {}) { const el = { parentElement, getAttribute(name) { if (name === 'aria-hidden') return ariaHidden if (name === 'hidden') return hidden ? '' : null if (name === 'inert') return inert ? '' : null if (name === 'data-state') return dataState return null }, closest() { return null }, } return { el, style: { display, visibility } } } test('hidden dialog elements (including ancestor display:none, inert, and closed state) do not block shortcuts', () => { const hiddenDisplay = fakeDialog({ display: 'none' }) const hiddenVis = fakeDialog({ visibility: 'hidden' }) const hiddenCollapse = fakeDialog({ visibility: 'collapse' }) const hiddenAttr = fakeDialog({ hidden: true }) const hiddenInert = fakeDialog({ inert: true }) const hiddenAria = fakeDialog({ ariaHidden: 'true' }) const closedState = fakeDialog({ dataState: 'closed' }) const hiddenParent = fakeDialog({ display: 'none' }) const childOfHiddenParent = fakeDialog({ parentElement: hiddenParent.el }) const visibleParent = fakeDialog({ display: 'block' }) const visible = fakeDialog({ parentElement: visibleParent.el }) const styles = new Map([ [hiddenDisplay.el, hiddenDisplay.style], [hiddenVis.el, hiddenVis.style], [hiddenCollapse.el, hiddenCollapse.style], [hiddenAttr.el, hiddenAttr.style], [hiddenInert.el, hiddenInert.style], [hiddenAria.el, hiddenAria.style], [closedState.el, closedState.style], [hiddenParent.el, hiddenParent.style], [childOfHiddenParent.el, childOfHiddenParent.style], [visibleParent.el, visibleParent.style], [visible.el, visible.style], ]) const getStyle = (node) => styles.get(node) ?? { display: 'block', visibility: 'visible' } for (const hiddenCase of [ hiddenDisplay, hiddenVis, hiddenCollapse, hiddenAttr, hiddenInert, hiddenAria, closedState, childOfHiddenParent, ]) { assert.equal(isDialogElementVisible(hiddenCase.el, getStyle), false) } assert.equal(isDialogElementVisible(visible.el, getStyle), true) assert.equal( hasVisibleDialog( { querySelectorAll: () => [hiddenDisplay.el, hiddenVis.el, childOfHiddenParent.el, closedState.el] }, getStyle, ), false, ) assert.equal( hasVisibleDialog({ querySelectorAll: () => [childOfHiddenParent.el, visible.el] }, getStyle), true, ) }) test('L1 ui:script plugins receive accurate, style-compliant warning instead of L3 sidecar copy', () => { const uiScriptPlugin = { tier: 'L1', permissions: [{ name: 'ui:script', level: 'high' }], } const zhNotice = resolvePluginApprovalNotice(uiScriptPlugin, null, 'zh-CN') const enNotice = resolvePluginApprovalNotice(uiScriptPlugin, null, 'en-US') assert.ok(zhNotice.includes('ui:script'), `expected ui:script zh notice, got: ${zhNotice}`) assert.ok(!zhNotice.includes('L3 Sidecar'), `L1 ui:script must not show L3 Sidecar warning: ${zhNotice}`) assert.ok(!zhNotice.includes('请'), `zh notice should follow design guidelines (no 请): ${zhNotice}`) assert.ok(enNotice.includes('ui:script'), `expected ui:script en notice, got: ${enNotice}`) assert.ok(!enNotice.includes('L3 Sidecar'), `L1 ui:script must not show L3 Sidecar warning: ${enNotice}`) assert.ok(!enNotice.endsWith('.'), `en notice should not end with a trailing period: ${enNotice}`) const l3Plugin = { tier: 'L3', permissions: [{ name: 'driver:vm', level: 'high' }] } const l3Notice = resolvePluginApprovalNotice(l3Plugin, null, 'en-US') assert.ok(l3Notice.includes('L3 Sidecar'), `expected L3 Sidecar warning, got: ${l3Notice}`) const plainTheme = { tier: 'L1', permissions: [] } assert.equal(resolvePluginApprovalNotice(plainTheme, null, 'en-US'), '') }) test('dialog body children and plugin scan lists disable flex shrinking so tall modals scroll instead of clipping', () => { const css = fs.readFileSync(appCSSPath, 'utf8') assert.match(css, /\.dialog-body\s*>\s*\*\s*\{[^}]*flex-shrink\s*:\s*0/) assert.match(css, /\.plugin-scan-section\s*>\s*\.list\s*\{[^}]*flex-shrink\s*:\s*0/) })