|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { readdirSync, readFileSync, statSync } from 'node:fs' |
| 5 | +import { join } from 'node:path' |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | +import { PAGE_HEADER_BAR } from '@/components/page-header-bar' |
| 8 | + |
| 9 | +/** The geometry every page header bar shares, minus the top padding. */ |
| 10 | +const BAR_SIGNATURE = 'px-[16px]' |
| 11 | +const LANE_VAR = 'var(--workspace-content-title-bar-inset)' |
| 12 | + |
| 13 | +const ROOTS = ['app', 'components'].map((dir) => join(process.cwd(), dir)) |
| 14 | + |
| 15 | +function* sourceFiles(dir: string): Generator<string> { |
| 16 | + for (const entry of readdirSync(dir)) { |
| 17 | + if (entry === 'node_modules' || entry.startsWith('.')) continue |
| 18 | + const full = join(dir, entry) |
| 19 | + if (statSync(full).isDirectory()) { |
| 20 | + yield* sourceFiles(full) |
| 21 | + continue |
| 22 | + } |
| 23 | + if (/\.tsx?$/.test(entry)) yield full |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +describe('PAGE_HEADER_BAR', () => { |
| 28 | + it('reserves the desktop title-bar lane in its top padding', () => { |
| 29 | + // Without this the bar sits under the macOS traffic lights and the sidebar |
| 30 | + // expander whenever the sidebar is collapsed in the desktop app. |
| 31 | + expect(PAGE_HEADER_BAR).toContain(LANE_VAR) |
| 32 | + expect(PAGE_HEADER_BAR).toContain(BAR_SIGNATURE) |
| 33 | + }) |
| 34 | + |
| 35 | + it('is the only definition of the page header bar geometry', () => { |
| 36 | + const offenders: string[] = [] |
| 37 | + for (const root of ROOTS) { |
| 38 | + for (const file of sourceFiles(root)) { |
| 39 | + if (file.endsWith(join('components', 'page-header-bar.ts'))) continue |
| 40 | + const source = readFileSync(file, 'utf8') |
| 41 | + // A header bar re-derived inline: the shared gutter plus the old fixed top |
| 42 | + // padding, rather than composing PAGE_HEADER_BAR. |
| 43 | + if (source.includes(`${BAR_SIGNATURE} pt-[8.5px]`)) { |
| 44 | + offenders.push(file.replace(process.cwd(), '.')) |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + expect(offenders).toEqual([]) |
| 50 | + }) |
| 51 | +}) |
0 commit comments