fix(webui): stabilize interaction tests and tooltip dismissal
This commit is contained in:
1 parent
c4dac649da
commit
8aa0deaca3
9 files changed
+172
-24
No files matched your search
@@ -318,11 +318,15 @@ test("archived task results stay with the retained boundary when earlier message
|
||||
const body = page.getByTestId("thread-message-region");
|
||||
const otherTasks = body.getByRole("region", { name: "Other tasks" });
|
||||
await expect(otherTasks).toBeAttached();
|
||||
// Clicking an offscreen disclosure scrolls it into view and can prefetch history.
|
||||
await positionAtTop(body);
|
||||
await otherTasks.getByRole("button", { name: /Other tasks/ }).click();
|
||||
await expect(otherTasks.getByRole("button", { name: /Earlier check Completed/ })).toBeVisible();
|
||||
await stableLayout(body);
|
||||
const originalTop = await positionAtTop(body);
|
||||
await body.hover();
|
||||
await expect(body.locator(".thread-history-slot")).toHaveCount(0);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
await page.mouse.wheel(0, -100);
|
||||
await expect(page.locator(".thread-history-status")).toHaveAttribute("data-state", "loading");
|
||||
const held = await expectHeld(body, "Question 40");
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
async function fixture(page: Page) {
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock");
|
||||
// Hold the observed pending-animation window open; input remains native.
|
||||
await page.addStyleTag({ content: "[data-radix-popper-content-wrapper] > [data-state] { animation-delay: 3s !important; }" });
|
||||
await expect(page.getByTestId("subagent-task-dock-trigger")).toContainText("Running: 3");
|
||||
}
|
||||
|
||||
async function showDockHint(page: Page) {
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
await trigger.hover();
|
||||
await expect(trigger).toHaveAttribute("data-state", /open/);
|
||||
await expect(page.getByRole("tooltip")).toContainText("Subtasks");
|
||||
}
|
||||
|
||||
test("a disabled completed-dock hint cannot consume Escape", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 390, height: 900 });
|
||||
await fixture(page);
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
const tree = page.getByTestId("subagent-task-tree");
|
||||
await page.getByRole("button", { name: "增加任务", exact: true }).click();
|
||||
await expect(trigger).toContainText("Running: 23");
|
||||
await page.getByRole("button", { name: "全部完成", exact: true }).click();
|
||||
await expect(trigger).toContainText("Completed: 23");
|
||||
await showDockHint(page);
|
||||
await trigger.click();
|
||||
await expect(trigger).toHaveAttribute("aria-expanded", "true");
|
||||
await expect(tree.locator('[data-task-state="done"]')).toHaveCount(23);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(tree).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a disabled dragged-dock hint cannot consume Escape", async ({ page }) => {
|
||||
await fixture(page);
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
await page.getByRole("button", { name: "增加任务", exact: true }).click();
|
||||
await expect(trigger).toContainText("Running: 23");
|
||||
await showDockHint(page);
|
||||
const bounds = (await trigger.boundingBox())!;
|
||||
const x = bounds.x + 8, y = bounds.y + bounds.height / 2;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x, y + 30, { steps: 4 });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.mouse.move(x, y - 60, { steps: 6 });
|
||||
await page.mouse.up();
|
||||
await expect(trigger).toHaveAttribute("aria-expanded", "false");
|
||||
});
|
||||
|
||||
test("an actually open task tooltip owns the first Escape", async ({ page }) => {
|
||||
await fixture(page);
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
const tree = page.getByTestId("subagent-task-tree");
|
||||
await trigger.click();
|
||||
await expect(tree).toBeVisible();
|
||||
const stop = tree.getByRole("button", { name: "Stop 检查项目实现", exact: true });
|
||||
await stop.hover();
|
||||
await expect(stop).toHaveAttribute("data-state", /open/);
|
||||
await expect(page.getByRole("tooltip")).toContainText("Stop 检查项目实现");
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(page.locator("[data-radix-popper-content-wrapper]")).toHaveCount(0);
|
||||
await expect(trigger).toHaveAttribute("aria-expanded", "true");
|
||||
await expect(tree).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(tree).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a task detail dialog owns the first Escape and returns focus before the next", async ({ page }) => {
|
||||
await fixture(page);
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
const tree = page.getByTestId("subagent-task-tree");
|
||||
const row = tree.locator('[data-subagent-id="preview-0"]');
|
||||
await trigger.click();
|
||||
await row.click();
|
||||
const dialog = page.getByRole("dialog", { name: "检查项目实现", exact: true });
|
||||
await expect(dialog).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(trigger).toHaveAttribute("aria-expanded", "true");
|
||||
await expect(tree).toBeVisible();
|
||||
// The dialog can lose its name before its exit and focus restoration finish.
|
||||
await expect(page.locator('[role="dialog"]')).toHaveCount(0);
|
||||
await expect(row).toBeFocused();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(tree).toHaveCount(0);
|
||||
});
|
||||
@@ -243,20 +243,45 @@ test("browsers without View Transitions keep a working palette fade", async ({ p
|
||||
Object.defineProperty(document, "startViewTransition", { value: undefined });
|
||||
});
|
||||
await page.goto("/browser/fixture.html?case=theme-toggle&chat");
|
||||
const pane = page.locator(".workbench-pane");
|
||||
const sampleHandle = await pane.evaluateHandle(node => {
|
||||
const sample: { before: string; midpoint: string | null; transitions: number; duration: number | null } = {
|
||||
before: getComputedStyle(node).backgroundColor, midpoint: null, transitions: 0, duration: null,
|
||||
};
|
||||
const observer = new MutationObserver(() => {
|
||||
if (!document.documentElement.classList.contains("dark")) return;
|
||||
observer.disconnect();
|
||||
// Capture at the class commit, before a protocol round-trip can outlive the fade.
|
||||
const paint = node.getAnimations().filter(animation => animation instanceof CSSTransition
|
||||
&& animation.transitionProperty === "background-color");
|
||||
sample.transitions = paint.length;
|
||||
const duration = paint[0]?.effect?.getTiming().duration;
|
||||
sample.duration = typeof duration === "number" ? duration : null;
|
||||
if (sample.duration !== null) {
|
||||
paint.forEach(animation => { animation.pause(); animation.currentTime = sample.duration! / 2; });
|
||||
}
|
||||
sample.midpoint = getComputedStyle(node).backgroundColor;
|
||||
paint.forEach(animation => animation.finish());
|
||||
});
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
||||
return sample;
|
||||
});
|
||||
await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
|
||||
await expect(page.locator("html")).toHaveClass(/dark/);
|
||||
const midpoint = await page.locator(".workbench-pane").evaluate(async node => {
|
||||
await new Promise(requestAnimationFrame);
|
||||
const paint = node.getAnimations().filter(animation => animation instanceof CSSTransition);
|
||||
paint.forEach(animation => { animation.pause(); animation.currentTime = 140; });
|
||||
const color = getComputedStyle(node).backgroundColor;
|
||||
paint.forEach(animation => animation.finish());
|
||||
return color;
|
||||
});
|
||||
expect(midpoint).not.toBe("rgb(48, 48, 48)");
|
||||
expect(midpoint).not.toBe("rgb(255, 255, 255)");
|
||||
const sample = await sampleHandle.jsonValue();
|
||||
await sampleHandle.dispose();
|
||||
expect(sample.transitions).toBe(1);
|
||||
expect(sample.duration).toBeGreaterThan(0);
|
||||
expect(sample.before).toBe("rgb(255, 255, 255)");
|
||||
expect(sample.midpoint).not.toBeNull();
|
||||
expect(sample.midpoint).not.toBe("rgb(48, 48, 48)");
|
||||
expect(sample.midpoint).not.toBe(sample.before);
|
||||
await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
|
||||
await expect(page.getByRole("textbox")).toBeEditable();
|
||||
await expect(pane).toHaveCSS("background-color", "rgb(48, 48, 48)");
|
||||
const input = page.getByRole("textbox");
|
||||
await expect(input).toBeEditable();
|
||||
await input.fill("Editing remains available after the fallback fade");
|
||||
await expect(input).toHaveValue("Editing remains available after the fallback fade");
|
||||
});
|
||||
|
||||
test("a browser-skipped transition still applies the theme and releases the toggle", async ({ page }) => {
|
||||
|
||||
@@ -18,10 +18,10 @@ export function HoverHint({ content, children, enabled = true, side = "top", ali
|
||||
<TooltipProvider>
|
||||
<Tooltip open={enabled && open} onOpenChange={(next) => setOpen(enabled && next)}>
|
||||
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||
<TooltipContent side={side} align={align} sideOffset={sideOffset}
|
||||
{enabled && open ? <TooltipContent side={side} align={align} sideOffset={sideOffset}
|
||||
className={cn("max-w-[min(28rem,calc(100vw-2rem))] whitespace-pre-wrap break-words", contentClassName)}>
|
||||
{content}
|
||||
</TooltipContent>
|
||||
</TooltipContent> : null}
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { MessageBlockMenuActions, MessageBubble } from "@/components/MessageBubble";
|
||||
import { preloadMarkdownText } from "@/components/MarkdownText";
|
||||
import { ThreadMessages } from "@/components/thread/ThreadMessages";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
import { parseWebuiThreadPayload } from "@/lib/api";
|
||||
@@ -110,6 +111,8 @@ function menuActions(root: ParentNode = document): HTMLElement {
|
||||
}
|
||||
|
||||
describe("MessageBubble", () => {
|
||||
beforeAll(preloadMarkdownText);
|
||||
|
||||
it.each(["live", "paged history"] as const)("renders and copies literal output unchanged through %s, alongside ordinary Markdown", async (source) => {
|
||||
const raw = [
|
||||
" Switched model preset to `raw`.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { act, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { SessionInfoPopover } from "@/components/thread/SessionInfoPopover";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
@@ -34,6 +34,8 @@ function automationsResponse(jobs: unknown[]) {
|
||||
}
|
||||
|
||||
describe("SessionInfoPopover", () => {
|
||||
beforeAll(async () => { await import("@/components/settings/system/AutomationsSettings"); });
|
||||
|
||||
beforeEach(async () => {
|
||||
await setAppLanguage("en");
|
||||
requestMutation.mockReset();
|
||||
|
||||
@@ -49,12 +49,17 @@ describe("Inline shared proxy setup", () => {
|
||||
const url = within(parent).getByPlaceholderText("https://api.example.com/v1");
|
||||
const key = within(parent).getByPlaceholderText("Enter API key");
|
||||
await user.type(name, "Keep this draft");
|
||||
await user.type(url, "https://gateway.example/v1");
|
||||
await user.type(key, "draft-key");
|
||||
await user.click(url);
|
||||
await user.paste("https://gateway.example/v1");
|
||||
await user.click(key);
|
||||
await user.paste("draft-key");
|
||||
await user.click(within(parent).getByRole("button", { name: "Advanced options" }));
|
||||
await user.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
let setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
await user.type(within(setup).getByRole("textbox"), "http://127.0.0.1:7890");
|
||||
let proxy = within(setup).getByRole("textbox");
|
||||
await user.click(proxy);
|
||||
await user.paste("http://127.0.0.1:7890");
|
||||
expect(proxy).toHaveValue("http://127.0.0.1:7890");
|
||||
await user.click(within(setup).getByRole("button", { name: "Cancel" }));
|
||||
expect(name).toHaveValue("Keep this draft");
|
||||
expect(url).toHaveValue("https://gateway.example/v1");
|
||||
@@ -62,8 +67,10 @@ describe("Inline shared proxy setup", () => {
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
await user.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
expect(within(setup).getByRole("textbox")).toHaveValue("");
|
||||
await user.type(within(setup).getByRole("textbox"), "http://127.0.0.1:7890");
|
||||
proxy = within(setup).getByRole("textbox");
|
||||
expect(proxy).toHaveValue("");
|
||||
await user.click(proxy);
|
||||
await user.paste("http://127.0.0.1:7890");
|
||||
requestMutationMock.mockResolvedValueOnce(saved);
|
||||
await user.click(within(setup).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Shared proxy" })).not.toBeInTheDocument());
|
||||
|
||||
@@ -991,19 +991,29 @@ describe("session-owned task UI", () => {
|
||||
|
||||
it("keeps elapsed time in task rows without repeating it in details", async () => {
|
||||
vi.useFakeTimers();
|
||||
// At 12s row elapsed, the independent activity clock reads 1m 12s.
|
||||
vi.setSystemTime(new Date(162_000));
|
||||
vi.spyOn(performance, "now").mockImplementation(() => Date.now());
|
||||
render(layout());
|
||||
await act(async () => { await Promise.resolve(); });
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(10_000); });
|
||||
fireEvent.click(screen.getByTestId("subagent-task-dock-trigger"));
|
||||
const row = within(screen.getByTestId("subagent-task-tree")).getByRole("button", { name: /Config check Running/ });
|
||||
expect(row).toHaveTextContent("12s");
|
||||
expect(within(row).getByText("12s", { exact: true })).toBeVisible();
|
||||
fireEvent.click(row);
|
||||
const detail = screen.getByRole("dialog", { name: "Config check" });
|
||||
expect(detail).toHaveAccessibleDescription("Running");
|
||||
expect(detail).not.toHaveTextContent("12s");
|
||||
// The child activity has its own wall-clock duration, not the row's elapsed time.
|
||||
const activity = within(detail).getByRole("status", { name: "Working for 1m 12s" });
|
||||
expect(activity).toHaveTextContent(/^Working for 1m 12s$/);
|
||||
const duplicateElapsed = (elapsed: string) => within(detail).queryByText((text, element) =>
|
||||
new RegExp(`\\b${elapsed}\\b`).test(text) && !activity.contains(element));
|
||||
expect(duplicateElapsed("12s")).not.toBeInTheDocument();
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
|
||||
expect(row).toHaveTextContent("13s");
|
||||
expect(within(row).getByText("13s", { exact: true })).toBeVisible();
|
||||
expect(activity).toHaveAccessibleName("Working for 1m 13s");
|
||||
expect(activity).toHaveTextContent(/^Working for 1m 13s$/);
|
||||
expect(duplicateElapsed("13s")).not.toBeInTheDocument();
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
vi.mocked(performance.now).mockRestore();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Window as HappyWindow } from "happy-dom";
|
||||
|
||||
import {
|
||||
assistantForkFlags,
|
||||
@@ -62,7 +63,17 @@ describe("ThreadMessages", () => {
|
||||
link.focus();
|
||||
expect(fireEvent.keyDown(link, { key: "F10", shiftKey: true })).toBe(true);
|
||||
expect(link).toHaveFocus();
|
||||
expect(fireEvent.click(link, { ctrlKey: true })).toBe(true);
|
||||
expect(link).toHaveAttribute("href", "https://example.com/?q=one#two");
|
||||
expect(link).toHaveAttribute("target", "_blank");
|
||||
// Happy DOM follows native links; verify the event without accessing the network.
|
||||
const navigation = (window as unknown as HappyWindow).happyDOM.settings.navigation;
|
||||
const previous = navigation.disableMainFrameNavigation;
|
||||
navigation.disableMainFrameNavigation = true;
|
||||
try {
|
||||
expect(fireEvent.click(link, { ctrlKey: true })).toBe(true);
|
||||
} finally {
|
||||
navigation.disableMainFrameNavigation = previous;
|
||||
}
|
||||
});
|
||||
|
||||
it.each(["diff", "collapsed_diff"] as const)(
|
||||
|
||||
Reference in new issue
Block a user