Site: alpha-aware contrast check; test the open steps (R2.1)
This commit is contained in:
2 files changed
+30
-5
No files matched your search
+13
-5
@@ -66,19 +66,27 @@ for (const scheme of ["light", "dark"] as const) {
|
||||
await page.emulateMedia({ colorScheme: scheme });
|
||||
await open(page);
|
||||
const worst = await page.evaluate(() => {
|
||||
const parse = (c: string) => c.match(/[\d.]+/g)!.slice(0, 3).map(Number);
|
||||
const lum = (c: string) => {
|
||||
const [r, g, b] = parse(c).map((v) => {
|
||||
const parse = (c: string) => {
|
||||
const [r, g, b, a = 1] = c.match(/[\d.]+/g)!.map(Number);
|
||||
return { rgb: [r, g, b], a };
|
||||
};
|
||||
const lum = (rgb: number[]) => {
|
||||
const [r, g, b] = rgb.map((v) => {
|
||||
const s = v / 255;
|
||||
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
};
|
||||
const page = lum(getComputedStyle(document.documentElement).backgroundColor);
|
||||
const ground = parse(getComputedStyle(document.documentElement).backgroundColor).rgb;
|
||||
const page = lum(ground);
|
||||
const shown = (c: string) => {
|
||||
const { rgb, a } = parse(c);
|
||||
return rgb.map((v, i) => v * a + ground[i] * (1 - a));
|
||||
};
|
||||
const ratios = [...document.querySelectorAll<HTMLElement>("h1, h2, h3, p, a, li, button")]
|
||||
.filter((el) => el.textContent?.trim() && getComputedStyle(el).color !== "rgba(0, 0, 0, 0)")
|
||||
.map((el) => {
|
||||
const text = lum(getComputedStyle(el).color);
|
||||
const text = lum(shown(getComputedStyle(el).color));
|
||||
return { ratio: (Math.max(text, page) + 0.05) / (Math.min(text, page) + 0.05), text: el.textContent };
|
||||
});
|
||||
return ratios.sort((a, b) => a.ratio - b.ratio)[0];
|
||||
|
||||
@@ -126,3 +126,20 @@ test.describe("English locale", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("the download area tells how to open an unnotarized app", async ({ browser }) => {
|
||||
for (const [locale, words] of [
|
||||
["en-US", ["System Settings", "Privacy & Security", "Open Anyway"]],
|
||||
["zh-CN", ["系统设置", "隐私与安全性", "仍要打开"]],
|
||||
] as const) {
|
||||
const page = await browser.newPage({ locale, reducedMotion: "reduce" });
|
||||
await page.goto("/");
|
||||
const steps = page.locator("#download [data-t=unsigned]");
|
||||
await expect(steps).toBeVisible();
|
||||
for (const word of words) await expect(steps).toContainText(word);
|
||||
await page.locator(".lang").click();
|
||||
await expect(steps).toBeVisible();
|
||||
await expect(steps).not.toContainText(words[0]);
|
||||
await page.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user