// @vitest-environment happy-dom
import { describe, expect, it } from 'vitest'
import {
buildPluginPanelShellHtml,
PANEL_DESIGN_TOKEN_ALLOWLIST,
PLUGIN_PANEL_CSP
} from './plugin-panel-shell'
describe('buildPluginPanelShellHtml', () => {
it('keeps destructive surface and foreground tokens paired', () => {
expect(PANEL_DESIGN_TOKEN_ALLOWLIST).toEqual(
expect.arrayContaining(['--destructive', '--destructive-foreground'])
)
})
it('places CSP and navigation guards before plugin content', () => {
const html = buildPluginPanelShellHtml('Plugin')
const pluginOffset = html.indexOf('plugin-content')
expect(PLUGIN_PANEL_CSP).toContain("form-action 'none'")
expect(html.indexOf('Content-Security-Policy')).toBeLessThan(pluginOffset)
expect(html.indexOf("window.navigation.addEventListener('navigate'")).toBeLessThan(pluginOffset)
expect(html.indexOf("window.addEventListener('click'")).toBeLessThan(pluginOffset)
expect(html.indexOf("window.addEventListener('submit'")).toBeLessThan(pluginOffset)
expect(html.indexOf("Object.defineProperty(window, 'open'")).toBeLessThan(pluginOffset)
})
it('cancels anchor and form default navigation in the fallback path', () => {
const html = buildPluginPanelShellHtml('Plugin')
const script = html.match(/