fix(webui): use file-type icons in file change activity
This commit is contained in:
1 parent
d076e4ef13
commit
8de03ac0a2
8 files changed
+132
-68
No files matched your search
@@ -1,10 +1,14 @@
|
||||
import { cleanup, render, screen, within } from "@testing-library/react";
|
||||
import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { FileCode2 } from "lucide-react";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { ActivityStep } from "@/components/thread/activity/ActivityStep";
|
||||
|
||||
afterEach(cleanup);
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("animates a running label with details and keeps the completed activity readable", () => {
|
||||
const { rerender } = render(<ActivityStep label="Running Blender" detail="--json project new" active />);
|
||||
@@ -32,3 +36,29 @@ it("keeps truncated activity details available on keyboard focus", async () => {
|
||||
const tooltip = await screen.findByRole("tooltip");
|
||||
expect(within(tooltip).getByText(/Used Blender/)).toHaveTextContent("--json project new");
|
||||
});
|
||||
|
||||
it("describes a named operation marker on keyboard focus before the file action", async () => {
|
||||
render(<ActivityStep icon={FileCode2} markerLabel="Created" label={<button>src/app.tsx</button>} />);
|
||||
|
||||
await userEvent.tab();
|
||||
|
||||
const marker = screen.getByRole("img", { name: "Created" });
|
||||
expect(marker).toHaveFocus();
|
||||
expect(marker.closest('[aria-hidden="true"]')).toBeNull();
|
||||
expect(screen.getByRole("tooltip")).toHaveTextContent("Created");
|
||||
|
||||
await userEvent.tab();
|
||||
expect(screen.getByRole("button", { name: "src/app.tsx" })).toHaveFocus();
|
||||
});
|
||||
|
||||
it("uses the shared hover delay for a named operation marker", () => {
|
||||
vi.useFakeTimers();
|
||||
render(<ActivityStep icon={FileCode2} markerLabel="Created" label={<span>src/app.tsx</span>} />);
|
||||
const marker = screen.getByRole("img", { name: "Created" });
|
||||
|
||||
fireEvent.pointerMove(marker, { pointerType: "mouse" });
|
||||
act(() => vi.advanceTimersByTime(499));
|
||||
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(screen.getByRole("tooltip")).toHaveTextContent("Created");
|
||||
});
|
||||
@@ -162,7 +162,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`Reading file ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Using Blender, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Opening example.com, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("zh-CN"));
|
||||
@@ -171,7 +171,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`正在读取文件 ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("正在使用 Blender, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("正在打开 example.com, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByText("编辑")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "编辑", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("ja"));
|
||||
@@ -180,8 +180,9 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`${path} ファイルを読み取り中`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Blender を使用中, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("example.com 開いています, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "編集", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference").closest('[data-testid="activity-step"]'))
|
||||
.toHaveTextContent(`${path} 編集`);
|
||||
.toHaveAttribute("aria-label", `${path} 編集`);
|
||||
});
|
||||
|
||||
it("loads deferred trace details only after completed activity is expanded", async () => {
|
||||
@@ -535,7 +536,7 @@ describe("AgentActivityCluster", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
assertBetween(screen.getByText("Editing"));
|
||||
assertBetween(screen.getByRole("img", { name: "Editing", exact: true }));
|
||||
|
||||
rerender(
|
||||
<AgentActivityCluster
|
||||
@@ -545,7 +546,7 @@ describe("AgentActivityCluster", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
assertBetween(screen.getByText("Edited"));
|
||||
assertBetween(screen.getByRole("img", { name: "Edited", exact: true }));
|
||||
});
|
||||
|
||||
it.each(["diff", "collapsed_diff"] as const)(
|
||||
@@ -676,7 +677,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByTestId("file-edit-diff")).toBeInTheDocument();
|
||||
expect(screen.getByText("return <Old />;")).toBeInTheDocument();
|
||||
expect(screen.getByText("return <New />;")).toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
|
||||
expect(screen.getAllByTestId("activity-diff-pair")).toHaveLength(1);
|
||||
|
||||
@@ -684,7 +685,7 @@ describe("AgentActivityCluster", () => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "summary" });
|
||||
});
|
||||
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
|
||||
act(() => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "diff" });
|
||||
@@ -977,9 +978,10 @@ describe("AgentActivityCluster", () => {
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("Created")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Created", exact: true }).querySelector("svg"))
|
||||
.toHaveClass("lucide-file-text");
|
||||
expect(screen.getByLabelText("Created tmp.txt")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Edited")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("tmp.txt");
|
||||
expect(!!screen.queryByTestId("file-edit-diff")).toBe(hasDiff);
|
||||
} finally {
|
||||
@@ -1015,8 +1017,9 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByText("Deleted")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Edited")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Deleted", exact: true }).querySelector("svg"))
|
||||
.toHaveClass("lucide-file-code2");
|
||||
expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders file-only edits without a redundant disclosure", () => {
|
||||
@@ -1048,8 +1051,11 @@ describe("AgentActivityCluster", () => {
|
||||
|
||||
expect(screen.queryByRole("button", { name: /edited app\.tsx/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument();
|
||||
const marker = screen.getByRole("img", { name: "Edited", exact: true });
|
||||
expect(marker.querySelector("svg")).toHaveClass("lucide-file-code2");
|
||||
expect(marker.closest('[data-testid="activity-step"]')?.querySelectorAll("svg")).toHaveLength(1);
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
|
||||
expect(screen.getByText("+12")).toBeInTheDocument();
|
||||
expect(screen.getByText("-3")).toBeInTheDocument();
|
||||
@@ -1798,7 +1804,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.queryByText("+0")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("-0")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -1893,7 +1899,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]');
|
||||
const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
|
||||
expect(row).toBeInTheDocument();
|
||||
expect(row).not.toHaveAttribute("title");
|
||||
expect(screen.queryByText("Target text was not found in angry-birds.html.")).not.toBeInTheDocument();
|
||||
@@ -1927,7 +1933,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]');
|
||||
const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
|
||||
expect(row).toBeInTheDocument();
|
||||
expect(row).not.toHaveAttribute("title");
|
||||
expect(screen.queryByText("No permission to change this location.")).not.toBeInTheDocument();
|
||||
@@ -2008,7 +2014,7 @@ describe("AgentActivityCluster", () => {
|
||||
const fileRefs = screen.getAllByTestId("activity-file-reference");
|
||||
expect(fileRefs).toHaveLength(3);
|
||||
expect(fileRefs.every((ref) => ref.textContent?.includes("minecraft-fps/index.html"))).toBe(true);
|
||||
const failedRow = screen.getByText("Could not edit").closest(
|
||||
const failedRow = screen.getByRole("img", { name: "Could not edit", exact: true }).closest(
|
||||
'[data-testid="activity-step"]',
|
||||
);
|
||||
expect(failedRow).toBeInTheDocument();
|
||||
@@ -2066,8 +2072,8 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByText("Could not edit")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Could not edit", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getAllByTestId("activity-file-reference")).toHaveLength(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -63,6 +63,19 @@ describe("shared file icons", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps iconless activity references named and keyboard-operable", () => {
|
||||
const open = vi.fn();
|
||||
render(<FileReferenceChip path="src/app.tsx" previewPath="/repo/src/app.tsx"
|
||||
display="path" showIcon={false} onOpen={open} />);
|
||||
|
||||
const reference = screen.getByRole("button", { name: "src/app.tsx" });
|
||||
expect(reference).toHaveTextContent("src/app.tsx");
|
||||
expect(reference.querySelector("svg")).toBeNull();
|
||||
expect(reference).toHaveAttribute("tabindex", "0");
|
||||
fireEvent.keyDown(reference, { key: "Enter" });
|
||||
expect(open).toHaveBeenCalledWith("/repo/src/app.tsx");
|
||||
});
|
||||
|
||||
it.each(["image", "video"] as const)("retains %s identity when its attachment is unavailable", (kind) => {
|
||||
const { container } = render(<AttachmentTile attachment={{ kind, name: "Unavailable" }} />);
|
||||
expect(container.querySelector("svg")).toHaveClass(kind === "image" ? "lucide-file-image" : "lucide-file-video2");
|
||||
|
||||
@@ -86,7 +86,7 @@ describe("ThreadMessages", () => {
|
||||
const assertIndependentDiff = () => {
|
||||
const diff = screen.getByTestId("file-edit-diff");
|
||||
expect(diff).toBeVisible();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-content"]'))
|
||||
.toBeNull();
|
||||
expect(screen.getByText("File updated")).toBeVisible();
|
||||
|
||||
Reference in new issue
Block a user