Files
clean-architecture-frontend…/tests/visual/scrollbar-gutter.visual.spec.ts
T
DongHyeonka 1b5a8c6f54
frontend-quality-gates / merge / static checks (pull_request) Successful in 1m13s
frontend-quality-gates / merge / tests (pull_request) Failing after 11m34s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m32s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
test(browser): strict 검사를 공용 watcher로 빼 같은 context의 다른 탭도 본다
문제: strict fixture는 fixture의 `page` 하나에만 콘솔·pageerror·
requestfailed listener를 붙였다. 다른 탭을 여는 capability 시험 7곳
(cross-context invalidation, OPFS, IndexedDB)의 두 번째 탭은 아무도 보지
않았다. SW recovery 시험은 자기 context를 쓰며 fixture와 다른 손 사본
(WebKit 문구 무시 없음)으로 검사했다.

고친 것: 검사 본문을 `watchBrowserFailures(page, { preloads })`로 뺀다.
fixture는 자기 page(preload 검사 포함)와, 같은 context에서 열리는 모든 탭에
같은 함수를 붙인다(탭이 열릴 때 동기로 붙여 spec이 이동하기 전이다). SW
recovery는 회복된 load 전에 같은 함수를 붙인다. 손 사본은 지운다.
fixture의 기록을 읽는 `preload-use.spec.ts`에 둘째 탭의 console.error가
기록되는지 보는 시험을 더한다.

위험·한계: 둘째 탭의 preload 사용은 보지 않는다(첫 page만). SW recovery도
preload를 보지 않는다. 그 context는 같은 origin을 두 번 열어, WebKit이 회복된
load의 script를 캐시에서 주며 추적기의 route를 지나쳐 모든 preload가
미사용으로 읽혔다(16건).

검증: desktop — 옛 fixture에서 둘째 탭 시험이 세 엔진 모두 실패(RED),
고친 fixture에서 preload-use·SW recovery 통과, capability 세 spec은
FE-GATE-008에서 본다.

Refs: 1112/03-05
2026-11-13 23:29:13 +09:00

168 lines
6.4 KiB
TypeScript

