Files
monkey-ai-web/test/unit/brand-palette.test.js
T
zhanjunhao cb9d836227 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

76 lines
2.3 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { colord } from 'colord';
import {
resolveBrandPalette,
resolveGradientLabel,
} from '../../src/helpers/brandPalette.js';
import { PRESETS } from '../../src/styles/presets.js';
test('brand interactions retain readable contrast in all solid states', () => {
for (const dark of [false, true]) {
const mode = dark ? 'dark' : 'light';
const surface = dark ? '#1b212b' : '#ffffff';
const inputs = [
...Object.values(PRESETS).map((preset) => preset[mode]['brand-primary']),
'#000000',
'#ffffff',
'#eaff00',
'#00ffff',
'#010331',
'#ee00ff',
'#ff552280',
'not-a-color',
];
for (const input of inputs) {
const palette = resolveBrandPalette(input, dark, surface);
for (const state of ['normal', 'hover', 'active']) {
const fill = colord(palette[state]);
assert.equal(fill.alpha(), 1);
assert.ok(
fill.contrast(palette.onSolid) >= 4.5,
[mode, input, state].join(' '),
);
}
assert.ok(
colord(palette.selectionText).contrast(palette.selectionBg) >= 4.5,
);
if (!palette.isPrototype) {
assert.ok(colord(palette.accent).contrast(palette.tintHover) >= 4.5);
assert.ok(colord(palette.tint).contrast(surface) < 1.6);
if (dark)
assert.ok(colord(palette.hover).contrast(palette.onSolid) < 7.1);
}
}
}
});
test('prototype amber retains its selected foreground and surface', () => {
const light = resolveBrandPalette('#B96508', false, '#ffffff');
const dark = resolveBrandPalette('#D1963A', true, '#1b212b');
assert.deepEqual(
[light.selectionBg, light.selectionText],
['#fff3df', '#a45a07'],
);
assert.deepEqual(
[dark.selectionBg, dark.selectionText],
['#382b1b', '#f2ad41'],
);
});
test('preview gradient labels use readable ink or a neutral backing', () => {
assert.deepEqual(resolveGradientLabel(['#d1963a', '#f2ad41'], '#101014'), {
color: '#11151c',
});
assert.deepEqual(resolveGradientLabel(['#0e192a', '#17436b'], '#f6f8fb'), {
color: '#ffffff',
});
assert.deepEqual(
resolveGradientLabel(['#ffffff80', '#ffffff00'], '#010101'),
{
color: '#ffffff',
background: '#010101',
},
);
});