test: replace false-green checks with behavioral coverage (#6282)
* test: replace false-green checks with behavioral coverage * test: complete behavior-focused audit coverage
This commit is contained in:
1 parent
c7ab7aa6da
commit
74942bd190
91 files changed
+1891
-1391
No files matched your search
@@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Browser regression fixtures</title></head>
|
||||
<body><div id="root"></div><script type="module" src="/browser/fixture.tsx"></script></body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { ThreadMessages } from "@/components/thread/ThreadMessages";
|
||||
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { initializeI18n } from "@/i18n";
|
||||
import type { UIMessage } from "@/lib/types";
|
||||
import "../src/globals.css";
|
||||
|
||||
const history: UIMessage[] = [
|
||||
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
|
||||
{ id: "answer", role: "assistant", content: "Earlier answer", createdAt: 1_700_000_001_000 },
|
||||
];
|
||||
const trace: UIMessage = {
|
||||
id: "trace", role: "tool", kind: "trace", content: "Earlier tool call", createdAt: 1_700_000_002_000,
|
||||
};
|
||||
|
||||
function HistoryFixture() {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <main>
|
||||
<button onClick={() => setOpen(!open)}>{open ? "Close history" : "Reopen history"}</button>
|
||||
<section aria-label="Persisted history">
|
||||
{open && <>
|
||||
<ThreadMessages messages={history} isStreaming={false} />
|
||||
<MessageBubble message={trace} />
|
||||
</>}
|
||||
</section>
|
||||
</main>;
|
||||
}
|
||||
|
||||
function TallDialogFixture({ placement }: { placement: "center" | "bottom" }) {
|
||||
return <main aria-label="Background content" style={{ height: 240, overflowY: "auto" }}>
|
||||
<div style={{ minHeight: 1800 }}><Dialog>
|
||||
<DialogTrigger asChild><button>Open tall dialog</button></DialogTrigger>
|
||||
<DialogContent placement={placement}>
|
||||
<DialogTitle>Tall dialog</DialogTitle>
|
||||
<DialogDescription>All controls must remain reachable in a short viewport.</DialogDescription>
|
||||
{Array.from({ length: 30 }, (_, index) => <label key={index}>
|
||||
Field {index + 1}<input aria-label={`Field ${index + 1}`} style={{ display: "block", height: 40 }} />
|
||||
</label>)}
|
||||
<DialogClose asChild><button>Save tall dialog</button></DialogClose>
|
||||
</DialogContent>
|
||||
</Dialog></div>
|
||||
</main>;
|
||||
}
|
||||
|
||||
const parameters = new URLSearchParams(location.search);
|
||||
await initializeI18n();
|
||||
createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
{parameters.get("case") === "history"
|
||||
? <HistoryFixture />
|
||||
: <TallDialogFixture placement={parameters.get("placement") === "bottom" ? "bottom" : "center"} />}
|
||||
</TooltipProvider>);
|
||||
@@ -0,0 +1,77 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
for (const placement of ["center", "bottom"]) {
|
||||
test(`oversized ${placement} dialog keeps both ends keyboard-reachable`, async ({ page }) => {
|
||||
await page.setViewportSize({ width: 640, height: 320 });
|
||||
await page.goto(`/browser/fixture.html?placement=${placement}`);
|
||||
const background = page.getByRole("main", { name: "Background content", includeHidden: true });
|
||||
const trigger = page.getByRole("button", { name: "Open tall dialog" });
|
||||
await trigger.click();
|
||||
const dialog = page.getByRole("dialog", { name: "Tall dialog" });
|
||||
const close = dialog.getByRole("button", { name: "Close", exact: true });
|
||||
const lastAction = dialog.getByRole("button", { name: "Save tall dialog" });
|
||||
await expect(dialog.getByRole("heading", { name: "Tall dialog" })).toBeInViewport({ ratio: 1 });
|
||||
await expect(close).toBeInViewport({ ratio: 1 });
|
||||
expect(await dialog.evaluate((element) => element.scrollHeight)).toBeGreaterThan(320);
|
||||
await expect(page.locator("body")).toHaveAttribute("data-scroll-locked", "1");
|
||||
|
||||
await close.focus();
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await expect(lastAction).toBeFocused();
|
||||
await expect(lastAction).toBeInViewport({ ratio: 1 });
|
||||
expect(await background.evaluate((element) => element.scrollTop)).toBe(0);
|
||||
await lastAction.press("Enter");
|
||||
await expect(dialog).not.toBeVisible();
|
||||
await expect(trigger).toBeFocused();
|
||||
await expect(page.locator("body")).not.toHaveAttribute("data-scroll-locked");
|
||||
await background.hover({ position: { x: 300, y: 180 } });
|
||||
await page.mouse.wheel(0, 400);
|
||||
await expect.poll(() => background.evaluate((element) => element.scrollTop)).toBeGreaterThan(0);
|
||||
});
|
||||
}
|
||||
|
||||
test("reopened completed history is readable without subtree entrance motion", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=history");
|
||||
const history = page.getByRole("region", { name: "Persisted history" });
|
||||
for (let reopen = 0; reopen < 2; reopen++) {
|
||||
const observation = await history.evaluateHandle((element) => {
|
||||
const names = new Set<string>();
|
||||
let frames = 0;
|
||||
let frame = 0;
|
||||
const onAnimation = (event: Event) => names.add((event as AnimationEvent).animationName);
|
||||
element.addEventListener("animationstart", onAnimation);
|
||||
const sample = () => {
|
||||
for (const animation of element.getAnimations({ subtree: true })) {
|
||||
names.add(animation.constructor.name);
|
||||
}
|
||||
frames++;
|
||||
frame = requestAnimationFrame(sample);
|
||||
};
|
||||
frame = requestAnimationFrame(sample);
|
||||
return {
|
||||
get frames() { return frames; },
|
||||
stop() {
|
||||
cancelAnimationFrame(frame);
|
||||
element.removeEventListener("animationstart", onAnimation);
|
||||
return [...names];
|
||||
},
|
||||
};
|
||||
});
|
||||
try {
|
||||
await page.getByRole("button", { name: "Reopen history" }).click();
|
||||
await expect(history.getByText("Earlier question", { exact: true })).toBeVisible();
|
||||
await expect(history.getByText("Earlier answer", { exact: true })).toBeVisible();
|
||||
await expect(history.getByRole("button", { name: "Using a tool", exact: true })).toBeVisible();
|
||||
await expect.poll(() => observation.evaluate((record) => record.frames)).toBeGreaterThan(12);
|
||||
expect(await observation.evaluate((record) => record.stop())).toEqual([]);
|
||||
} finally {
|
||||
await observation.evaluate((record) => record.stop());
|
||||
await observation.dispose();
|
||||
}
|
||||
const disclosure = history.getByRole("button", { name: "Using a tool", exact: true });
|
||||
await disclosure.click();
|
||||
await expect(history.getByText("Earlier tool call", { exact: true })).toBeVisible();
|
||||
await page.getByRole("button", { name: "Close history" }).click();
|
||||
await expect(history.getByText("Earlier question", { exact: true })).not.toBeVisible();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user