import { fileURLToPath } from "node:url";
import {
expect,
test,
type Page,
} from "../support/browser/strict-browser-test.ts";
import { KO_MESSAGES } from "../../src/presentation/i18n/catalog.ts";
/**
* 1106/08-03. `scrollbar-gutter: stable` (base.css, 1105/15-05) keeps a
* classic scrollbar's strip on the right even when the page does not scroll.
* Only the root background paints that strip; the page and every fixed box,
* the modal `::backdrop` included, end at its left edge. The goldens run with
* Playwright's `--hide-scrollbars`, so this spec starts Chromium with the
* scrollbar most Windows and Linux desktops draw and reads the drawn pixels.
* Hit testing is no evidence here: the strip answers `null` either way.
*/
test.use({
launchOptions: {
// `test.use` replaces the config's launchOptions whole: the font pin
// from playwright.visual.config.ts is repeated.
env: {
...process.env,
FONTCONFIG_FILE: fileURLToPath(new URL("./fonts.conf", import.meta.url)),
},
ignoreDefaultArgs: ["--hide-scrollbars"],
},
});
type Colour = readonly number[];
type Strip = Readonly<{ x: number; width: number }>;
/**
* The largest channel difference the gutter may show against the strip
* beside it. The drawer's shadow (`--shadow-dialog`, 70 px blur) still
* darkens the strip beside the gutter by about 3 levels; rounding adds 1 or
* 2. In the light theme a gutter the scrim does not cover
* (the page surface against 55% of the content colour over it) differs by
* about 120.
*/
const SAME_COLOUR = 12;
/** The mean colour of each strip, from one screenshot of the band. */
async function stripColours(
page: Page,
band: Readonly<{ y: number; height: number }>,
strips: readonly Strip[],
): Promise<Colour[]> {
const left = Math.min(...strips.map((strip) => strip.x));
const right = Math.max(...strips.map((strip) => strip.x + strip.width));
const png = await page.screenshot({
animations: "disabled",
clip: { x: left, y: band.y, width: right - left, height: band.height },
scale: "css",
});
// Decoded in a blank page, so the page under test runs nothing extra.
const decoder = await page.context().newPage();
try {
return await decoder.evaluate(
async ({ base64, offsets }) => {
const bytes = Uint8Array.from(atob(base64), (character) =>
character.charCodeAt(0),
);
const bitmap = await createImageBitmap(
new Blob([bytes], { type: "image/png" }),
);
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
// Read back once per strip: without the hint Chromium warns on the
// console of this tab, which the strict fixture watches (1112/03-05).
const context = canvas.getContext("2d", { willReadFrequently: true });
if (context === null) throw new Error("no 2d canvas context");
context.drawImage(bitmap, 0, 0);
return offsets.map(({ x, width }) => {
const { data } = context.getImageData(x, 0, width, bitmap.height);
const sums = [0, 0, 0];
for (let index = 0; index < data.length; index += 4) {
for (let channel = 0; channel < 3; channel += 1) {
sums[channel] += data[index + channel];
}
}
return sums.map((sum) => Math.round(sum / (data.length / 4)));
});
},
{
base64: png.toString("base64"),
offsets: strips.map((strip) => ({ x: strip.x - left, width: strip.width })),
},
);
} finally {
await decoder.close();
}
}
async function expectGutterLikeBeside(
page: Page,
geometry: Readonly<{
band: Readonly<{ y: number; height: number }>;
beside: Strip;
gutter: Strip;
}>,
what: string,
) {
const [beside, gutter] = await stripColours(page, geometry.band, [
geometry.beside,
geometry.gutter,
]);
const difference = Math.max(
...gutter.map((value, channel) => Math.abs(value - beside[channel])),
);
// On failure, tells a rule that did not match from a colour not drawn.
const root = await page.evaluate(() => {
const style = getComputedStyle(document.documentElement);
return `${style.backgroundColor} / ${style.backgroundImage}, open dialogs ${document.querySelectorAll(".ui-dialog[open]").length}`;
});
expect(
difference,
`${what}: gutter rgb(${gutter.join(" ")}), beside it rgb(${beside.join(" ")}); root background ${root}`,
).toBeLessThanOrEqual(SAME_COLOUR);
}
test("the open drawer's scrim covers the classic scrollbar gutter on a page that does not scroll", async ({
page,
}) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.goto("/not-found");
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
KO_MESSAGES["page.notFound.title"],
);
const layout = await page.evaluate(() => ({
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
// With the gutter empty, documentElement.clientWidth is the window
// width (08-R2); the page's own box ends at the gutter.
pageRight: Math.round(document.body.getBoundingClientRect().right),
scrolls:
document.documentElement.scrollHeight >
document.documentElement.clientHeight,
}));
expect(layout.scrolls, "a page that scrolls draws its scrollbar in the gutter").toBe(
false,
);
expect(
layout.windowWidth - layout.pageRight,
"Chromium without --hide-scrollbars reserves a classic scrollbar's gutter",
).toBeGreaterThanOrEqual(10);
// A band at mid-height. The strip beside the gutter lies in the page's own
// padding, 5 px in from its edge so the scrim's 2 px blur stays inside it;
// the gutter strip keeps 3 px off both of its edges.
const geometry = {
band: { y: Math.round(layout.windowHeight / 2) - 20, height: 40 },
beside: { x: layout.pageRight - 10, width: 5 },
gutter: { x: layout.pageRight + 3, width: layout.windowWidth - layout.pageRight - 6 },
};
await expectGutterLikeBeside(page, geometry, "closed, the gutter shows the page surface");
const menu = page.getByRole("button", { name: KO_MESSAGES["shell.menu"], exact: true });
await menu.click();
await expect(page.locator(".ui-drawer")).toHaveJSProperty("open", true);
await expectGutterLikeBeside(page, geometry, "open, the scrim reaches the window edge");
await page.keyboard.press("Escape");
await expect(page.locator(".ui-drawer")).toHaveJSProperty("open", false);
await expectGutterLikeBeside(page, geometry, "closed again, the gutter shows the page surface");
});