fix(webui): make action feedback easier to notice (#6702)
* fix(webui): make action feedback easier to notice * fix(webui): preserve undo and report confirmed action results * refactor(webui): trim toast preview and redundant coverage * test(webui): advance the undo window for the last topic deletion
This commit is contained in:
1 parent
0f45d74fec
commit
9ccf3b6214
59 files changed
+1621
-508
No files matched your search
@@ -1,10 +1,17 @@
|
||||
import { useState } from "react";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ToastProvider } from "@/components/ui/toast";
|
||||
|
||||
export function installMissingMicrophonePreview() {
|
||||
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
||||
value: async () => { throw new DOMException("No microphone", "NotFoundError"); },
|
||||
});
|
||||
}
|
||||
|
||||
export function ComposerActionFixture({ parameters }: { parameters: URLSearchParams }) {
|
||||
const [running, setRunning] = useState(false);
|
||||
const [stopRequested, setStopRequested] = useState(false);
|
||||
return <main className="mx-auto w-full max-w-5xl px-4 pt-24">
|
||||
return <ToastProvider><main className="mx-auto w-full max-w-5xl px-4" style={{ paddingTop: "6rem" }}>
|
||||
<ThreadComposer
|
||||
variant={parameters.get("composerVariant") === "thread" ? "thread" : "hero"}
|
||||
placeholder={parameters.has("opening") ? "Opening a new topic…" : undefined}
|
||||
@@ -19,5 +26,5 @@ export function ComposerActionFixture({ parameters }: { parameters: URLSearchPar
|
||||
<button onClick={() => { setRunning(false); setStopRequested(false); }}>Finish response</button>
|
||||
<button onClick={() => document.documentElement.classList.toggle("dark")}>Toggle theme</button>
|
||||
</div>
|
||||
</main>;
|
||||
</main></ToastProvider>;
|
||||
}
|
||||
@@ -1,5 +1,29 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("missing microphone uses a short toast without resizing the mobile composer", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 320, height: 720 });
|
||||
await page.goto("/browser/fixture.html?case=composer-action&voiceError=noDevice");
|
||||
const voice = page.getByRole("button", { name: "Voice input" });
|
||||
const composer = page.locator(".thread-composer-form");
|
||||
await expect(voice).toBeVisible();
|
||||
await page.evaluate(async () => { await document.fonts.ready; });
|
||||
await voice.hover();
|
||||
// Compact controls can be visible before the footer's padding finishes transitioning.
|
||||
await expect(composer).toHaveAttribute("data-compact-controls", "true");
|
||||
const footer = composer.locator(".thread-composer-footer");
|
||||
await expect.poll(() => footer.evaluate((element) => element.getAnimations().some((animation) =>
|
||||
animation instanceof CSSTransition && animation.transitionProperty === "padding-bottom",
|
||||
))).toBe(false);
|
||||
const bounds = await composer.boundingBox();
|
||||
await voice.click();
|
||||
const alert = page.locator('[data-toast-tone="error"]').getByRole("alert");
|
||||
await expect(alert).toHaveText("Connect a microphone to record.");
|
||||
expect(await alert.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true);
|
||||
expect(await composer.boundingBox()).toEqual(bounds);
|
||||
await expect(alert).toBeHidden();
|
||||
await expect(voice).toBeEnabled();
|
||||
});
|
||||
|
||||
for (const width of [1280, 390]) {
|
||||
for (const variant of ["hero", "thread"]) {
|
||||
test(`composer edge presses send and stop without losing the click (${width}px, ${variant})`, async ({ page }) => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { createRoot } from "react-dom/client";
|
||||
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { initializeI18n, setAppLanguage } from "@/i18n";
|
||||
import { normalizeLocale } from "@/i18n/config";
|
||||
import { LOCALE_STORAGE_KEY, normalizeLocale } from "@/i18n/config";
|
||||
import "../src/globals.css";
|
||||
|
||||
const parameters = new URLSearchParams(location.search);
|
||||
@@ -27,6 +27,10 @@ async function loadFixture() {
|
||||
installModelOptionsPreviewApi();
|
||||
return <ModelOptionsFixture />;
|
||||
}
|
||||
case "toast": {
|
||||
const { ToastFixture } = await import("./toast-fixture");
|
||||
return <ToastFixture parameters={parameters} />;
|
||||
}
|
||||
case "session-transition": {
|
||||
const { installSessionTransitionPreviewApi, SessionTransitionFixture } = await import("./session-transition-fixture");
|
||||
if (parameters.has("preview")) installSessionTransitionPreviewApi();
|
||||
@@ -67,7 +71,8 @@ async function loadFixture() {
|
||||
return withClient(<MobileChatLayoutFixture parameters={parameters} />);
|
||||
}
|
||||
case "composer-action": {
|
||||
const { ComposerActionFixture } = await import("./composer-action-fixture");
|
||||
const { ComposerActionFixture, installMissingMicrophonePreview } = await import("./composer-action-fixture");
|
||||
if (parameters.get("voiceError") === "noDevice") installMissingMicrophonePreview();
|
||||
return <ComposerActionFixture parameters={parameters} />;
|
||||
}
|
||||
case "workspace-alignment": {
|
||||
@@ -214,6 +219,12 @@ async function loadFixture() {
|
||||
const fixture = await loadFixture();
|
||||
await initializeI18n();
|
||||
if (fixtureCase === "activity-wheel") await setAppLanguage("zh-CN");
|
||||
if (fixtureCase === "toast" && parameters.has("lang")) {
|
||||
const previous = localStorage.getItem(LOCALE_STORAGE_KEY);
|
||||
await setAppLanguage(normalizeLocale(parameters.get("lang")));
|
||||
if (previous === null) localStorage.removeItem(LOCALE_STORAGE_KEY);
|
||||
else localStorage.setItem(LOCALE_STORAGE_KEY, previous);
|
||||
}
|
||||
if ((["appearance", "session-transition", "tools-catalog"].includes(fixtureCase ?? "") || historyPreview) && parameters.has("lang")) {
|
||||
await setAppLanguage(normalizeLocale(parameters.get("lang")));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Sheet, SheetContent, SheetDescription, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||
import { ToastProvider, useToast } from "@/components/ui/toast";
|
||||
|
||||
function ToastActions({ stack, longTitle, modal }: { stack: boolean; longTitle: boolean; modal: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const show = useToast();
|
||||
const [result, setResult] = useState<"undone" | "committed" | null>(null);
|
||||
|
||||
const play = () => {
|
||||
setResult(null);
|
||||
show?.({
|
||||
message: t("toast.pendingDeleteSingle"),
|
||||
detail: longTitle ? "Research notes: cross-platform layout and keyboard accessibility verification" : "Research notes",
|
||||
tone: "pending",
|
||||
action: { label: t("toast.undo"), run: () => setResult("undone") },
|
||||
onExpire: () => setResult("committed"),
|
||||
});
|
||||
if (stack) show?.({ message: t("fileActions.copied"), tone: "success" });
|
||||
};
|
||||
|
||||
return <main className="mx-auto max-w-3xl space-y-4 px-4" style={{ paddingTop: "8rem" }}>
|
||||
<h1>Toast fixtures</h1>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button variant="outline" onClick={play}>Play timing</Button>
|
||||
{modal && <>
|
||||
{/* The app also has a live region outside the modal; Radix then hides the toast viewport itself. */}
|
||||
<span aria-live="polite" className="sr-only" />
|
||||
<Sheet>
|
||||
<SheetTrigger asChild><Button variant="outline">Open sheet</Button></SheetTrigger>
|
||||
<SheetContent>
|
||||
<SheetTitle>Navigation sheet</SheetTitle>
|
||||
<SheetDescription>Toast actions are not reachable while this sheet is open.</SheetDescription>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</>}
|
||||
</div>
|
||||
{result === "undone" && <p>Undo applied</p>}
|
||||
{result === "committed" && <p>Simulated delete committed</p>}
|
||||
</main>;
|
||||
}
|
||||
|
||||
export function ToastFixture({ parameters }: { parameters: URLSearchParams }) {
|
||||
document.documentElement.classList.toggle("dark", parameters.has("dark"));
|
||||
return <ToastProvider>
|
||||
<ToastActions stack={parameters.get("scene") === "stack"} longTitle={parameters.has("long-title")} modal={parameters.has("modal")} />
|
||||
</ToastProvider>;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { expect, test, type Locator } from "@playwright/test";
|
||||
|
||||
const fixture = "/browser/fixture.html?case=toast&lang=en&scene=";
|
||||
const shadowStyle = (card: Locator, property: string) => card.evaluate(
|
||||
(element, key) => getComputedStyle(element, "::before").getPropertyValue(key),
|
||||
property,
|
||||
);
|
||||
|
||||
test("plain feedback expires in the short tier while the pending delete stays available", async ({ page }) => {
|
||||
await page.clock.install();
|
||||
await page.goto(`${fixture}stack`);
|
||||
await page.getByRole("button", { name: "Play timing" }).click();
|
||||
|
||||
const copied = page.locator('[data-toast-tone="success"]');
|
||||
const deletion = page.locator('[data-toast-tone="pending"]');
|
||||
await expect(copied.getByRole("status")).toHaveText("Copied");
|
||||
await expect(deletion.getByText("Research notes")).toBeVisible();
|
||||
expect(await shadowStyle(copied, "animation-duration")).toBe("3s");
|
||||
expect(await shadowStyle(deletion, "animation-duration")).toBe("8s");
|
||||
await page.clock.runFor(2_000);
|
||||
await expect(copied).toBeVisible();
|
||||
await page.clock.runFor(1_001);
|
||||
await expect(copied).toHaveCount(0);
|
||||
await deletion.getByRole("button", { name: "Undo" }).click();
|
||||
await expect(page.getByText("Undo applied")).toBeVisible();
|
||||
await page.clock.runFor(8_001);
|
||||
await expect(page.getByText("Simulated delete committed")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a long title is clipped on one line without crowding keyboard undo on a narrow screen", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 320, height: 650 });
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.clock.install();
|
||||
await page.goto(`${fixture}delete&dark&long-title`);
|
||||
await page.getByRole("button", { name: "Play timing" }).click();
|
||||
|
||||
const card = page.locator('[data-toast-tone="pending"]');
|
||||
const status = card.getByRole("status");
|
||||
const undo = card.getByRole("button", { name: "Undo" });
|
||||
await expect(status).toContainText("Research notes: cross-platform layout and keyboard accessibility verification");
|
||||
await expect(undo).toBeInViewport();
|
||||
const bounds = (await card.boundingBox())!;
|
||||
const content = (await status.boundingBox())!;
|
||||
const button = (await undo.boundingBox())!;
|
||||
expect(bounds.x).toBeGreaterThanOrEqual(12);
|
||||
expect(bounds.x + bounds.width).toBeLessThanOrEqual(308);
|
||||
expect(bounds.height).toBeLessThanOrEqual(44);
|
||||
expect(button.x).toBeGreaterThan(content.x + content.width);
|
||||
expect(content.y + content.height / 2).toBeCloseTo(button.y + button.height / 2);
|
||||
expect(await status.evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(true);
|
||||
|
||||
await undo.focus();
|
||||
await expect(undo).toBeFocused();
|
||||
await page.clock.runFor(8_001);
|
||||
await undo.press("Enter");
|
||||
await expect(page.getByText("Undo applied")).toBeVisible();
|
||||
});
|
||||
|
||||
test("a pending delete waits while hovered and commits after leaving the card", async ({ page }) => {
|
||||
await page.clock.install();
|
||||
await page.goto(`${fixture}delete`);
|
||||
await page.getByRole("button", { name: "Play timing" }).click();
|
||||
|
||||
const undo = page.getByRole("button", { name: "Undo" });
|
||||
const committed = page.getByText("Simulated delete committed");
|
||||
const card = page.locator('[data-toast-tone="pending"]');
|
||||
await undo.hover();
|
||||
await expect.poll(() => shadowStyle(card, "animation-play-state")).toBe("paused");
|
||||
await page.clock.runFor(8_001);
|
||||
await expect(undo).toBeVisible();
|
||||
await expect(committed).toHaveCount(0);
|
||||
|
||||
await page.getByRole("heading", { name: "Toast fixtures" }).hover();
|
||||
await expect.poll(() => shadowStyle(card, "animation-play-state")).toBe("running");
|
||||
await page.clock.runFor(8_001);
|
||||
await expect(committed).toBeVisible();
|
||||
await expect(undo).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a modal sheet pauses an unreachable Undo and preserves the remaining time", async ({ page }) => {
|
||||
await page.clock.install();
|
||||
await page.goto(`${fixture}delete&modal`);
|
||||
await page.getByRole("button", { name: "Play timing" }).click();
|
||||
const undo = page.getByRole("button", { name: "Undo" });
|
||||
const card = page.locator('[data-toast-tone="pending"]');
|
||||
const committed = page.getByText("Simulated delete committed");
|
||||
await expect(undo).toBeVisible();
|
||||
await page.clock.runFor(3_000);
|
||||
await page.getByRole("button", { name: "Open sheet" }).click();
|
||||
await expect(page.getByRole("dialog", { name: "Navigation sheet" })).toBeVisible();
|
||||
await expect(undo).toHaveCount(0);
|
||||
await expect.poll(() => shadowStyle(card, "animation-play-state")).toBe("paused");
|
||||
await page.clock.runFor(8_001);
|
||||
await expect(card).toBeAttached();
|
||||
await expect(committed).toHaveCount(0);
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(undo).toBeVisible();
|
||||
await page.clock.runFor(4_000);
|
||||
await expect(undo).toBeVisible();
|
||||
await page.clock.runFor(1_100);
|
||||
await expect(committed).toBeVisible();
|
||||
await expect(undo).toHaveCount(0);
|
||||
});
|
||||
Reference in new issue
Block a user