fix(ui): preserve queue labels and primary button contrast
This commit is contained in:
parent
76caa2d081
commit
66fa4cfa54
|
|
@ -53,3 +53,12 @@ NODE_PATH=/tmp/csai-ui-tools/node_modules node scripts/check-ui-design-system.cj
|
|||
|
||||
所有场景都在四档屏宽与两种主题下运行;夹具请求拒绝非 GET 操作。
|
||||
需要定位单个断点时可设置 `CSAI_UI_WIDTHS=390`;提交前省略该变量运行完整矩阵。
|
||||
|
||||
### 队列动态文案与按钮对比度
|
||||
|
||||
队列标题将可翻译的前缀与原样保留的队列名称分开渲染;执行按钮的 `data-i18n` 随暂停、待执行及 Cron 状态更新。
|
||||
主要操作的小号按钮明确使用强调色背景和配套文字色,避免旧尺寸样式把背景改灰后仍保留深色文字。
|
||||
|
||||
回归增加了:暂停/待执行/运行/完成/取消、Cron 开关、中英文切换、桌面与手机断点切换、空标题和含特殊字符的标题。
|
||||
针对可见的开始/继续/重跑按钮,检查正常、悬停和键盘焦点状态下的计算颜色,要求文字与不透明背景的对比度不低于 4.5:1;每档尺寸和主题的计算结果保存为 `queue-contrast-*.json`。
|
||||
浏览器回归使用真实 i18next 翻译函数,不再用固定中文替代函数覆盖它。
|
||||
|
|
|
|||
|
|
@ -65,19 +65,6 @@ const server = http.createServer((req, res) => {
|
|||
);
|
||||
await page.goto("http://127.0.0.1:" + server.address().port);
|
||||
await page.evaluate(() => window.i18nReady);
|
||||
await page.evaluate(
|
||||
(catalog) => {
|
||||
window.t = (key, opts = {}) => {
|
||||
let value = key.split(".").reduce((o, k) => o && o[k], catalog);
|
||||
return typeof value === "string"
|
||||
? value.replace(/\{\{(\w+)\}\}/g, (_, k) => opts[k] ?? "")
|
||||
: key;
|
||||
};
|
||||
},
|
||||
JSON.parse(
|
||||
fs.readFileSync(root + "/web/static/i18n/zh-CN.json", "utf8"),
|
||||
),
|
||||
);
|
||||
await page.evaluate((t) => {
|
||||
document.documentElement.dataset.theme = t;
|
||||
document
|
||||
|
|
|
|||
|
|
@ -121,10 +121,30 @@ module.exports = async function ({ page, width, height, theme, out }) {
|
|||
animations: "disabled",
|
||||
path: `${out}/real-${name}-${width}-${theme}.png`,
|
||||
});
|
||||
const contrastResults = [];
|
||||
await activate("page-tasks");
|
||||
for (const state of ["paused", "running", "completed"]) {
|
||||
const states = [
|
||||
{ status: "paused", scheduleMode: "manual", label: "继续执行" },
|
||||
{ status: "pending", scheduleMode: "manual", label: "开始执行" },
|
||||
{
|
||||
status: "pending",
|
||||
scheduleMode: "cron",
|
||||
scheduleEnabled: true,
|
||||
label: "立即执行一轮",
|
||||
},
|
||||
{
|
||||
status: "pending",
|
||||
scheduleMode: "cron",
|
||||
scheduleEnabled: false,
|
||||
label: "开始执行",
|
||||
},
|
||||
{ status: "running", scheduleMode: "manual" },
|
||||
{ status: "completed", scheduleMode: "manual" },
|
||||
{ status: "cancelled", scheduleMode: "manual" },
|
||||
];
|
||||
for (const state of states) {
|
||||
await page.evaluate(async (state) => {
|
||||
fixtureQueue.status = state;
|
||||
Object.assign(fixtureQueue, state);
|
||||
await showBatchQueueDetail("ui-fixture");
|
||||
}, state);
|
||||
await page
|
||||
|
|
@ -157,21 +177,159 @@ module.exports = async function ({ page, width, height, theme, out }) {
|
|||
assert(layout.titleWidth > 200, JSON.stringify(layout));
|
||||
assert(layout.headerHeight < 190, JSON.stringify(layout));
|
||||
assert(layout.allInside && !layout.titleOverlaps, JSON.stringify(layout));
|
||||
if (state === "paused") await shot("queue");
|
||||
await page.evaluate(() => applyTranslations(document.body));
|
||||
const assertLabels = async () => {
|
||||
const text = await page.locator("#batch-queue-detail-title").innerText();
|
||||
assert.equal(text, "批量任务队列 - 多目标授权评估回归队列");
|
||||
if (state.label)
|
||||
assert.equal(
|
||||
await page.locator("#batch-queue-start-btn").innerText(),
|
||||
state.label,
|
||||
);
|
||||
else
|
||||
assert.equal(
|
||||
await page.locator("#batch-queue-start-btn").isVisible(),
|
||||
false,
|
||||
);
|
||||
};
|
||||
await assertLabels();
|
||||
// Real breakpoint transitions call mobile boot, which reapplies all translations.
|
||||
if (width === 1440 && state.label) {
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.waitForTimeout(150);
|
||||
await assertLabels();
|
||||
await page.setViewportSize({ width, height });
|
||||
await page.waitForTimeout(150);
|
||||
await assertLabels();
|
||||
}
|
||||
for (const button of await page
|
||||
.locator(
|
||||
"#batch-queue-detail-modal .modal-header-actions .btn-primary:visible",
|
||||
)
|
||||
.all()) {
|
||||
for (const appearance of ["normal", "hover", "focus"]) {
|
||||
if (appearance === "normal")
|
||||
await page.mouse.move(width - 4, height - 4);
|
||||
if (appearance === "hover") await button.hover();
|
||||
if (appearance === "focus") {
|
||||
await page.mouse.move(width - 4, height - 4);
|
||||
await button.focus();
|
||||
await page.keyboard.press("Tab");
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert(
|
||||
await button.evaluate((e) => e.matches(":focus-visible")),
|
||||
"Keyboard focus indicator missing",
|
||||
);
|
||||
}
|
||||
await page.waitForTimeout(220);
|
||||
const colors = await button.evaluate((e) => ({
|
||||
foreground: getComputedStyle(e).color,
|
||||
background: getComputedStyle(e).backgroundColor,
|
||||
disabled: e.disabled,
|
||||
text: e.textContent,
|
||||
}));
|
||||
assert(!colors.disabled);
|
||||
const rgb = (value) => {
|
||||
assert(/^rgb/.test(value), JSON.stringify(colors));
|
||||
const values = value.match(/[\d.]+/g).map(Number);
|
||||
assert(
|
||||
values.length === 3 || values[3] === 1,
|
||||
"Primary background must be opaque",
|
||||
);
|
||||
return values.slice(0, 3).map((v) => {
|
||||
const c = v / 255;
|
||||
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
};
|
||||
const lum = (value) => {
|
||||
const [r, g, b] = rgb(value);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
};
|
||||
const a = lum(colors.foreground),
|
||||
b = lum(colors.background);
|
||||
const ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
||||
contrastResults.push({
|
||||
state: state.status,
|
||||
label: state.label,
|
||||
appearance,
|
||||
ratio,
|
||||
...colors,
|
||||
});
|
||||
assert(
|
||||
ratio >= 4.5,
|
||||
JSON.stringify({ width, theme, appearance, ratio, ...colors }),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (state.status === "paused") await shot("queue");
|
||||
await page.evaluate(() => closeBatchQueueDetailModal());
|
||||
}
|
||||
// Queue names are literal content, including characters that look like markup.
|
||||
await page.evaluate(async () => {
|
||||
fixtureQueue.title = "复核 & <说明>";
|
||||
fixtureQueue.status = "paused";
|
||||
await showBatchQueueDetail("ui-fixture");
|
||||
applyTranslations(document.body);
|
||||
});
|
||||
assert.equal(
|
||||
await page.locator("#batch-queue-detail-title").innerText(),
|
||||
"批量任务队列 - 复核 & <说明>",
|
||||
);
|
||||
assert.equal(await page.locator("#batch-queue-detail-title > *").count(), 1);
|
||||
await page.evaluate(async () => {
|
||||
fixtureQueue.title = "";
|
||||
await showBatchQueueDetail("ui-fixture");
|
||||
applyTranslations(document.body);
|
||||
});
|
||||
assert.equal(
|
||||
await page.locator("#batch-queue-detail-title").innerText(),
|
||||
"批量任务队列",
|
||||
);
|
||||
await page.evaluate(() => {
|
||||
fixtureQueue.title = "多目标授权评估回归队列";
|
||||
});
|
||||
require("node:fs").writeFileSync(
|
||||
`${out}/queue-contrast-${width}-${theme}.json`,
|
||||
JSON.stringify(contrastResults, null, 2),
|
||||
);
|
||||
// A real language change translates the prefix and action, but never the queue name.
|
||||
await page.evaluate(async () => {
|
||||
fixtureQueue.status = "paused";
|
||||
await showBatchQueueDetail("ui-fixture");
|
||||
onLanguageSelect("en-US");
|
||||
});
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.documentElement.lang === "en-US" &&
|
||||
document.getElementById("batch-queue-start-btn").textContent === "Resume",
|
||||
);
|
||||
assert(
|
||||
(await page.locator("#batch-queue-detail-title").innerText()).endsWith(
|
||||
" - 多目标授权评估回归队列",
|
||||
),
|
||||
);
|
||||
await page.evaluate(() => onLanguageSelect("zh-CN"));
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.documentElement.lang === "zh-CN" &&
|
||||
document.getElementById("batch-queue-start-btn").textContent ===
|
||||
"继续执行",
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator("#batch-queue-detail-title").innerText(),
|
||||
"批量任务队列 - 多目标授权评估回归队列",
|
||||
);
|
||||
await page.evaluate(() => closeBatchQueueDetailModal());
|
||||
await activate("page-roles-management");
|
||||
await page.evaluate(() => editRole("界面回归角色"));
|
||||
await page.locator("#role-tools-list input").first().waitFor();
|
||||
await page.evaluate(() => applyTranslations(document));
|
||||
assert.equal(await page.locator("#role-modal-title").innerText(), "编辑角色");
|
||||
const stats = await page
|
||||
.locator("#role-tools-stats")
|
||||
.evaluate((e) => ({
|
||||
width: e.clientWidth,
|
||||
scroll: e.scrollWidth,
|
||||
text: e.textContent,
|
||||
}));
|
||||
const stats = await page.locator("#role-tools-stats").evaluate((e) => ({
|
||||
width: e.clientWidth,
|
||||
scroll: e.scrollWidth,
|
||||
text: e.textContent,
|
||||
}));
|
||||
assert(stats.text.includes("614") && stats.text.includes("626"), stats.text);
|
||||
assert(stats.scroll <= stats.width + 2, JSON.stringify(stats));
|
||||
await page.locator("#role-tools-stats").scrollIntoViewIfNeeded();
|
||||
|
|
@ -226,13 +384,11 @@ module.exports = async function ({ page, width, height, theme, out }) {
|
|||
await page.locator('[data-da-action="create"]').click();
|
||||
await page.locator("#da-form-drawer[open]").waitFor();
|
||||
await page.waitForTimeout(220);
|
||||
const native = await page
|
||||
.locator("#da-form-drawer")
|
||||
.evaluate((e) => ({
|
||||
rect: e.getBoundingClientRect().toJSON(),
|
||||
bg: getComputedStyle(e).backgroundColor,
|
||||
expand: !!e.querySelector(".app-drawer-expand"),
|
||||
}));
|
||||
const native = await page.locator("#da-form-drawer").evaluate((e) => ({
|
||||
rect: e.getBoundingClientRect().toJSON(),
|
||||
bg: getComputedStyle(e).backgroundColor,
|
||||
expand: !!e.querySelector(".app-drawer-expand"),
|
||||
}));
|
||||
assert(native.expand);
|
||||
assert(Math.abs(native.rect.right - width) < 2, JSON.stringify(native));
|
||||
assert(Math.abs(native.rect.height - height) < 2);
|
||||
|
|
|
|||
|
|
@ -317,3 +317,19 @@ html body dialog.da-drawer .da-drawer-close::before {
|
|||
mask: var(--icon-close-mask) center / contain no-repeat;
|
||||
-webkit-mask: var(--icon-close-mask) center / contain no-repeat;
|
||||
}
|
||||
|
||||
/* Queue primary actions keep their semantic fill even with .btn-small.
|
||||
* Mobile's dark foreground assumes an accent fill, never a translucent gray. */
|
||||
html body #batch-queue-detail-modal .modal-header-actions .btn-primary {
|
||||
background: var(--accent-color) !important;
|
||||
border-color: var(--accent-color);
|
||||
color: #fff !important;
|
||||
}
|
||||
html[data-theme="dark"] body #batch-queue-detail-modal .modal-header-actions .btn-primary {
|
||||
color: #0b1120 !important;
|
||||
}
|
||||
html body #batch-queue-detail-modal .modal-header-actions .btn-primary:is(:hover, :focus-visible, :active):not(:disabled) {
|
||||
background: var(--accent-hover) !important;
|
||||
border-color: var(--accent-hover);
|
||||
}
|
||||
html body #batch-queue-detail-modal #batch-queue-detail-title { display: block; }
|
||||
|
|
|
|||
|
|
@ -1798,8 +1798,14 @@ async function showBatchQueueDetail(queueId) {
|
|||
const allowSubtaskMutation = batchQueueAllowsSubtaskMutation(queue);
|
||||
|
||||
if (title) {
|
||||
// textContent 本身会做转义;这里不要再 escapeHtml,否则会把 && 显示成 &...(看起来像“变形/乱码”)
|
||||
title.textContent = queue.title ? _t('tasks.batchQueueTitle') + ' - ' + String(queue.title) : _t('tasks.batchQueueTitle');
|
||||
// Translate only the label. The queue name is literal user content and
|
||||
// must survive mobile boot / language refresh without being replaced.
|
||||
title.removeAttribute('data-i18n');
|
||||
const label = document.createElement('span');
|
||||
label.setAttribute('data-i18n', 'tasks.batchQueueTitle');
|
||||
label.textContent = _t('tasks.batchQueueTitle');
|
||||
title.replaceChildren(label);
|
||||
if (queue.title) title.appendChild(document.createTextNode(' - ' + String(queue.title)));
|
||||
}
|
||||
|
||||
// 更新按钮显示
|
||||
|
|
@ -1810,14 +1816,11 @@ async function showBatchQueueDetail(queueId) {
|
|||
if (startBtn) {
|
||||
// pending状态显示"开始执行",paused状态显示"继续执行"
|
||||
startBtn.style.display = (queue.status === 'pending' || queue.status === 'paused') ? 'inline-block' : 'none';
|
||||
if (startBtn && queue.status === 'paused') {
|
||||
startBtn.textContent = _t('tasks.resumeExecute');
|
||||
} else if (startBtn && queue.status === 'pending') {
|
||||
const isCronPending = queue.scheduleMode === 'cron' && queue.scheduleEnabled !== false;
|
||||
startBtn.textContent = isCronPending
|
||||
? _t('batchQueueDetailModal.startExecuteNow')
|
||||
: _t('batchQueueDetailModal.startExecute');
|
||||
}
|
||||
const isCronPending = queue.status === 'pending' && queue.scheduleMode === 'cron' && queue.scheduleEnabled !== false;
|
||||
const startLabelKey = queue.status === 'paused' ? 'tasks.resumeExecute'
|
||||
: isCronPending ? 'batchQueueDetailModal.startExecuteNow' : 'batchQueueDetailModal.startExecute';
|
||||
startBtn.setAttribute('data-i18n', startLabelKey);
|
||||
startBtn.textContent = _t(startLabelKey);
|
||||
}
|
||||
const rerunBtn = document.getElementById('batch-queue-rerun-btn');
|
||||
if (rerunBtn) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
<link rel="stylesheet" href="/static/css/vulnerability-list.css?v=20261113-compact-rows">
|
||||
<script src="/static/js/router.js?v=20261114-assessment-links"></script>
|
||||
<link rel="stylesheet" href="/static/css/deep-assessments.css?v=20261115-intents">
|
||||
<link rel="stylesheet" href="/static/css/design-system.css?v=20261115-2">
|
||||
<link rel="stylesheet" href="/static/css/design-system.css?v=20261115-3">
|
||||
</head>
|
||||
<body>
|
||||
<div id="login-overlay" class="login-overlay" style="display: none;">
|
||||
|
|
@ -7144,7 +7144,7 @@
|
|||
<script src="/static/js/assessment-exploration-views.js?v=20261115-intents"></script>
|
||||
<script src="/static/js/deep-assessment-graph.js?v=20261115-intents"></script>
|
||||
<script src="/static/js/deep-assessments.js?v=20261115-ui-review-state"></script>
|
||||
<script src="/static/js/tasks.js?v=20261114-batch-restore"></script>
|
||||
<script src="/static/js/tasks.js?v=20261115-queue-label-contrast"></script>
|
||||
<script src="/static/js/workflow-package-client.js"></script>
|
||||
<script src="/static/js/workflows.js"></script>
|
||||
<script src="/static/js/update.js?v={{.Version}}-update-status"></script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue