import { expect, test } from "@playwright/test";
import { textContrast } from "./rendered-contrast";
test("contrast measurement composites nested opacity and shadow-root surfaces", async ({ page }) => {
await page.setContent(`
Opaque text
`);
await page.locator("#host").evaluate(element => {
let shadow = element.attachShadow({ mode: "open" });
let text = document.createElement("span");
text.id = "shadow";
text.style.color = "white";
text.textContent = "Shadow text";
shadow.append(text);
});
expect(await textContrast(page.locator("#opaque"))).toBeCloseTo(21, 2);
expect(await textContrast(page.locator("#half"))).toBeCloseTo(3.976, 2);
expect(await textContrast(page.locator("#quarter"))).toBeCloseTo(1.834, 2);
expect(await textContrast(page.locator("#shadow"))).toBeCloseTo(21, 2);
});