131 lines
6.8 KiB
JavaScript
131 lines
6.8 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import { parse } from 'vue/compiler-sfc'
|
|
const palettePath = new URL('../src/theme/macaron.json', import.meta.url)
|
|
const luminance = hex => {
|
|
const channels = hex.slice(1).match(/../g).map(c => parseInt(c, 16) / 255).map(c => c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4)
|
|
return channels[0] * .2126 + channels[1] * .7152 + channels[2] * .0722
|
|
}
|
|
test('all semantic button colors retain AA text contrast in both themes', () => {
|
|
const { buttons } = JSON.parse(readFileSync(palettePath))
|
|
for (const mode of ['light', 'dark']) for (const [name, colors] of Object.entries(buttons[mode])) {
|
|
for (const bg of [colors.bg, colors.hover]) {
|
|
const values = [luminance(bg), luminance(colors.text)].sort((a,b) => b-a)
|
|
assert.ok((values[0]+.05)/(values[1]+.05)>=4.5, `${mode}/${name}: low contrast`)
|
|
}
|
|
}
|
|
})
|
|
test('palette covers all Tailwind color families used by the application including opacity variants', () => {
|
|
const { colors } = JSON.parse(readFileSync(palettePath))
|
|
for (const family of ['blue','indigo','cyan','sky','green','emerald','teal','red','rose','pink','purple','violet','yellow','amber','orange','gray','slate','zinc','neutral','stone','lime','fuchsia']) {
|
|
for (const shade of [50,100,200,300,400,500,600,700,800,900,950]) assert.match(colors[family][shade], /^#[a-f0-9]{6}$/)
|
|
}
|
|
})
|
|
test('mobile page-size chooser does not span the whole pagination row', () => {
|
|
const { descriptor }=parse(readFileSync(new URL('../src/components/common/DataPagination.vue',import.meta.url),'utf8'))
|
|
assert.ok(!descriptor.template.content.match(/<select[\s\S]*?class="[^"]*col-span-3/), 'page size occupies the full row')
|
|
})
|
|
|
|
test('all native action buttons use shared motion unless they are cards, switches or backdrops', async () => {
|
|
const { globSync } = await import('glob')
|
|
for(const file of globSync('src/**/*.vue')) {
|
|
const { descriptor }=parse(readFileSync(file,'utf8'))
|
|
function visit(node) {
|
|
if(node.tag==='button') {
|
|
const opening=node.loc.source.match(/^<button\b(?:[^>"']|"[^"]*"|'[^']*')*>/s)?.[0]||''
|
|
assert.ok(/fcb-action|theme-2026-card-hover|role="switch"|inset-0/.test(opening), `Missing button motion: ${file}`)
|
|
}
|
|
for(const child of node.children||[])visit(child)
|
|
}
|
|
if(descriptor.template?.ast)visit(descriptor.template.ast)
|
|
}
|
|
})
|
|
|
|
test('primary submit buttons do not add a second white or gradient hover overlay', () => {
|
|
for(const path of ['src/views/SendFileView.vue','src/components/common/RetrieveForm.vue']) {
|
|
const source=readFileSync(path,'utf8')
|
|
assert.ok(!/group-hover:opacity-(20|100)/.test(source), `${path}: extra hover brightness layer`)
|
|
assert.ok(source.includes('fcb-button-primary'))
|
|
}
|
|
})
|
|
|
|
test('large content sections do not opt into card movement', async () => {
|
|
const {globSync}=await import('glob')
|
|
for(const path of globSync('src/views/**/*.vue')) {
|
|
const {descriptor}=parse(readFileSync(path,'utf8'))
|
|
function visit(node) {
|
|
if(node.tag==='section') {
|
|
const opening=node.loc.source.match(/^<section\b(?:[^>"']|"[^"]*"|'[^']*')*>/s)?.[0]||''
|
|
assert.ok(!opening.includes('theme-2026-card-hover'), `Moving large container: ${path}`)
|
|
}
|
|
for(const child of node.children||[])visit(child)
|
|
}
|
|
if(descriptor.template?.ast)visit(descriptor.template.ast)
|
|
}
|
|
})
|
|
|
|
test('settings shell and shared data table stay stationary while child actions opt in separately', () => {
|
|
for(const path of ['src/views/manage/SystemSettingsView.vue','src/components/common/DataTable.vue']) {
|
|
const source=readFileSync(path,'utf8')
|
|
const outer=source.match(/class="[^"]*fcb-static-container[^"]*"/)?.[0]
|
|
assert.ok(outer && !outer.includes('theme-2026-card-hover'),path)
|
|
}
|
|
})
|
|
|
|
test('list hover styles do not render an inset frame or lift rows', async () => {
|
|
const {default:postcss}=await import('postcss')
|
|
const css=postcss.parse(readFileSync('src/assets/style/main.css','utf8'))
|
|
let found=false
|
|
css.walkRules(rule=>{
|
|
if(rule.selector.includes('.fcb-list-row:hover')) {
|
|
const declarations=Object.fromEntries(rule.nodes.filter(n=>n.type==='decl').map(n=>[n.prop,n.value]))
|
|
assert.equal(declarations['box-shadow'],'none')
|
|
assert.equal(declarations.transform,'none')
|
|
found=true
|
|
}
|
|
})
|
|
assert.ok(found)
|
|
})
|
|
|
|
test('light and dark card shadows use their separately approved light directions', async () => {
|
|
const {default:postcss}=await import('postcss')
|
|
const css=postcss.parse(readFileSync('src/assets/style/main.css','utf8'))
|
|
const shadows={}
|
|
css.walkDecls('--fcb-card-shadow',decl=>{shadows[decl.parent.selector]=decl.value})
|
|
const rgb=shadow=>[...shadow.matchAll(/rgba\((\d+),(\d+),(\d+),[^)]+\)/g)].map(m=>Number(m[1])+Number(m[2])+Number(m[3]))
|
|
const light=rgb(shadows[':root']),dark=rgb(shadows['.dark'])
|
|
assert.equal(light.length,2);assert.equal(dark.length,2)
|
|
assert.ok(light[0]>light[1],'light theme: top-left must be lighter')
|
|
assert.ok(dark[0]<dark[1],'dark theme: top-left must be darker')
|
|
})
|
|
|
|
test('all five expiration choices retain native multi-selection and shared action motion', () => {
|
|
const source=readFileSync('src/views/manage/SystemSettingsView.vue','utf8')
|
|
const group=source.slice(source.indexOf('v-for="style in'),source.indexOf('v-for="style in')+1500)
|
|
assert.ok(group.includes("['day', 'hour', 'minute', 'forever', 'count']"))
|
|
assert.ok(group.includes('type="checkbox"') && group.includes('v-model="config.expireStyle"'))
|
|
assert.ok(group.includes('fcb-action fcb-choice-face'))
|
|
})
|
|
|
|
test('storage detail cards animate visual properties without transitioning grid geometry', async () => {
|
|
const {default:postcss}=await import('postcss')
|
|
const {descriptor}=parse(readFileSync('src/views/manage/FileManageView.vue','utf8'))
|
|
assert.match(descriptor.template.content,/v-for="item in detailStorageItems"[\s\S]*?class="[^"]*fcb-storage-card/)
|
|
const css=postcss.parse(descriptor.styles.map(s=>s.content).join('\n'))
|
|
let transition
|
|
css.walkRules(r=>{if(r.selector==='.fcb-storage-card')r.walkDecls('transition',d=>transition=d.value)})
|
|
assert.ok(transition)
|
|
assert.ok(!/\ball\b/.test(transition))
|
|
for(const property of ['transform','box-shadow','background-color','border-color'])assert.ok(transition.includes(property))
|
|
})
|
|
|
|
test('storage card hover uses a stationary wrapper and disables movement for touch or reduced motion', async () => {
|
|
const {descriptor}=parse(readFileSync('src/views/manage/FileManageView.vue','utf8'))
|
|
const content=descriptor.template.content
|
|
assert.match(content,/v-for="item in detailStorageItems"[\s\S]*?class="fcb-storage-hitbox"[\s\S]*?<div\s+class="fcb-storage-card/)
|
|
const css=descriptor.styles.map(s=>s.content).join('\n')
|
|
assert.match(css,/\.fcb-storage-hitbox:hover\s+\.fcb-storage-card[\s\S]*?translateY\(-2px\)/)
|
|
assert.match(css,/@media \(prefers-reduced-motion: reduce\), \(hover: none\)/)
|
|
})
|