feat(webui): refine day-night themes and interaction continuity
This commit is contained in:
1 parent
12c7d116a0
commit
e8544a79a6
32 files changed
+613
-29
No files matched your search
@@ -238,7 +238,10 @@ test("unfinished numeric input reports an error instead of acting like a cleared
|
||||
expect(await input.evaluate((element: HTMLInputElement) => element.validity.badInput)).toBe(true);
|
||||
await input.press("Enter");
|
||||
await expect(input).toHaveAttribute("aria-invalid", "true");
|
||||
// The pointer can leave the editor while the user reads the validation hint.
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page.getByRole("tooltip", { name: /Your text remains at 18 px\./ })).toBeVisible();
|
||||
await expect(input).toBeFocused();
|
||||
await expect(paragraph).toHaveCSS("font-size", "18px");
|
||||
await input.click();
|
||||
await input.press("Escape");
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>nanobot · 昼夜小猫对比</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; padding: 48px 24px; color: #262626; background: #f4f3f0; font-family: system-ui, sans-serif; }
|
||||
main { max-width: 760px; margin: auto; }
|
||||
h1 { margin: 0 0 12px; font-size: 28px; font-weight: 600; }
|
||||
p { margin: 0 0 28px; color: #666; line-height: 1.6; }
|
||||
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
|
||||
figure { margin: 0; padding: 36px 24px 24px; border-radius: 24px; text-align: center; background: white; }
|
||||
.night { color: #eee; background: #303030; }
|
||||
.large { display: block; width: 144px; height: 144px; margin: 0 auto 28px; object-fit: contain; }
|
||||
figcaption { font-size: 17px; font-weight: 500; }
|
||||
.actual { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 32px; font-size: 12px; opacity: 0.75; }
|
||||
.actual img { width: 32px; height: 32px; object-fit: contain; }
|
||||
footer { margin-top: 22px; color: #777; font-size: 12px; line-height: 1.6; }
|
||||
@media (max-width: 500px) { body { padding: 28px 16px; } .pair { gap: 12px; } figure { padding: 28px 12px 20px; } .large { width: 104px; height: 104px; } .actual { flex-direction: column; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>同一只小猫,陪你从白天到夜晚。</h1>
|
||||
<p>白天还是熟悉的橘猫,夜晚戴上小睡帽,安静陪着你。</p>
|
||||
<div class="pair">
|
||||
<figure><img class="large" src="/brand/nanobot_mark.svg" alt="原版睁眼橘猫" /><figcaption>白天 · 原版</figcaption><div class="actual"><img src="/brand/nanobot_mark.svg" alt="" /><span>侧栏实际大小 · 32px</span></div></figure>
|
||||
<figure class="night"><img class="large" src="/brand/nanobot_mark_night.svg" alt="戴睡帽的夜间橘猫" /><figcaption>夜晚 · 小睡帽</figcaption><div class="actual"><img src="/brand/nanobot_mark_night.svg" alt="" /><span>侧栏实际大小 · 32px</span></div></figure>
|
||||
</div>
|
||||
<footer>图形对比预览。实际侧栏跟随应用深浅主题,不代表 Agent 停止运行;Dock、favicon 和原版素材均未改变。</footer>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Disclosure } from "@/components/ui/disclosure";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { sidePanelSurfaceClassName } from "@/components/ui/floating-surface";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { SidebarPanel } from "@/components/ui/sidebar-panel";
|
||||
|
||||
export function ContinuityFixture() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const trigger = useRef<HTMLButtonElement>(null);
|
||||
const close = () => { setOpen(false); trigger.current?.focus(); };
|
||||
return <main className="mx-auto flex min-h-screen max-w-5xl flex-col gap-6 px-5 py-12">
|
||||
<h1 className="text-title">Interaction continuity</h1>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild><Button variant="outline">Conversation actions</Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
<DropdownMenuItem>Rename conversation</DropdownMenuItem>
|
||||
<DropdownMenuItem>Duplicate conversation</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild><Button variant="outline">Quick note</Button></PopoverTrigger>
|
||||
<PopoverContent className="w-64 p-4" align="start"><Input aria-label="Quick note draft" placeholder="Write a note" /></PopoverContent>
|
||||
</Popover>
|
||||
<Button ref={trigger} variant="outline" onClick={() => setOpen(value => !value)} aria-expanded={open}>Toggle details</Button>
|
||||
</div>
|
||||
<section className="max-w-lg space-y-4 rounded-panel border p-5">
|
||||
<Disclosure summary="Advanced options" summaryClassName="text-control-label" contentClassName="pt-4">
|
||||
<Input aria-label="Advanced draft" placeholder="This draft survives folding" />
|
||||
<p className="mt-3 text-caption text-muted-foreground">The next row moves with the expanded content.</p>
|
||||
</Disclosure>
|
||||
<p data-testid="following-row" className="text-ui">The following row stays in the page flow.</p>
|
||||
</section>
|
||||
<div className="thread-preview-layout relative flex shrink-0 overflow-hidden rounded-panel border" style={{ height: 340 }}>
|
||||
<div className="min-w-0 flex-1 p-5">
|
||||
<p className="mb-3 text-control-label">Conversation stays in place</p>
|
||||
<Input aria-label="Conversation draft" placeholder="Your next message" />
|
||||
</div>
|
||||
<SidebarPanel open={open} width={420} aria-label="Details" contentClassName={sidePanelSurfaceClassName} header={<span className="text-control-label">Details</span>}
|
||||
onKeyDown={event => { if (event.key === "Escape") { event.preventDefault(); close(); } }}>
|
||||
<div className="space-y-4 p-5">
|
||||
<Input aria-label="Details draft" placeholder="Reopen during closing to keep editing" />
|
||||
<span aria-label="Activity" className="block size-4 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none" />
|
||||
<Button variant="outline" onClick={close}>Close details</Button>
|
||||
</div>
|
||||
</SidebarPanel>
|
||||
</div>
|
||||
</main>;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
for (const width of [1280, 390]) {
|
||||
for (const name of ["Conversation actions", "Quick note"]) {
|
||||
test(`${name} grows from its anchor and returns keyboard focus at ${width}px`, async ({ page }) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.goto("/browser/fixture.html?case=continuity");
|
||||
// Capture at animation start, before protocol latency can outlive the 150ms entry.
|
||||
await page.evaluate(() => {
|
||||
const capture = (event: AnimationEvent) => {
|
||||
const element = event.target as HTMLElement;
|
||||
if (!element.matches("[role=menu], [role=dialog]")) return;
|
||||
for (const animation of element.getAnimations()) if (animation instanceof CSSAnimation) animation.pause();
|
||||
document.removeEventListener("animationstart", capture);
|
||||
};
|
||||
document.addEventListener("animationstart", capture);
|
||||
});
|
||||
const trigger = page.getByRole("button", { name, exact: true, includeHidden: true });
|
||||
const before = (await trigger.boundingBox())!;
|
||||
await trigger.click();
|
||||
const surface = page.getByRole(name === "Quick note" ? "dialog" : "menu");
|
||||
await expect(surface).toBeVisible();
|
||||
await expect(surface).toHaveCSS("pointer-events", "auto");
|
||||
// Keep the entry measurable while Radix resolves the anchor's final geometry.
|
||||
await surface.evaluate(element => { for (const animation of element.getAnimations()) if (animation instanceof CSSAnimation) animation.pause(); });
|
||||
await expect(surface).toHaveCSS("transform-origin", "0px 0px");
|
||||
if (name === "Quick note") await expect(page.getByRole("textbox", { name: "Quick note draft" })).toBeFocused();
|
||||
else await expect(surface).toBeFocused();
|
||||
const motion = await surface.evaluate(element => {
|
||||
const animation = element.getAnimations().find(item => item instanceof CSSAnimation);
|
||||
if (!animation) return null;
|
||||
animation.pause();
|
||||
animation.currentTime = 75;
|
||||
const css = getComputedStyle(element);
|
||||
const sample = { transform: css.transform, origin: css.transformOrigin, side: element.getAttribute("data-side"), width: element.clientWidth };
|
||||
animation.play();
|
||||
return sample;
|
||||
});
|
||||
expect(motion).not.toBeNull();
|
||||
expect(motion!.transform).not.toBe("none");
|
||||
const origin = motion!.origin.split(" ").map(Number.parseFloat);
|
||||
if (motion!.side === "bottom") expect(origin[1]).toBe(0);
|
||||
else if (motion!.side === "top") expect(origin[1]).toBeGreaterThan(0);
|
||||
expect(Math.abs((await trigger.boundingBox())!.x - before.x)).toBeLessThan(1);
|
||||
const box = (await surface.boundingBox())!;
|
||||
expect(box.x).toBeGreaterThanOrEqual(0);
|
||||
expect(box.x + box.width).toBeLessThanOrEqual(width);
|
||||
if (name === "Quick note") await page.getByRole("textbox", { name: "Quick note draft" }).press("Escape");
|
||||
else await surface.press("Escape");
|
||||
await expect(surface).toBeHidden();
|
||||
await expect(trigger).toBeFocused();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test("a sidebar follows its actual exit and preserves an interrupted editor", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=continuity");
|
||||
const toggle = page.getByRole("button", { name: "Toggle details", exact: true });
|
||||
const panel = page.locator(".file-preview-pane");
|
||||
await toggle.click();
|
||||
await expect.poll(() => panel.evaluate(element => Math.round(element.getBoundingClientRect().width))).toBe(420);
|
||||
await page.getByRole("textbox", { name: "Details draft" }).fill("Keep this draft");
|
||||
const original = (await panel.elementHandle())!;
|
||||
// Hold the real close in flight; a wall-clock timeout must not remove the surface.
|
||||
await page.evaluate(async () => {
|
||||
(document.querySelector("button[aria-expanded=true]") as HTMLButtonElement).click();
|
||||
await new Promise(requestAnimationFrame);
|
||||
const node = document.querySelector(".file-preview-pane")!;
|
||||
const animations = [node, node.firstElementChild!].flatMap(element => element.getAnimations());
|
||||
for (const animation of animations) { animation.pause(); animation.currentTime = 80; }
|
||||
});
|
||||
await expect(panel).toHaveAttribute("inert");
|
||||
await expect(panel).toHaveAttribute("aria-hidden", "true");
|
||||
// This exceeds the old fixed 300ms teardown while the actual exit is paused.
|
||||
const heldSince = Date.now();
|
||||
await expect.poll(async () => ({
|
||||
connected: await original.evaluate(element => element.isConnected),
|
||||
held: Date.now() - heldSince >= 350,
|
||||
})).toEqual({ connected: true, held: true });
|
||||
await toggle.click();
|
||||
await expect(panel).not.toHaveAttribute("inert");
|
||||
expect(await original.evaluate(element => element === document.querySelector(".file-preview-pane"))).toBe(true);
|
||||
await expect(page.getByRole("textbox", { name: "Details draft" })).toHaveValue("Keep this draft");
|
||||
await page.getByRole("textbox", { name: "Details draft" }).focus();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(panel).toHaveCount(0);
|
||||
await expect(toggle).toBeFocused();
|
||||
});
|
||||
|
||||
test("folding moves the next row continuously without discarding drafts", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=continuity");
|
||||
const toggle = page.getByRole("button", { name: "Advanced options", exact: true });
|
||||
const content = page.locator(".inline-disclosure");
|
||||
const row = page.getByTestId("following-row");
|
||||
const closed = (await row.boundingBox())!.y;
|
||||
await toggle.click();
|
||||
await expect.poll(() => content.evaluate(element => element.getAnimations().length)).toBe(0);
|
||||
await page.getByRole("textbox", { name: "Advanced draft" }).fill("Keep folded draft");
|
||||
const expanded = (await row.boundingBox())!.y;
|
||||
expect(expanded).toBeGreaterThan(closed + 50);
|
||||
await toggle.click();
|
||||
const middle = await content.evaluate(element => {
|
||||
for (const animation of element.getAnimations()) { animation.pause(); animation.currentTime = 110; }
|
||||
const top = document.querySelector("[data-testid=following-row]")!.getBoundingClientRect().y;
|
||||
for (const animation of element.getAnimations()) animation.play();
|
||||
return top;
|
||||
});
|
||||
expect(middle).toBeGreaterThan(closed);
|
||||
expect(middle).toBeLessThan(expanded);
|
||||
await expect(content).toHaveAttribute("inert");
|
||||
await toggle.click();
|
||||
await expect(page.getByRole("textbox", { name: "Advanced draft" })).toHaveValue("Keep folded draft");
|
||||
});
|
||||
|
||||
test("reduced motion keeps the same controls without travel or delayed teardown", async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.goto("/browser/fixture.html?case=continuity");
|
||||
for (const name of ["Conversation actions", "Quick note"]) {
|
||||
const trigger = page.getByRole("button", { name, exact: true });
|
||||
await trigger.click();
|
||||
const surface = page.getByRole(name === "Quick note" ? "dialog" : "menu");
|
||||
await expect(surface).toHaveCSS("animation-name", "none");
|
||||
await expect(surface).toHaveCSS("pointer-events", "auto");
|
||||
if (name === "Quick note") await expect(page.getByRole("textbox", { name: "Quick note draft" })).toBeFocused();
|
||||
else await expect(surface).toBeFocused();
|
||||
if (name === "Quick note") await page.getByRole("textbox", { name: "Quick note draft" }).press("Escape");
|
||||
else await surface.press("Escape");
|
||||
await expect(surface).toBeHidden();
|
||||
await expect(trigger).toBeFocused();
|
||||
}
|
||||
await page.getByRole("button", { name: "Toggle details", exact: true }).click();
|
||||
const panel = page.locator(".file-preview-pane");
|
||||
await expect(page.getByRole("textbox", { name: "Details draft" })).toBeVisible();
|
||||
await page.getByRole("button", { name: "Close details", exact: true }).click();
|
||||
await expect(panel).toHaveCount(0);
|
||||
});
|
||||
@@ -47,6 +47,7 @@ import { DisplayMathFixture } from "./display-math-fixture";
|
||||
import { AttachmentLayoutFixture } from "./attachment-layout-fixture";
|
||||
import { LoadedSessionSearchFixture } from "./loaded-session-search-fixture";
|
||||
import { AppearanceFixture } from "./appearance-fixture";
|
||||
import { ContinuityFixture } from "./continuity-fixture";
|
||||
import { installSubagentDockApi, SubagentDockFixture } from "./subagent-dock-fixture";
|
||||
|
||||
const history: UIMessage[] = [
|
||||
@@ -226,7 +227,9 @@ if (parameters.get("case") === "appearance" && parameters.has("lang")) {
|
||||
await setAppLanguage(normalizeLocale(parameters.get("lang")));
|
||||
}
|
||||
createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
{parameters.get("case") === "appearance"
|
||||
{parameters.get("case") === "continuity"
|
||||
? <ContinuityFixture />
|
||||
: parameters.get("case") === "appearance"
|
||||
? <AppearanceFixture />
|
||||
: parameters.get("case") === "loaded-session-search"
|
||||
? <LoadedSessionSearchFixture />
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("sidebar cat follows the chosen app theme without moving or losing the draft", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.emulateMedia({ colorScheme: "dark", reducedMotion: "reduce" });
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem("nanobot.locale", "en");
|
||||
if (!localStorage.getItem("nanobot-webui.theme")) localStorage.setItem("nanobot-webui.theme", "light");
|
||||
});
|
||||
await page.goto("/browser/fixture.html?case=theme-toggle&chat");
|
||||
const mark = page.getByTestId("sidebar-brand-mark");
|
||||
const day = mark.locator("img").nth(0);
|
||||
const night = mark.locator("img").nth(1);
|
||||
await expect.poll(() => mark.locator("img").evaluateAll(elements => elements.every(element => {
|
||||
const image = element as HTMLImageElement;
|
||||
return image.complete && image.naturalWidth === 759 && image.naturalHeight === 718;
|
||||
}))).toBe(true);
|
||||
await expect(day).toHaveCSS("opacity", "1");
|
||||
await expect(night).toHaveCSS("opacity", "0");
|
||||
const before = (await mark.boundingBox())!;
|
||||
const draft = page.getByRole("textbox");
|
||||
await draft.fill("Keep this draft while the cat gets sleepy");
|
||||
await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
|
||||
await expect(night).toHaveCSS("opacity", "1");
|
||||
await expect(day).toHaveCSS("opacity", "0");
|
||||
expect(await mark.boundingBox()).toEqual(before);
|
||||
await expect(draft).toHaveValue("Keep this draft while the cat gets sleepy");
|
||||
await page.reload();
|
||||
await expect(night).toHaveCSS("opacity", "1");
|
||||
await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
|
||||
await expect(day).toHaveCSS("opacity", "1");
|
||||
await expect(night).toHaveCSS("opacity", "0");
|
||||
});
|
||||
|
||||
test("the sidebar night mark follows live System theme changes", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.emulateMedia({ colorScheme: "light", reducedMotion: "reduce" });
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem("nanobot.locale", "en");
|
||||
localStorage.setItem("nanobot-webui.theme", "system");
|
||||
});
|
||||
await page.goto("/browser/fixture.html?case=theme-toggle&chat");
|
||||
const images = page.getByTestId("sidebar-brand-mark").locator("img");
|
||||
await expect(images.nth(0)).toHaveCSS("opacity", "1");
|
||||
await expect(images.nth(1)).toHaveCSS("opacity", "0");
|
||||
await page.emulateMedia({ colorScheme: "dark" });
|
||||
await expect(images.nth(1)).toHaveCSS("opacity", "1");
|
||||
await expect(images.nth(0)).toHaveCSS("opacity", "0");
|
||||
});
|
||||
|
||||
test("paired artwork blends in place without native snapshots", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem("nanobot.locale", "en");
|
||||
localStorage.setItem("nanobot-webui.theme", "light");
|
||||
Object.defineProperty(document, "startViewTransition", { value: undefined });
|
||||
});
|
||||
await page.goto("/browser/fixture.html?case=theme-toggle&chat");
|
||||
const mark = page.getByTestId("sidebar-brand-mark");
|
||||
const box = await mark.boundingBox();
|
||||
const draft = page.getByRole("textbox");
|
||||
await draft.fill("A draft survives the artwork transition");
|
||||
await expect(mark.locator("img").first()).toHaveCSS("opacity", "1");
|
||||
// Hold each real opacity transition when it starts, not after a protocol round trip.
|
||||
await page.evaluate(() => document.addEventListener("transitionrun", event => {
|
||||
const image = event.target as HTMLElement;
|
||||
if (!image.matches(".theme-art") || event.propertyName !== "opacity") return;
|
||||
for (const fade of image.getAnimations()) { fade.pause(); fade.currentTime = 100; }
|
||||
}));
|
||||
for (const target of ["dark", "light"]) {
|
||||
await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
|
||||
await expect(mark.locator("img").first()).toHaveCSS("opacity", "0.5");
|
||||
const middle = await mark.evaluate(element => {
|
||||
const images = Array.from(element.querySelectorAll("img"));
|
||||
const fades = images.flatMap(image => image.getAnimations());
|
||||
const result = { theme: document.documentElement.className, count: fades.length, opacity: images.map(image => Number(getComputedStyle(image).opacity)) };
|
||||
for (const fade of fades) fade.finish();
|
||||
return result;
|
||||
});
|
||||
expect(middle.count).toBe(2);
|
||||
expect(middle.theme.includes("dark")).toBe(target === "dark");
|
||||
for (const opacity of middle.opacity) expect(opacity).toBeCloseTo(0.5);
|
||||
await expect(mark.locator("img").nth(target === "dark" ? 1 : 0)).toHaveCSS("opacity", "1");
|
||||
expect(await mark.boundingBox()).toEqual(box);
|
||||
await expect(draft).toHaveValue("A draft survives the artwork transition");
|
||||
await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
for (const width of [1280, 390]) {
|
||||
test(`invitation follows the app theme without losing its artwork or layout at ${width}px`, async ({ page }, info) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.emulateMedia({ colorScheme: "light", reducedMotion: "reduce" });
|
||||
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
|
||||
await page.goto("/browser/fixture.html?case=theme-toggle&star");
|
||||
await page.getByRole("button", { name: "Open invitation", exact: true }).click();
|
||||
const dialog = page.getByRole("dialog");
|
||||
const images = dialog.locator(".star-prompt-art img");
|
||||
await expect(images).toHaveCount(2);
|
||||
await expect.poll(() => images.evaluateAll(elements => elements.every(element => {
|
||||
const image = element as HTMLImageElement;
|
||||
return image.complete && image.naturalWidth === 1672 && image.naturalHeight === 941;
|
||||
}))).toBe(true);
|
||||
await expect(images.nth(0)).toHaveCSS("opacity", "1");
|
||||
await expect(images.nth(1)).toHaveCSS("opacity", "0");
|
||||
await expect(dialog).toHaveCSS("animation-name", "none");
|
||||
const initial = (await dialog.boundingBox())!;
|
||||
await page.screenshot({ path: info.outputPath("invitation-day.png") });
|
||||
|
||||
// System changes are live even while the modal is open.
|
||||
await page.emulateMedia({ colorScheme: "dark" });
|
||||
await expect(images.nth(0)).toHaveCSS("opacity", "0");
|
||||
await expect(images.nth(1)).toHaveCSS("opacity", "1");
|
||||
// Color can still fade; await its settled state rather than sampling the first paint.
|
||||
await expect(dialog).toHaveCSS("background-color", "rgb(36, 41, 50)");
|
||||
const night = (await dialog.boundingBox())!;
|
||||
expect(Math.abs(night.height - initial.height)).toBeLessThanOrEqual(1);
|
||||
expect(night.x).toBeGreaterThanOrEqual(0);
|
||||
expect(night.x + night.width).toBeLessThanOrEqual(width);
|
||||
await expect(dialog.getByRole("button", { name: "Maybe later" })).toBeInViewport();
|
||||
await page.screenshot({ path: info.outputPath("invitation-night.png") });
|
||||
|
||||
// Explicit Light must override a dark OS, rather than using an image media query.
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(dialog).toBeHidden();
|
||||
await page.getByRole("button", { name: "Toggle theme", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Open invitation", exact: true }).click();
|
||||
await expect(images.nth(0)).toHaveCSS("opacity", "1");
|
||||
await expect(images.nth(1)).toHaveCSS("opacity", "0");
|
||||
await dialog.getByRole("button", { name: "Maybe later" }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
});
|
||||
}
|
||||
@@ -9,12 +9,14 @@ import type { ChatSummary, UIMessage } from "@/lib/types";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ThreadHeader } from "@/components/thread/ThreadHeader";
|
||||
import { ThemeProvider, useTheme } from "@/hooks/useTheme";
|
||||
import { StarPromptView } from "@/components/StarPromptView";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function ThemeToggleFixture() {
|
||||
const { theme, toggle } = useTheme();
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
{new URLSearchParams(location.search).has("chat") ? <ThemeChatFixture theme={theme} toggle={toggle} /> : (
|
||||
{new URLSearchParams(location.search).has("star") ? <ThemeInvitationFixture toggle={toggle} /> : new URLSearchParams(location.search).has("chat") ? <ThemeChatFixture theme={theme} toggle={toggle} /> : (
|
||||
<main data-theme-surface className="thread-workspace relative flex flex-col justify-center gap-8 bg-background px-6" style={{ height: "100vh" }}>
|
||||
<div className="absolute inset-x-0 top-0">
|
||||
<ThreadHeader title="Theme preview" hideTitle theme={theme} onToggleTheme={toggle} onToggleSidebar={() => {}} />
|
||||
@@ -31,6 +33,16 @@ export function ThemeToggleFixture() {
|
||||
);
|
||||
}
|
||||
|
||||
function ThemeInvitationFixture({ toggle }: { toggle: () => void }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <main className="flex h-full flex-col items-center justify-center gap-4 bg-background">
|
||||
<Button onClick={toggle}>Toggle theme</Button>
|
||||
<Button onClick={() => setOpen(true)}>Open invitation</Button>
|
||||
<StarPromptView open={open} saving={false} error={false} onOpenChange={setOpen}
|
||||
onDismissForever={() => setOpen(false)} onStar={() => {}} />
|
||||
</main>;
|
||||
}
|
||||
|
||||
const sessions: ChatSummary[] = ["Theme chat", "Another chat"].map((title, index) => ({
|
||||
key: `websocket:theme-${index}`, channel: "websocket", chatId: `theme-${index}`,
|
||||
title, preview: "", createdAt: null, updatedAt: null,
|
||||
|
||||
@@ -199,6 +199,7 @@ for (const width of [1440, 390]) {
|
||||
oldBlend: oldTheme.mixBlendMode, newBlend: newTheme.mixBlendMode,
|
||||
isolation: getComputedStyle(root, "::view-transition-image-pair(root)").isolation,
|
||||
mask: newTheme.maskImage, clip: newTheme.clipPath,
|
||||
artworkDuration: getComputedStyle(document.querySelector(".theme-art")!).transitionDuration,
|
||||
};
|
||||
});
|
||||
expect(middle.durations).toEqual([200, 200]);
|
||||
@@ -212,6 +213,7 @@ for (const width of [1440, 390]) {
|
||||
expect(middle.isolation).toBe("isolate");
|
||||
expect(middle.mask).toBe("none");
|
||||
expect(middle.clip).toBe("none");
|
||||
expect(middle.artworkDuration).toBe("0s");
|
||||
await expect(toggle).toBeFocused();
|
||||
expect(await input.boundingBox()).toEqual(box);
|
||||
await page.screenshot({ path: test.info().outputPath(`crossfade-${width}-${initial}-mid.png`), animations: "allow" });
|
||||
|
||||
Reference in new issue
Block a user