import { describe, expect, test } from 'bun:test' import { readFileSync } from 'node:fs' import { resolve } from 'node:path' import { webSidebarRoleMap } from '../../storage/framework/defaults/resources/functions/dashboard/sidebar' const layoutSource = readFileSync( resolve('storage/framework/defaults/views/dashboard/layouts/default.stx'), 'utf8', ) const guestLayoutSource = readFileSync( resolve('storage/framework/defaults/views/dashboard/layouts/guest.stx'), 'utf8', ) const notFoundSource = readFileSync( resolve('storage/framework/defaults/resources/components/Dashboard/NotFoundDashboard.stx'), 'utf8', ) /** STX expands this declarative contract into the synchronous pre-paint guard. */ const BOOTSTRAP = /@appearanceBootstrap\(\{[\s\S]*?\n\}\)/ const bootstrap = layoutSource.match(BOOTSTRAP)?.[0] ?? '' describe('dashboard layout client architecture', () => { test('gives guest pages a semantic SPA navigation container', () => { expect(guestLayoutSource).toStartWith('') expect(guestLayoutSource).toContain('
') expect(guestLayoutSource).toContain('@yield(\'content\')') }) test('leaves the traffic lights to the platform', () => { // The window's buttons are AppKit's in every Craft window that is not // frameless. The sidebar header draws none and reserves whatever room the // host says they need — which is nothing in a browser, and nothing in a // window that keeps them in a titlebar of their own. expect(layoutSource).toContain('') expect(layoutSource).not.toContain('showWindowControls') }) test('renders the sidebar once and lends it to the mobile drawer', () => { // A second Sidebar for the drawer rendered all its rows again on every // page and doubled each page's first render (stacksjs/stacks#3177). expect(layoutSource.match(/') // The component wrapper moves, not just the pane: the layout's itemClick // listener is on the wrapper, so a bare pane never navigated. expect(layoutSource).toContain("pane?.closest('[data-stx-component-wrapper]')") }) test('returns missing dashboard routes to the canonical home route', () => { expect(notFoundSource).toContain('