You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.4 KiB
36 lines
1.4 KiB
import { describe, expect, it } from 'vitest'
|
|
import design from '../../design.tokens.json'
|
|
|
|
function luminance(hex: string): number {
|
|
const channels = hex
|
|
.slice(1)
|
|
.match(/../g)!
|
|
.map((value) => {
|
|
const channel = parseInt(value, 16) / 255
|
|
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4
|
|
})
|
|
return channels[0]! * 0.2126 + channels[1]! * 0.7152 + channels[2]! * 0.0722
|
|
}
|
|
function contrast(first: string, second: string): number {
|
|
const a = luminance(first)
|
|
const b = luminance(second)
|
|
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
|
|
}
|
|
|
|
describe('desktop design constraints', () => {
|
|
for (const mode of ['light', 'dark'] as const) {
|
|
it(`${mode}: keeps text and input boundaries distinguishable`, () => {
|
|
const theme = design[mode]
|
|
for (const background of [theme.background, theme.surface, theme.sidebar]) {
|
|
expect(contrast(theme.ink, background)).toBeGreaterThanOrEqual(4.5)
|
|
expect(contrast(theme.muted, background)).toBeGreaterThanOrEqual(4.5)
|
|
}
|
|
expect(contrast(theme.accent, theme['accent-ink'])).toBeGreaterThanOrEqual(4.5)
|
|
expect(contrast(theme.accent, theme['accent-soft'])).toBeGreaterThanOrEqual(4.5)
|
|
expect(contrast(theme.control, theme.background)).toBeGreaterThanOrEqual(3)
|
|
})
|
|
}
|
|
it('leaves a border below the native window controls', () => {
|
|
expect(design.layout.titlebar - design.layout.nativeControls).toBe(1)
|
|
})
|
|
})
|
|
|