refactor(webui): use native link actions and remove website previews (#6391)
* refactor(webui): remove website previews and custom link menus * docs(webui): focus guide on product-specific usage
This commit is contained in:
1 parent
bc5c58d239
commit
08ca3b4525
42 files changed
+179
-1493
No files matched your search
@@ -92,7 +92,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
const store = new FilePreviewStore();
|
||||
const resource = createFilePreviewResource(path => fetchFilePreview("test", "a", path));
|
||||
store.open("a", "file", "reports/REPORT.md");
|
||||
store.open("a", "reports/REPORT.md");
|
||||
function View() {
|
||||
const { state, openFile, resolveFile, selectTab, closeTab, close } = useFilePreviewState("a", store);
|
||||
const active = state.tabs.find(tab => tab.id === state.activeId)!;
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("shared file icons", () => {
|
||||
const open = vi.fn();
|
||||
render(<>
|
||||
<FileReferenceChip path={path} onOpen={open} />
|
||||
<PreviewPane tabs={[{ id: path, kind: "file", value: path }]} activeId={path}
|
||||
<PreviewPane tabs={[{ id: path, value: path }]} activeId={path}
|
||||
width={544} isClosing={false} onSelect={() => {}} onCloseTab={() => {}}
|
||||
onClose={() => {}} onResizeStart={() => {}}><p>Preview</p></PreviewPane>
|
||||
<AttachmentTile attachment={{ kind: "file", name: path, url: `/download/${path}` }} />
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { useRef } from "react";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { preloadMarkdownText } from "@/components/MarkdownText";
|
||||
import { ThreadMessages } from "@/components/thread/ThreadMessages";
|
||||
import { WebLink, WebPreviewContext } from "@/components/WebLink";
|
||||
import { useMessageWebLinks } from "@/components/MessageLinksMenu";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
|
||||
vi.mock("@/lib/clipboard", () => ({ copyTextToClipboard: vi.fn(async () => true) }));
|
||||
const credentialless = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "credentialless");
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", { configurable: true, value: false });
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup(); vi.unstubAllGlobals(); vi.mocked(copyTextToClipboard).mockReset().mockResolvedValue(true);
|
||||
if (credentialless) Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", credentialless);
|
||||
else Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
});
|
||||
|
||||
function view(content: string, openPreview?: (url: string) => void) {
|
||||
return <WebPreviewContext.Provider value={openPreview}>
|
||||
<ThreadMessages messages={[{ id: "links", role: "assistant", content, createdAt: 1 }]} />
|
||||
</WebPreviewContext.Provider>;
|
||||
}
|
||||
|
||||
async function openLinks() {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View links" }));
|
||||
return screen.getByRole("dialog", { name: "Message actions" });
|
||||
}
|
||||
|
||||
describe("message link actions", () => {
|
||||
beforeAll(preloadMarkdownText);
|
||||
|
||||
function mobileViewport() {
|
||||
const listeners = new Set<() => void>();
|
||||
let narrow = true;
|
||||
vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
|
||||
get matches() { return query === "(max-width: 767px)" && narrow; },
|
||||
media: query,
|
||||
addEventListener: (_event: string, listener: () => void) => listeners.add(listener),
|
||||
removeEventListener: (_event: string, listener: () => void) => listeners.delete(listener),
|
||||
})));
|
||||
return (value: boolean) => act(() => { narrow = value; listeners.forEach(listener => listener()); });
|
||||
}
|
||||
|
||||
it("puts mobile actions after the reply and opens one bottom sheet with working back, copy and preview", async () => {
|
||||
mobileViewport();
|
||||
const preview = vi.fn();
|
||||
const content = "[Website](https://example.com/demo)";
|
||||
const { container } = render(view(content, preview));
|
||||
const link = await screen.findByRole("link", { name: /Website/ });
|
||||
const footer = container.querySelector("[data-message-mobile-actions]")!;
|
||||
expect(link.compareDocumentPosition(footer) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(container.querySelector(".message-block-menu-trigger")).not.toBeInTheDocument();
|
||||
expect(container.querySelector("[data-message-hover-time]")).not.toBeInTheDocument();
|
||||
fireEvent.click(within(footer as HTMLElement).getByRole("button", { name: "Copy" }));
|
||||
await waitFor(() => expect(copyTextToClipboard).toHaveBeenCalledWith(content));
|
||||
const menu = await openLinks();
|
||||
expect(menu).toHaveAttribute("data-message-mobile-sheet");
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Back" }));
|
||||
expect(within(menu).queryByRole("button", { name: "Copy" })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Close" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Message actions" })).toHaveFocus();
|
||||
await openLinks();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Preview website" }));
|
||||
expect(preview).toHaveBeenCalledWith("https://example.com/demo");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it("restores the desktop menu on resize without duplicating actions", async () => {
|
||||
const resize = mobileViewport();
|
||||
const { container } = render(view("[Website](https://example.com/demo)"));
|
||||
await screen.findByRole("link", { name: /Website/ });
|
||||
await openLinks();
|
||||
resize(false);
|
||||
await waitFor(() => expect(container.querySelector("[data-message-mobile-actions]")).not.toBeInTheDocument());
|
||||
expect(screen.queryByRole("dialog")).not.toHaveAttribute("data-message-mobile-sheet");
|
||||
expect(screen.getAllByRole("button", { name: "Message actions" })).toHaveLength(1);
|
||||
// Resizing may close the modal as focus is returned; either way its trigger stays usable.
|
||||
if (!screen.queryByRole("dialog")) fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
});
|
||||
it("keeps mobile users in the link sheet when isolated previews are unsupported", async () => {
|
||||
mobileViewport();
|
||||
Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
const preview = vi.fn();
|
||||
render(view("[Website](https://example.com/demo)", preview));
|
||||
await screen.findByRole("link", { name: /Website/ });
|
||||
const menu = await openLinks();
|
||||
expect(within(menu).queryByRole("button", { name: "Preview website" })).not.toBeInTheDocument();
|
||||
expect(within(menu).getByText(/does not support credential-isolated/)).toBeVisible();
|
||||
const external = within(menu).getByRole("link", { name: "Open in browser" });
|
||||
expect(external).toHaveAttribute("href", "https://example.com/demo");
|
||||
expect(external).toHaveAttribute("rel", "noreferrer noopener");
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Copy link" }));
|
||||
await waitFor(() => expect(copyTextToClipboard).toHaveBeenLastCalledWith("https://example.com/demo"));
|
||||
expect(preview).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole("dialog")).toBe(menu);
|
||||
});
|
||||
|
||||
it("keeps user actions outside the bubble and exposes a labelled mobile fork action", async () => {
|
||||
mobileViewport();
|
||||
const fork = vi.fn();
|
||||
const { container } = render(<ThreadMessages onForkFromMessage={fork} messages={[
|
||||
{ id: "user", role: "user", content: "A prompt", createdAt: 1 },
|
||||
{ id: "reply", role: "assistant", content: "A reply", createdAt: 2 },
|
||||
]} />);
|
||||
await screen.findByText("A reply");
|
||||
expect(container.querySelector("[data-user-text-bubble] [data-message-block-menu-trigger]")).toBeNull();
|
||||
expect(container.querySelectorAll("[data-message-mobile-actions]")).toHaveLength(2);
|
||||
fireEvent.click(screen.getAllByRole("button", { name: "Message actions" })[1]);
|
||||
const menu = screen.getByRole("dialog");
|
||||
expect(within(menu).getByRole("button", { name: "New chat from here" })).toHaveTextContent("New chat from here");
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "New chat from here" }));
|
||||
expect(fork).toHaveBeenCalledWith(1);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it("collects rendered links, deduplicates destinations and ignores code, images and file references", async () => {
|
||||
render(view("[First](https://example.com/) and [Again](https://example.com).\n\n[Second](https://example.org/demo)\n\nhttps://example.net/plain\n\n`https://code.invalid/inline`\n\n```text\nhttps://code.invalid/block\n```\n\n\n\n[notes.txt](notes.txt)"));
|
||||
await screen.findByRole("link", { name: "First" });
|
||||
const menu = await openLinks();
|
||||
expect(within(menu).getAllByRole("button").map(button => button.textContent)).toEqual(["View links", "First", "Second", "https://example.net/plain"]);
|
||||
expect(within(menu).queryByRole("button", { name: "Again" })).not.toBeInTheDocument();
|
||||
expect(within(menu).getByRole("button", { name: "Second" })).toBeVisible();
|
||||
expect(within(menu).getByRole("button", { name: "https://example.net/plain" })).toBeVisible();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "First" }));
|
||||
expect(within(menu).getByRole("link", { name: "Open in browser" })).toHaveAttribute("href", "https://example.com/");
|
||||
expect(within(menu).getByRole("link", { name: "Open in browser" })).toHaveAttribute("rel", "noreferrer noopener");
|
||||
expect(within(menu).queryByRole("button", { name: "Preview website" })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Back" }));
|
||||
expect(within(menu).getByRole("button", { name: "Second" })).toBeVisible();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Back" }));
|
||||
expect(within(menu).getByRole("button", { name: "View links" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("does not show an entry for a message without a rendered web link", async () => {
|
||||
render(view("No links here. `https://example.com/code` [Mail](mailto:test@example.com) [Unsafe](javascript:alert)"));
|
||||
await screen.findByText(/No links here/);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
expect(screen.queryByRole("button", { name: "View links" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens the single link's actions directly and closes the message menu on preview", async () => {
|
||||
const preview = vi.fn();
|
||||
render(view("[Website](https://example.com/demo?q=one#two)", preview));
|
||||
await screen.findByRole("link", { name: /Website/ });
|
||||
const menu = await openLinks();
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Preview website" }));
|
||||
expect(preview).toHaveBeenCalledWith("https://example.com/demo?q=one#two");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
expect(screen.getByRole("button", { name: "View links" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("provides copy feedback and retry without losing the selected link", async () => {
|
||||
vi.mocked(copyTextToClipboard).mockResolvedValueOnce(false).mockResolvedValueOnce(true);
|
||||
render(view("[Website](https://example.com/demo)"));
|
||||
await screen.findByRole("link", { name: /Website/ });
|
||||
const menu = await openLinks();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Copy link" }));
|
||||
expect(await screen.findByRole("status")).toHaveTextContent("Could not copy link");
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Copy link" }));
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("Link copied"));
|
||||
expect(copyTextToClipboard).toHaveBeenLastCalledWith("https://example.com/demo");
|
||||
fireEvent.keyDown(menu, { key: "Escape" });
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Message actions" })).toHaveFocus();
|
||||
});
|
||||
|
||||
it("ignores late copy feedback after going back", async () => {
|
||||
let finish!: (result: boolean) => void;
|
||||
vi.mocked(copyTextToClipboard).mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
|
||||
render(view("[Old](https://example.com/old)"));
|
||||
await screen.findByRole("link", { name: /Old/ });
|
||||
const menu = await openLinks();
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Copy link" }));
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Back" }));
|
||||
await act(async () => finish(true));
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
expect(within(menu).getByRole("button", { name: "View links" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("tracks newly rendered or changed links only within the owning message", async () => {
|
||||
function LiveMessage({ href }: { href: string | null }) {
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
const links = useMessageWebLinks(root, true);
|
||||
return <><WebLink href="https://elsewhere.invalid/">Another message</WebLink>
|
||||
<div ref={root}>
|
||||
<WebLink href="https://activity.invalid/">An activity link, not part of the reply</WebLink>
|
||||
<div data-assistant-selectable>{href ? <WebLink href={href}>Current link</WebLink> : null}</div>
|
||||
</div>
|
||||
<output>{links.map(link => link.href).join(",")}</output></>;
|
||||
}
|
||||
const { rerender } = render(<LiveMessage href={null} />);
|
||||
expect(screen.getByRole("status")).toBeEmptyDOMElement();
|
||||
rerender(<LiveMessage href="https://example.com/old" />);
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent(/^https:\/\/example.com\/old$/));
|
||||
rerender(<LiveMessage href="https://example.com/new" />);
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent(/^https:\/\/example.com\/new$/));
|
||||
rerender(<LiveMessage href={null} />);
|
||||
await waitFor(() => expect(screen.getByRole("status")).toBeEmptyDOMElement());
|
||||
});
|
||||
});
|
||||
@@ -6,20 +6,20 @@ import { FilePreviewStore, useFilePreviewState } from "@/hooks/useFilePreviewSta
|
||||
describe("preview tabs", () => {
|
||||
it("reuses a gateway-resolved file without merging same-named files or sessions", () => {
|
||||
const store = new FilePreviewStore();
|
||||
store.open("a", "file", "reports/REPORT.md");
|
||||
store.open("a", "reports/REPORT.md");
|
||||
store.resolveFile("a", "reports/REPORT.md", "/workspace/reports/REPORT.md");
|
||||
store.open("a", "file", "/workspace/reports/./details.md");
|
||||
store.open("a", "/workspace/reports/./details.md");
|
||||
store.resolveFile("a", "/workspace/reports/./details.md", "/workspace/reports/details.md");
|
||||
store.update("a", { width: 620 });
|
||||
store.open("a", "file", "/workspace/reports/./REPORT.md");
|
||||
store.open("a", "/workspace/reports/./REPORT.md");
|
||||
store.resolveFile("a", "/workspace/reports/./REPORT.md", "/workspace/reports/REPORT.md");
|
||||
expect(store.get("a").tabs.map(tab => tab.value)).toEqual([
|
||||
"reports/REPORT.md", "/workspace/reports/./details.md",
|
||||
]);
|
||||
expect(store.get("a")).toMatchObject({ activeId: "file:reports/REPORT.md", width: 620 });
|
||||
store.open("a", "file", "archive/REPORT.md");
|
||||
store.open("a", "archive/REPORT.md");
|
||||
store.resolveFile("a", "archive/REPORT.md", "/workspace/archive/REPORT.md");
|
||||
store.open("b", "file", "reports/REPORT.md");
|
||||
store.open("b", "reports/REPORT.md");
|
||||
store.resolveFile("b", "reports/REPORT.md", "/workspace/reports/REPORT.md");
|
||||
expect(store.get("a").tabs).toHaveLength(3);
|
||||
expect(store.get("b").tabs).toHaveLength(1);
|
||||
@@ -28,11 +28,11 @@ describe("preview tabs", () => {
|
||||
it("deduplicates targets, keeps selection and width per session, and closes neighboring tabs", () => {
|
||||
const store = new FilePreviewStore();
|
||||
const storage = vi.spyOn(Storage.prototype, "setItem");
|
||||
store.open("a", "file", "chart.png");
|
||||
store.open("a", "file", "index.html");
|
||||
store.open("a", "file", "data.json");
|
||||
store.open("a", "chart.png");
|
||||
store.open("a", "index.html");
|
||||
store.open("a", "data.json");
|
||||
store.update("a", { width: 620 });
|
||||
store.open("a", "file", "index.html");
|
||||
store.open("a", "index.html");
|
||||
expect(store.get("a").tabs).toHaveLength(3);
|
||||
expect(store.get("a").activeId).toBe("file:index.html");
|
||||
store.closeTab("a", "file:chart.png");
|
||||
@@ -42,12 +42,12 @@ describe("preview tabs", () => {
|
||||
store.select("a", "missing");
|
||||
store.closeTab("a", "missing");
|
||||
expect(store.get("a").activeId).toBe("file:data.json");
|
||||
store.open("b", "web", "https://example.com");
|
||||
store.open("b", "other.txt");
|
||||
expect(store.get("a").width).toBe(620);
|
||||
store.closeTab("a", "file:data.json");
|
||||
expect(store.get("a")).toMatchObject({ tabs: [], activeId: null, width: 620 });
|
||||
expect(store.get("b").tabs).toHaveLength(1);
|
||||
store.open("a", "file", "chart.png");
|
||||
store.open("a", "chart.png");
|
||||
store.close("a");
|
||||
expect(store.get("a")).toMatchObject({ tabs: [], activeId: null, width: 620 });
|
||||
store.delete("b");
|
||||
@@ -60,9 +60,9 @@ describe("preview tabs", () => {
|
||||
|
||||
it("keeps one shell, supports keyboard tabs and close buttons, and never reloads the same tab", async () => {
|
||||
const store = new FilePreviewStore();
|
||||
store.open("a", "file", "chart.png");
|
||||
store.open("a", "file", "index.html");
|
||||
store.open("a", "file", "data.json");
|
||||
store.open("a", "chart.png");
|
||||
store.open("a", "index.html");
|
||||
store.open("a", "data.json");
|
||||
function View() {
|
||||
const { state, selectTab, closeTab, close } = useFilePreviewState("a", store);
|
||||
return state.activeId ? <PreviewPane tabs={state.tabs} activeId={state.activeId} width={544}
|
||||
@@ -86,7 +86,7 @@ describe("preview tabs", () => {
|
||||
fireEvent.keyDown(screen.getByRole("tab", { name: "chart.png" }), { key: "ArrowRight" });
|
||||
expect(screen.getByRole("tab", { name: "index.html" })).toHaveFocus();
|
||||
expect(screen.getByRole("tab", { name: "index.html" })).toHaveAttribute("aria-selected", "true");
|
||||
act(() => store.open("a", "file", "index.html"));
|
||||
act(() => store.open("a", "index.html"));
|
||||
expect(screen.getAllByRole("tab")).toHaveLength(3);
|
||||
fireEvent.keyDown(screen.getByRole("tab", { name: "index.html" }), { key: "Delete" });
|
||||
expect(screen.queryByRole("tab", { name: "index.html" })).not.toBeInTheDocument();
|
||||
@@ -108,7 +108,7 @@ describe("preview tabs", () => {
|
||||
disconnect = disconnect;
|
||||
});
|
||||
try {
|
||||
const tab = { id: "file:chart.png", kind: "file" as const, value: "chart.png" };
|
||||
const tab = { id: "file:chart.png", value: "chart.png" };
|
||||
const view = render(<PreviewPane tabs={[tab]} activeId={tab.id} width={544} isClosing={false}
|
||||
onSelect={() => {}} onCloseTab={() => {}} onClose={() => {}} onResizeStart={() => {}}>
|
||||
<p>Preview</p>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// @vitest-environment-options {"settings":{"disableIframePageLoading":true}}
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -11,7 +10,6 @@ import { canonicalThreadPayload } from "./thread-test-payload";
|
||||
|
||||
let groupedTopics = false;
|
||||
let withFiles = false;
|
||||
const credentialless = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "credentialless");
|
||||
const previewFile = (path: string) => ({
|
||||
path: `/workspace/${path}`, display_path: path, project_path: "/workspace",
|
||||
language: "text", content: `Preview of ${path}`, size: 20, truncated: false,
|
||||
@@ -151,8 +149,6 @@ describe("temporary chat navigation", () => {
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
if (credentialless) Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", credentialless);
|
||||
else Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
if (vi.isFakeTimers()) vi.clearAllTimers();
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
@@ -323,53 +319,6 @@ describe("temporary chat navigation", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("restores website targets per session, switches to files, and closes below menus", async () => {
|
||||
// Exercise the working embed path; unsupported browsers do not offer it.
|
||||
Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", { configurable: true, value: false });
|
||||
withFiles = true;
|
||||
render(<App />);
|
||||
await screen.findByRole("button", { name: "Temporary chat" });
|
||||
act(() => TestSocket.current.open());
|
||||
await startTemporaryChat("Synthetic separate session");
|
||||
await selectTopic("Regular topic");
|
||||
const website = await screen.findByRole("link", { name: "Website" });
|
||||
const storedWebsiteValues = () => [localStorage, sessionStorage].map((storage) =>
|
||||
Array.from({ length: storage.length }, (_, i) => storage.getItem(storage.key(i)!))
|
||||
.filter((value) => value?.includes("https://example.com/demo")));
|
||||
const beforePreview = storedWebsiteValues();
|
||||
fireEvent.contextMenu(website);
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Preview website" }));
|
||||
await screen.findByTestId("web-preview-panel");
|
||||
await selectTopic("Synthetic separate session");
|
||||
await waitFor(() => expect(screen.queryByTestId("web-preview-panel")).not.toBeInTheDocument());
|
||||
await selectTopic("Regular topic");
|
||||
await screen.findByTestId("web-preview-panel");
|
||||
fireEvent.contextMenu(screen.getByRole("link", { name: "Website" }));
|
||||
await screen.findByRole("menu");
|
||||
fireEvent.keyDown(screen.getByRole("menu"), { key: "Escape" });
|
||||
expect(screen.getByTestId("web-preview-panel")).toBeInTheDocument();
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
fireEvent.keyDown(window, { key: "Escape" });
|
||||
await waitFor(() => expect(screen.queryByTestId("web-preview-panel")).not.toBeInTheDocument());
|
||||
// The same pane is reachable with taps only, without intercepting a native
|
||||
// touch context menu or adding a button next to every rendered link.
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View links" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Preview website" }));
|
||||
await screen.findByTestId("web-preview-panel");
|
||||
expect(screen.queryByRole("dialog", { name: "Message actions" })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "notes.txt" }));
|
||||
await waitFor(() => expect(screen.queryByTestId("web-preview-panel")).not.toBeInTheDocument());
|
||||
await screen.findByText("Preview of notes.txt");
|
||||
fireEvent.contextMenu(screen.getByRole("link", { name: "Website" }));
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Preview website" }));
|
||||
expect(screen.queryByTestId("file-preview-panel")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close preview pane" }));
|
||||
await waitFor(() => expect(screen.queryByTestId("web-preview-panel")).not.toBeInTheDocument());
|
||||
// The transcript may cache its link; preview targets must not add persisted state.
|
||||
expect(storedWebsiteValues()).toEqual(beforePreview);
|
||||
});
|
||||
|
||||
it("keeps the sidebar mounted across tabs, deduplicates repeated opens, and handles Escape below dialogs", async () => {
|
||||
withFiles = true;
|
||||
render(<App />);
|
||||
@@ -418,7 +367,7 @@ describe("temporary chat navigation", () => {
|
||||
expect(store.get(`websocket:${chatId}`).activeId).toBe("file:notes.txt");
|
||||
await selectTopic("Close temporary chat: Show example files");
|
||||
expect(store.get(`websocket:${chatId}`).tabs).toEqual([]);
|
||||
act(() => store.open("websocket:regular", "file", "notes.txt"));
|
||||
act(() => store.open("websocket:regular", "notes.txt"));
|
||||
vi.useFakeTimers();
|
||||
act(() => TestSocket.current.close());
|
||||
expect(store.get("websocket:regular").tabs).toEqual([]);
|
||||
|
||||
@@ -52,6 +52,19 @@ function openMessageBlockMenu(root: ParentNode): {
|
||||
}
|
||||
|
||||
describe("ThreadMessages", () => {
|
||||
it("preserves native context menus and navigation on rendered reply links", async () => {
|
||||
await preloadMarkdownText();
|
||||
render(<ThreadMessages messages={[
|
||||
{ id: "reply", role: "assistant", content: "[**Website**](https://example.com/?q=one#two)", createdAt: 1 },
|
||||
]} />);
|
||||
const link = await screen.findByRole("link", { name: "Website" });
|
||||
expect(fireEvent.contextMenu(within(link).getByText("Website"))).toBe(true);
|
||||
link.focus();
|
||||
expect(fireEvent.keyDown(link, { key: "F10", shiftKey: true })).toBe(true);
|
||||
expect(link).toHaveFocus();
|
||||
expect(fireEvent.click(link, { ctrlKey: true })).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["diff", "collapsed_diff"] as const)(
|
||||
"keeps completed %s edits visible when answer activity is toggled",
|
||||
(fileEditDisplayMode) => {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { WebLink } from "@/components/WebLink";
|
||||
|
||||
const href = "https://example.com/?q=one#two";
|
||||
|
||||
describe("browser-owned web links", () => {
|
||||
it("keeps the address, anchor attributes and caller styling", () => {
|
||||
render(<WebLink href={href} className="underline" title="Full title">Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
expect(link).toHaveAttribute("href", href);
|
||||
expect(link).toHaveAttribute("target", "_blank");
|
||||
expect(link).toHaveAttribute("rel", "noreferrer noopener");
|
||||
expect(link).toHaveClass("underline");
|
||||
expect(link).toHaveAttribute("title", "Full title");
|
||||
});
|
||||
|
||||
it.each(["mouse", "touch"])("leaves %s context menus to the browser", (pointerType) => {
|
||||
render(<WebLink href={href}>Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
fireEvent.pointerDown(link, { pointerType, button: 2 });
|
||||
expect(fireEvent.contextMenu(link)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([{ key: "ContextMenu" }, { key: "F10", shiftKey: true }])(
|
||||
"leaves the $key keyboard menu to the browser", (event) => {
|
||||
render(<WebLink href={href}>Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
link.focus();
|
||||
expect(fireEvent.keyDown(link, event)).toBe(true);
|
||||
expect(link).toHaveFocus();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([{}, { ctrlKey: true }, { metaKey: true }, { shiftKey: true }])(
|
||||
"preserves native navigation for click modifiers %j", (modifiers) => {
|
||||
render(<WebLink href={href}>Example</WebLink>);
|
||||
expect(fireEvent.click(screen.getByRole("link", { name: "Example" }), modifiers)).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["http://127.1:4173/page?q=one#two", "/api/media/report.pdf", "./notes.html", "mailto:test@example.com", "tel:+1234567", "#section"])(
|
||||
"preserves supported link %s", (value) => {
|
||||
render(<WebLink href={value}>Example</WebLink>);
|
||||
expect(screen.getByRole("link", { name: "Example" })).toHaveAttribute("href", value);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["javascript:alert(1)", "data:text/html,hello", "file:///etc/passwd", "https://user:password@example.com/", "https://example.com/\n", "https:\\example.com", "https://example.com/" + "x".repeat(8192)])(
|
||||
"keeps unsafe or malformed addresses as text (%#)", (value) => {
|
||||
render(<WebLink href={value}>Example</WebLink>);
|
||||
expect(screen.getByText("Example")).toBeVisible();
|
||||
expect(screen.queryByRole("link")).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1,239 +0,0 @@
|
||||
// @vitest-environment-options {"settings":{"disableIframePageLoading":true}}
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { WebLink, WebPreviewContext } from "@/components/WebLink";
|
||||
import { WebPreviewPanel } from "@/components/WebPreviewPanel";
|
||||
import { FilePreviewStore, useFilePreviewState } from "@/hooks/useFilePreviewState";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { isNativeRuntime } from "@/lib/runtime";
|
||||
import { parseWebLink, webPreviewRestriction } from "@/lib/web-preview";
|
||||
|
||||
vi.mock("@/lib/runtime", () => ({ isNativeRuntime: vi.fn(() => false) }));
|
||||
vi.mock("@/lib/clipboard", () => ({ copyTextToClipboard: vi.fn(async () => true) }));
|
||||
const credentialless = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "credentialless");
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(isNativeRuntime).mockReturnValue(false);
|
||||
vi.mocked(copyTextToClipboard).mockResolvedValue(true);
|
||||
Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", { configurable: true, value: false });
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
if (credentialless) Object.defineProperty(HTMLIFrameElement.prototype, "credentialless", credentialless);
|
||||
else Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
});
|
||||
|
||||
describe("web preview boundaries", () => {
|
||||
it.each(["javascript:alert(1)", "data:text/html,hello", "file:///etc/passwd", "https://user:password@example.com/", "https://example.com/\n", "https:\\example.com", "/api/settings", "https://example.com/" + "x".repeat(8192)])("rejects %s", (url) => {
|
||||
expect(parseWebLink(url)).toBeNull();
|
||||
});
|
||||
it("keeps URL query/hash and accepts loopback without treating it as a server-side fetch", () => {
|
||||
expect(parseWebLink("http://127.1:4173/page?q=one#two")?.href).toBe("http://127.0.0.1:4173/page?q=one#two");
|
||||
});
|
||||
it("gates native, unsupported, same-origin and mixed-content embeds", () => {
|
||||
const page = new URL("https://nanobot.example");
|
||||
const external = new URL("https://example.com");
|
||||
expect(webPreviewRestriction(external, page, true, true)).toBe("native");
|
||||
expect(webPreviewRestriction(external, page, false, false)).toBe("unsupported");
|
||||
expect(webPreviewRestriction(page, page, false, true)).toBe("sameOrigin");
|
||||
expect(webPreviewRestriction(new URL("http://example.com"), page, false, true)).toBe("mixedContent");
|
||||
expect(webPreviewRestriction(external, page, false, true)).toBeNull();
|
||||
});
|
||||
it("embeds only on mount, without credentials/referrer/host permissions, and refreshes with a new frame", async () => {
|
||||
const { container } = render(<WebPreviewPanel url="https://example.com/demo" />);
|
||||
const frame = container.querySelector("iframe")!;
|
||||
expect(frame).toHaveAttribute("src", "https://example.com/demo");
|
||||
expect(frame).toHaveAttribute("sandbox", "allow-scripts");
|
||||
expect(frame).toHaveAttribute("credentialless", "");
|
||||
expect(frame).toHaveAttribute("referrerpolicy", "no-referrer");
|
||||
expect(frame.getAttribute("allow")).toContain("clipboard-read 'none'");
|
||||
// A frame load event is not evidence that CSP/X-Frame-Options allowed embedding.
|
||||
fireEvent.load(frame);
|
||||
expect(screen.queryByText(/Some sites block embedding/)).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "About website previews" }));
|
||||
expect(await screen.findByText(/Some sites block embedding/)).toBeInTheDocument();
|
||||
await userEvent.setup().keyboard("{Escape}");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Refresh website" }));
|
||||
expect(container.querySelector("iframe")).not.toBe(frame);
|
||||
expect(screen.getByRole("link", { name: "Open in browser" })).toHaveAttribute("rel", "noreferrer noopener");
|
||||
});
|
||||
it("does not load an iframe in native or unsupported browsers", () => {
|
||||
vi.mocked(isNativeRuntime).mockReturnValue(true);
|
||||
const { container, rerender } = render(<WebPreviewPanel url="https://example.com" />);
|
||||
expect(container.querySelector("iframe")).toBeNull();
|
||||
expect(screen.getByRole("status")).toHaveTextContent(/native host/);
|
||||
vi.mocked(isNativeRuntime).mockReturnValue(false);
|
||||
Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
rerender(<WebPreviewPanel url="https://example.com" />);
|
||||
expect(container.querySelector("iframe")).toBeNull();
|
||||
expect(screen.getByRole("status")).toHaveTextContent(/does not support/);
|
||||
});
|
||||
it("explains that loopback belongs to the browsing device on request", async () => {
|
||||
render(<WebPreviewPanel url="http://127.0.0.1:4173" />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "About website previews" }));
|
||||
expect(await screen.findByText(/not a remote gateway/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("web link actions", () => {
|
||||
it("keeps the primary link without a persistent action button or extra tab stop", () => {
|
||||
render(<WebLink href="https://example.com/">Long website title</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Long website title" });
|
||||
expect(link).toHaveAttribute("href", "https://example.com/");
|
||||
expect(link).toHaveAttribute("target", "_blank");
|
||||
expect(link).toHaveAttribute("rel", "noreferrer noopener");
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
expect(fireEvent.click(link)).toBe(true);
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
});
|
||||
it("opens a shared right-click menu without loading any website beforehand", async () => {
|
||||
const open = vi.fn();
|
||||
const { container } = render(<WebPreviewContext.Provider value={open}><WebLink href="https://example.com/?a=b#c">Example</WebLink></WebPreviewContext.Provider>);
|
||||
expect(container.querySelector("iframe")).toBeNull();
|
||||
fireEvent.contextMenu(screen.getByRole("link", { name: "Example" }));
|
||||
expect(screen.getAllByRole("menuitem")).toHaveLength(3);
|
||||
expect(screen.queryByText("example.com")).not.toBeInTheDocument();
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Preview website" }));
|
||||
expect(open).toHaveBeenCalledWith("https://example.com/?a=b#c");
|
||||
});
|
||||
it("supports keyboard menus and reports copy success or failure", async () => {
|
||||
render(<WebLink href="https://example.com/?q=one#two">Example</WebLink>);
|
||||
fireEvent.keyDown(screen.getByRole("link", { name: "Example" }), { key: "F10", shiftKey: true });
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Copy link" }));
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("Link copied"));
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("link", { name: "Example" })).toHaveFocus();
|
||||
expect(copyTextToClipboard).toHaveBeenCalledWith("https://example.com/?q=one#two");
|
||||
expect(screen.queryByRole("menuitem", { name: "Preview website" })).not.toBeInTheDocument();
|
||||
vi.mocked(copyTextToClipboard).mockResolvedValue(false);
|
||||
fireEvent.keyDown(screen.getByRole("link", { name: "Example" }), { key: "ContextMenu" });
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Copy link" }));
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("Could not copy link"));
|
||||
expect(screen.getByRole("menu")).toBeInTheDocument();
|
||||
vi.mocked(copyTextToClipboard).mockResolvedValue(true);
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Copy link" }));
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
});
|
||||
it.each(["unsupported", "native", "sameOrigin"])("omits unusable preview actions for %s links while keeping external open and copy", async (reason) => {
|
||||
if (reason === "unsupported") Reflect.deleteProperty(HTMLIFrameElement.prototype, "credentialless");
|
||||
if (reason === "native") vi.mocked(isNativeRuntime).mockReturnValue(true);
|
||||
const href = reason === "sameOrigin" ? `${window.location.origin}/settings` : "https://example.com/demo";
|
||||
const open = vi.fn();
|
||||
render(<WebPreviewContext.Provider value={open}><WebLink href={href}>Example</WebLink></WebPreviewContext.Provider>);
|
||||
fireEvent.contextMenu(screen.getByRole("link", { name: "Example" }));
|
||||
expect(screen.queryByRole("menuitem", { name: "Preview website" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("menuitem", { name: "Open in browser" })).toHaveAttribute("href", href);
|
||||
const explanation = reason === "unsupported" ? /does not support credential-isolated/ : reason === "native" ? /native host/ : /application itself cannot be embedded/;
|
||||
expect(screen.getByText(explanation)).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Copy link" }));
|
||||
await waitFor(() => expect(copyTextToClipboard).toHaveBeenLastCalledWith(href));
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
});
|
||||
it("ignores a late copy completion after the user reopens the menu", async () => {
|
||||
let finish!: (result: boolean) => void;
|
||||
vi.mocked(copyTextToClipboard).mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
|
||||
render(<WebLink href="https://example.com/">Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
fireEvent.contextMenu(link);
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Copy link" }));
|
||||
await userEvent.setup().keyboard("{Escape}");
|
||||
fireEvent.contextMenu(link);
|
||||
await act(async () => finish(true));
|
||||
expect(screen.getByRole("menu")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
});
|
||||
it("closes with Escape and restores focus, without stealing an outside click", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<><WebLink href="https://example.com/">Example</WebLink><button>Elsewhere</button></>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
fireEvent.keyDown(link, { key: "F10", shiftKey: true });
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(link).toHaveFocus());
|
||||
fireEvent.contextMenu(link);
|
||||
// Radix's modal menu disables hit testing on underlying controls. A real
|
||||
// outside pointer first dismisses the menu rather than activating that control.
|
||||
// Its document listener is deferred until the opening pointer event finishes.
|
||||
await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)); });
|
||||
fireEvent.pointerDown(document.body, { pointerType: "mouse", button: 0 });
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(link).not.toHaveFocus();
|
||||
});
|
||||
it("leaves touch holds, native context menus and subsequent taps to the browser", async () => {
|
||||
vi.useFakeTimers();
|
||||
const onClick = vi.fn();
|
||||
render(<WebLink href="https://example.com/" onClick={onClick}>Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
fireEvent.pointerDown(link, { pointerId: 1, pointerType: "touch", isPrimary: true, button: 0, clientX: 100, clientY: 150 });
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(fireEvent.contextMenu(link)).toBe(true);
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(link.className).not.toContain("touch-callout");
|
||||
fireEvent.pointerUp(link, { pointerId: 1, pointerType: "touch" });
|
||||
expect(fireEvent.click(link)).toBe(true);
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it("still supports a mouse and keyboard after touch on a hybrid device", () => {
|
||||
render(<WebLink href="https://example.com/">Example</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Example" });
|
||||
fireEvent.pointerDown(link, { pointerType: "touch" });
|
||||
fireEvent.pointerDown(link, { pointerType: "mouse", button: 2 });
|
||||
expect(fireEvent.contextMenu(link)).toBe(false);
|
||||
expect(screen.getByRole("menu")).toBeInTheDocument();
|
||||
fireEvent.keyDown(screen.getByRole("menu"), { key: "Escape" });
|
||||
fireEvent.pointerDown(link, { pointerType: "touch" });
|
||||
fireEvent.keyDown(link, { key: "F10", shiftKey: true });
|
||||
expect(screen.getByRole("menu")).toBeInTheDocument();
|
||||
});
|
||||
it("leaves a coarse-pointer context menu native even without a preceding pointer event", () => {
|
||||
const original = window.matchMedia;
|
||||
const media = vi.spyOn(window, "matchMedia").mockImplementation(query => ({ ...original(query), matches: query === "(pointer: coarse)" }));
|
||||
render(<WebLink href="https://example.com/">Example</WebLink>);
|
||||
expect(fireEvent.contextMenu(screen.getByRole("link", { name: "Example" }))).toBe(true);
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
media.mockRestore();
|
||||
});
|
||||
it("discards an open menu when its URL changes", () => {
|
||||
const view = (href: string) => <WebLink href={href}>Example</WebLink>;
|
||||
const { rerender } = render(view("https://example.com/old"));
|
||||
fireEvent.contextMenu(screen.getByRole("link", { name: "Example" }));
|
||||
expect(screen.getByRole("menu")).toBeInTheDocument();
|
||||
rerender(view("https://example.com/third"));
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
});
|
||||
it("does not add web actions for mail, files or executable addresses", () => {
|
||||
render(<><WebLink href="mailto:test@example.com">Mail</WebLink><WebLink href="javascript:alert(1)">Unsafe</WebLink><WebLink href="file:///notes">File</WebLink></>);
|
||||
expect(screen.getByRole("link", { name: "Mail" })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("link", { name: "Unsafe" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps file and website tabs per session, clears them on deletion, and never persists URLs", () => {
|
||||
const store = new FilePreviewStore();
|
||||
const local = vi.spyOn(Storage.prototype, "setItem");
|
||||
function View({ session }: { session: string }) {
|
||||
const { state, openWeb, openFile } = useFilePreviewState(session, store);
|
||||
return <><output>{state.tabs.find((tab) => tab.id === state.activeId)?.value ?? "closed"}</output><button onClick={() => openWeb("https://example.com/preview")}>Web</button><button onClick={() => openFile("notes.txt")}>File</button></>;
|
||||
}
|
||||
const { rerender } = render(<View session="a" />);
|
||||
fireEvent.click(screen.getByText("Web"));
|
||||
rerender(<View session="b" />);
|
||||
expect(screen.getByRole("status")).toHaveTextContent("closed");
|
||||
fireEvent.click(screen.getByText("File"));
|
||||
rerender(<View session="a" />);
|
||||
expect(screen.getByRole("status")).toHaveTextContent("https://example.com/preview");
|
||||
fireEvent.click(screen.getByText("File"));
|
||||
expect(store.get("a").activeId).toBe("file:notes.txt");
|
||||
expect(store.get("a").tabs).toHaveLength(2);
|
||||
fireEvent.click(screen.getByText("Web"));
|
||||
expect(store.get("a").activeId).toBe("web:https://example.com/preview");
|
||||
expect(store.get("a").tabs).toHaveLength(2);
|
||||
act(() => store.delete("a"));
|
||||
expect(screen.getByRole("status")).toHaveTextContent("closed");
|
||||
act(() => store.clear());
|
||||
expect(store.get("b").tabs).toEqual([]);
|
||||
expect(local).not.toHaveBeenCalled();
|
||||
});
|
||||
Reference in new issue
Block a user