fix(webui): preserve goal background without property registration
This commit is contained in:
1 parent
4ebd75623f
commit
d3bb330f57
2 files changed
+67
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { expect, test, type Locator, type Page } from "@playwright/test";
|
||||
|
||||
async function disableGoalPropertyRegistration(page: Page) {
|
||||
await page.route("**/goal-island.css", async route => {
|
||||
const response = await route.fetch();
|
||||
const source = await response.text();
|
||||
const declarations = source.match(/@property --goal-island-/g) ?? [];
|
||||
expect(declarations).toHaveLength(3);
|
||||
await route.fulfill({ response, body: source.replaceAll("@property --goal-island-", "@unknown --goal-island-") });
|
||||
});
|
||||
}
|
||||
|
||||
async function expectBackgroundToCover(page: Page, owner: Locator) {
|
||||
const surface = owner.locator(":scope > .goal-island-surface");
|
||||
const [ownerBox, surfaceBox, background] = await Promise.all([
|
||||
owner.boundingBox(),
|
||||
surface.boundingBox(),
|
||||
surface.evaluate(el => {
|
||||
const style = getComputedStyle(el, "::before");
|
||||
return { color: style.backgroundColor, clip: style.clipPath };
|
||||
}),
|
||||
]);
|
||||
expect(ownerBox).not.toBeNull();
|
||||
expect(surfaceBox).not.toBeNull();
|
||||
expect(surfaceBox!.width).toBeCloseTo(ownerBox!.width, 1);
|
||||
expect(surfaceBox!.height).toBeCloseTo(ownerBox!.height, 1);
|
||||
expect(background.color).not.toBe("rgba(0, 0, 0, 0)");
|
||||
expect(background.clip).not.toBe("none");
|
||||
|
||||
const image = await page.screenshot({ clip: { x: ownerBox!.x + 12, y: ownerBox!.y + 10, width: 1, height: 1 } });
|
||||
const pixel = await page.evaluate(async bytes => {
|
||||
const bitmap = await createImageBitmap(new Blob([new Uint8Array(bytes)], { type: "image/png" }));
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = canvas.height = 1;
|
||||
const context = canvas.getContext("2d")!;
|
||||
context.drawImage(bitmap, 0, 0);
|
||||
return Array.from(context.getImageData(0, 0, 1, 1).data);
|
||||
}, Array.from(image));
|
||||
expect(pixel.slice(0, 3).every(channel => channel > 180)).toBe(true);
|
||||
}
|
||||
|
||||
for (const reducedMotion of ["no-preference", "reduce"] as const) {
|
||||
test(`goal background covers the content without registered properties (${reducedMotion})`, async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion });
|
||||
await page.addInitScript(() => { localStorage.setItem("nanobot.locale", "en"); });
|
||||
await disableGoalPropertyRegistration(page);
|
||||
await page.goto("/browser/fixture.html?case=session-transition&preview&topic=goal");
|
||||
await page.addStyleTag({ content: '[data-testid="thread-header"] { background: black !important; }' });
|
||||
|
||||
const trigger = page.getByRole("button", { name: "Show full goal" });
|
||||
await expect(trigger).toBeVisible();
|
||||
await expectBackgroundToCover(page, trigger);
|
||||
|
||||
await trigger.click();
|
||||
const panel = page.getByRole("dialog", { name: "Goal", exact: true });
|
||||
await expect(panel).toBeVisible();
|
||||
await panel.evaluate(async el => { await Promise.all(el.getAnimations({ subtree: true }).map(animation => animation.finished)); });
|
||||
await expectBackgroundToCover(page, panel);
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(panel).toHaveCount(0);
|
||||
await expectBackgroundToCover(page, trigger);
|
||||
});
|
||||
}
|
||||
@@ -36,6 +36,9 @@
|
||||
}
|
||||
.goal-island,
|
||||
.goal-island-panel {
|
||||
--goal-island-width: 100%;
|
||||
--goal-island-height: 100%;
|
||||
--goal-island-radius: 16px;
|
||||
--goal-surface: hsl(var(--sidebar) / 94%);
|
||||
--goal-highlight: rgb(255 255 255 / 80%);
|
||||
--goal-shadow: rgb(20 20 24 / 10%);
|
||||
|
||||
Reference in new issue
Block a user