Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 76 additions & 14 deletions src/components/chunks-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ describe("ChunksPanel", () => {
expect(screen.getByText(/Showing all parsed chunks from/)).toBeTruthy();
});

it("switches parsed chunks into a section tree view", async () => {
const user = userEvent.setup();

it("defaults parsed chunks into a section tree view", () => {
render(
React.createElement(C, {
chunks: [
Expand Down Expand Up @@ -107,8 +105,6 @@ describe("ChunksPanel", () => {
}),
);

await user.click(screen.getByRole("button", { name: "Tree" }));

expect(
screen.getByRole("tree", { name: "Parsed chunk sections" }),
).toBeTruthy();
Expand Down Expand Up @@ -176,7 +172,7 @@ describe("ChunksPanel", () => {
expect(cardMinimumWidth).toBeGreaterThanOrEqual(treeWidth);
});

it("does not render section tree zoom controls over the canvas", async () => {
it("renders section tree zoom controls over the canvas", async () => {
const user = userEvent.setup();

render(
Expand All @@ -196,18 +192,65 @@ describe("ChunksPanel", () => {

await user.click(screen.getByRole("button", { name: "Tree" }));

const overlay = screen.getByTestId("chunk-section-tree-zoom-overlay");
const scrollContent = screen.getByTestId("chunks-scroll-content");

expect(overlay.className).toContain("absolute");
expect(overlay.className).toContain("left-3");
expect(overlay.className).toContain("top-3");
expect(scrollContent.contains(overlay)).toBe(false);
expect(
screen.queryByTestId("chunk-section-tree-zoom-overlay"),
).toBeNull();
screen.getByRole("group", { name: "Section tree zoom" }),
).toBeTruthy();
expect(
screen.queryByRole("group", { name: "Section tree zoom" }),
).toBeNull();
screen.getByRole("button", { name: "Zoom in section tree" }),
).toBeTruthy();
expect(
screen.queryByRole("button", { name: "Zoom in section tree" }),
).toBeNull();
screen.getByRole("button", { name: "Zoom out section tree" }),
).toBeTruthy();
expect(
screen.queryByRole("button", { name: "Zoom out section tree" }),
).toBeNull();
screen.getByRole("button", { name: "Reset section tree zoom" }),
).toBeTruthy();
});

it("resets the section tree zoom from the zoom controls", async () => {
const user = userEvent.setup();

render(
React.createElement(C, {
chunks: [
{
chunkId: "chunk_1",
type: "text",
content: "Overview text",
sectionPath: "manual.pdf/Overview/Product/Robotics",
sourceTitle: "manual.pdf",
},
],
selectedSource: "manual.pdf",
}),
);

await user.click(screen.getByRole("button", { name: "Tree" }));

const tree = screen.getByRole("tree", { name: "Parsed chunk sections" });
const resetButton = screen.getByRole("button", {
name: "Reset section tree zoom",
});

expect(resetButton.hasAttribute("disabled")).toBe(true);

await user.click(screen.getByRole("button", { name: "Zoom in section tree" }));

expect(tree.style.transform).toBe("scale(1.1)");
expect(screen.getByText("110%")).toBeTruthy();
expect(resetButton.hasAttribute("disabled")).toBe(false);

await user.click(resetButton);

expect(tree.style.transform).toBe("scale(1)");
expect(screen.getByText("100%")).toBeTruthy();
expect(resetButton.hasAttribute("disabled")).toBe(true);
});

it("allows the section tree to zoom out to 30 percent with the mouse wheel", async () => {
Expand Down Expand Up @@ -450,6 +493,7 @@ describe("ChunksPanel", () => {
},
}),
);
selectListView();

const openOriginalButton = screen.getByRole("button", {
name: "Open original file",
Expand Down Expand Up @@ -521,6 +565,7 @@ describe("ChunksPanel", () => {
},
}),
);
selectListView();

await user.click(
screen.getByRole("button", { name: "Open page 2 in original file" }),
Expand Down Expand Up @@ -562,6 +607,7 @@ describe("ChunksPanel", () => {
},
}),
);
selectListView();

await user.click(
screen.getByRole("button", { name: "Open page 2 in original file" }),
Expand Down Expand Up @@ -605,6 +651,7 @@ describe("ChunksPanel", () => {
selectedSourceFile,
}),
);
selectListView();

await user.click(screen.getByRole("button", { name: "Original" }));
expect(screen.getByRole("heading", { name: "Original File" })).toBeTruthy();
Expand Down Expand Up @@ -663,6 +710,7 @@ describe("ChunksPanel", () => {
selectedSource: "demo.pdf",
}),
);
selectListView();

expect(screen.getByTestId("chunks-scroll-content").className).toContain(
"min-w-0",
Expand Down Expand Up @@ -693,6 +741,7 @@ describe("ChunksPanel", () => {
],
}),
);
selectListView();

const sourcePanel = screen.getByTestId("chunk-source-panel-image_1");

Expand Down Expand Up @@ -727,6 +776,7 @@ describe("ChunksPanel", () => {
selectedSource: "TSLA-Q4-2025-Update.pdf",
}),
);
selectListView();

const financialSourcePanel = screen.getByTestId(
"chunk-source-panel-text_1",
Expand Down Expand Up @@ -767,6 +817,7 @@ describe("ChunksPanel", () => {
selectedSource: "TSLA-Q4-2025-UPDATE.PDF",
}),
);
selectListView();

expect(screen.getByTestId("chunk-source-panel-text_1").textContent).toContain(
"Installed Annual Capacity",
Expand Down Expand Up @@ -858,6 +909,7 @@ describe("ChunksPanel", () => {
selectedSource: "manual.pdf",
}),
);
selectListView();

const image = screen.getByRole("img", { name: "A wiring diagram." });
expect(image.getAttribute("src")).toBe(
Expand Down Expand Up @@ -917,6 +969,7 @@ describe("ChunksPanel", () => {
focusedChunkRequestId: 1,
}),
);
selectListView();

await user.click(screen.getByRole("button", { name: "Table 1" }));

Expand Down Expand Up @@ -948,6 +1001,7 @@ describe("ChunksPanel", () => {
focusedChunkRequestId: 1,
}),
);
selectListView();

await waitFor(() => {
expect(screen.getByTestId("chunk-card-shell-chunk_50")).toBeTruthy();
Expand Down Expand Up @@ -977,6 +1031,7 @@ describe("ChunksPanel", () => {
selectedSource: "large.pdf",
}),
);
selectListView();
const viewport = screen
.getByTestId("chunks-panel")
.querySelector<HTMLElement>("[data-radix-scroll-area-viewport]");
Expand Down Expand Up @@ -1039,6 +1094,7 @@ describe("ChunksPanel", () => {
selectedSource: "large.pdf",
}),
);
selectListView();

rerender(
React.createElement(C, {
Expand Down Expand Up @@ -1106,6 +1162,7 @@ describe("ChunksPanel", () => {
selectedSource: "large.pdf",
}),
);
selectListView();
const viewport = screen
.getByTestId("chunks-panel")
.querySelector<HTMLElement>("[data-radix-scroll-area-viewport]");
Expand Down Expand Up @@ -1165,6 +1222,7 @@ describe("ChunksPanel", () => {
selectedSource: "annual-report.pdf",
}),
);
selectListView();

expect(
screen.getByRole("button", {
Expand Down Expand Up @@ -1226,6 +1284,10 @@ function mockVisibleVirtualViewport(): void {
mockVirtualViewportWithChunkHeights({});
}

function selectListView(): void {
fireEvent.click(screen.getByRole("button", { name: "List" }));
}

function createFileDropEvent(file: File): Event {
const event = new Event("drop", { bubbles: true, cancelable: true });
const files: Pick<FileList, "length" | "item"> & { readonly 0: File } = {
Expand Down
Loading
Loading