Files
monkey-ai-web/test/unit/brand-palette.test.js
T
zhanjunhao e70e0d2224 fix(ui): 修复登录与并发请求并统一表格、主题和页面展示
验证:868 项单测、ESLint、Prettier、UI 依赖审计和差异检查通过。
2026-11-19 18:58:46 +08:00

95 lines
3.0 KiB
JavaScript

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
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',
},
);
});