返回 DeepSeek-Reasonix
workspace-presented-pagination.test.tsx
根目录 / desktop / frontend / src / __tests__ / workspace-presented-pagination.test.tsx
1 import { act } from "react";
2 import { flushPromises, renderFilesWorkspace, waitFor } from "./workspace-panel-test-harness";
3 import { performResourceAction } from "../lib/fileNavigationCommands";
4
5 const pageCalls: Array<{ offset: number; version: string }> = [];
6 const { dom, root } = await renderFilesWorkspace({
7 ReadPresentedFileForTab: async (_tabId, _toolCallId, path) => ({
8 path, body: "first\n", size: 18, truncated: true, binary: false, version: "18:1", nextOffset: 6,
9 }),
10 ReadPresentedFileSourceForTab: async (_tabId, _toolCallId, path) => ({
11 path, body: "first\n", size: 18, truncated: true, binary: false, version: "18:1", nextOffset: 6,
12 }),
13 ReadPresentedTextPageForTab: async (_tabId, _toolCallId, path, offset, version) => {
14 pageCalls.push({ offset, version });
15 return { path, body: "second\nthird\n", offset, nextOffset: 18, size: 18, hasMore: false, version };
16 },
17 });
18
19 // The presented file arrives the way the transcript opens it: as a command that
20 // commits a navigation record the mounted dock reads.
21 await act(async () => {
22 await performResourceAction({
23 source: "presented", hostId: "local", tabId: "tab-a", toolCallId: "present-1", path: "/tmp/large.txt",
24 }, "preview");
25 await flushPromises();
26 });
27
28 await waitFor("presented preview", () => document.body.textContent?.includes("first") === true);
29 if (!/external files|外部文件|外部檔案/i.test(document.body.textContent ?? "")) {
30 throw new Error("an absolute presented path was not identified as an external-file scope");
31 }
32 const scopeFilter = document.querySelector<HTMLInputElement>(".workspace-search input");
33 if (!scopeFilter || !/external files|外部文件|外部檔案/i.test(scopeFilter.placeholder)) {
34 throw new Error("the external-file scope did not expose a matching filter label");
35 }
36 const loadMore = Array.from(document.querySelectorAll<HTMLButtonElement>("button"))
37 .find(button => /load more|加载更多|載入更多/i.test(button.textContent ?? ""));
38 if (!loadMore) throw new Error("presented text preview did not expose Load more");
39 await act(async () => {
40 loadMore.dispatchEvent(new window.MouseEvent("click", { bubbles: true }));
41 await flushPromises();
42 });
43 await waitFor("appended text page", () => document.body.textContent?.includes("third") === true);
44 if (pageCalls.length !== 1 || pageCalls[0]?.offset !== 6 || pageCalls[0]?.version !== "18:1") {
45 throw new Error(`pagination did not preserve offset/version: ${JSON.stringify(pageCalls)}`);
46 }
47 if (!/full file loaded|已加载全文|已載入全文/i.test(document.body.textContent ?? "")) {
48 throw new Error("completed pagination did not report the full file state");
49 }
50
51 await act(async () => root.unmount());
52 dom.window.close();
53 console.log("workspace presented text pagination passed");
54
54 lines Plain Text