Files
hideck/web/tests/typographyReadabilitySource.test.ts
T
yibaiba 6ac6bf6e24 fix(web): improve dashboard text readability
Why: Dashboard labels, device addresses, status facts, and shared shell metadata rendered below the design system's readable minimum.\n\nWhy this works: Secondary text now uses the 12px caption token while data-heavy addresses and signal values use 13px, with a source regression check covering the route.\n\nRemaining: Apply and verify the same scale on the remaining migrated workspaces.
2026-08-13 23:55:08 +08:00

55 lines
1.8 KiB
TypeScript

import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const MIN_READABLE_FONT_SIZE = 12
const globalStyles = await readFile(new URL('../src/style.css', import.meta.url), 'utf8')
const dashboardTypographyFiles = [
'../src/views/Dashboard.vue',
'../src/components/DeviceCard.vue',
'../src/components/ConnectionFocusStage.vue',
'../src/components/TrafficAnalysisPanel.vue',
'../src/components/PageHeader.vue',
'../src/layouts/AuthenticatedShell.vue'
] as const
const FONT_DECLARATION_PATTERNS = [
/font-size:\s*([0-9.]+)px/g,
/font:\s*[^;{}]*?([0-9.]+)px(?:\/[^\s;{}]+)?/g
] as const
function findUnreadableFontSizes(source: string): number[] {
return FONT_DECLARATION_PATTERNS.flatMap((pattern) => {
return Array.from(source.matchAll(pattern), (match) => Number(match[1]))
.filter((size) => size < MIN_READABLE_FONT_SIZE)
})
}
test('shared typography tokens follow the production design scale', () => {
const expectedTokens = {
caption: 12,
'body-sm': 13,
body: 14,
title: 16,
section: 20,
'page-title': 24
}
for (const [name, size] of Object.entries(expectedTokens)) {
assert.match(globalStyles, new RegExp(`--ui-font-${name}:\\s*${size}px`))
}
})
test('typography audit detects declarations below the readable minimum', () => {
assert.deepEqual(findUnreadableFontSizes('.metadata { font-size: 11px; }'), [11])
assert.deepEqual(findUnreadableFontSizes('.code { font: 10px/1.4 monospace; }'), [10])
assert.deepEqual(findUnreadableFontSizes('.body { font-size: 12px; }'), [])
})
test('dashboard text does not declare font sizes below 12px', async () => {
for (const path of dashboardTypographyFiles) {
const source = await readFile(new URL(path, import.meta.url), 'utf8')
assert.deepEqual(findUnreadableFontSizes(source), [], path)
}
})