From bdb9b00b6e57ba7b84f32f648bd315e99fa1505e Mon Sep 17 00:00:00 2001 From: CieanYau Date: Sat, 7 Nov 2026 04:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=9A=E6=8C=89=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E5=8F=AF=E8=A7=81=E6=96=87=E5=AD=97=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=AF=B9=E6=AF=94=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/review-list-density.e2e.test.mjs | 38 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/review-list-density.e2e.test.mjs b/tests/review-list-density.e2e.test.mjs index a0dade5..1304f86 100644 --- a/tests/review-list-density.e2e.test.mjs +++ b/tests/review-list-density.e2e.test.mjs @@ -138,7 +138,6 @@ async function measure(page) { gap: style.gap, padding: style.padding, background: style.backgroundColor, - color: style.color, weight: style.fontWeight, fontSize: style.fontSize, shadow: style.boxShadow, @@ -239,6 +238,29 @@ for (const [name, routePath, kind, visibleText] of pages) { .locator(".p-datatable-mask") .waitFor({ state: "hidden" }); const filled = await measure(page); + const visible = content + .getByText(visibleText, { exact: true }) + .first(); + assert.equal(await visible.isVisible(), true); + // 容器可能没有直接绘制文字;对比度应取可见业务文字及其实际承载背景。 + filled.text = await visible.evaluate((element) => { + const rgb = (color) => color.match(/[\d.]+/g).map(Number); + const layers = []; + for (let owner = element; owner; owner = owner.parentElement) + layers.push(rgb(getComputedStyle(owner).backgroundColor)); + let background = [255, 255, 255]; + for (const layer of layers.reverse()) { + const alpha = layer[3] ?? 1; + background = background.map( + (channel, index) => + channel * (1 - alpha) + layer[index] * alpha, + ); + } + return { + color: getComputedStyle(element).color, + background: `rgb(${background.join(", ")})`, + }; + }); const violations = []; for (const [stateName, observed] of [ ["empty", empty], @@ -290,22 +312,16 @@ for (const [name, routePath, kind, visibleText] of pages) { } const surface = kind === "table" ? filled.table : filled.article; const background = luminance(surface.background); - const foreground = luminance(surface.color); + const textBackground = luminance(filled.text.background); + const foreground = luminance(filled.text.color); if (theme === "light" ? background < 0.5 : background > 0.1) violations.push("filled: surface ignores theme"); if ( - (Math.max(background, foreground) + 0.05) / - (Math.min(background, foreground) + 0.05) < + (Math.max(textBackground, foreground) + 0.05) / + (Math.min(textBackground, foreground) + 0.05) < 4.5 ) violations.push("filled: unreadable theme contrast"); - assert.equal( - await content - .getByText(visibleText, { exact: true }) - .first() - .isVisible(), - true, - ); assert.deepEqual(violations, [], JSON.stringify({ empty, filled })); return { routePath, width, theme, kind, empty, filled }; }),