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
64 changes: 0 additions & 64 deletions src/components/chunks-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,70 +63,6 @@ describe("ChunksPanel", () => {
expect(screen.getByText(/Showing all parsed chunks from/)).toBeTruthy();
});

it("searches loaded chunks and jumps between matching chunks", async () => {
mockVisibleVirtualViewport();
const user = userEvent.setup();
const { container } = render(
React.createElement(C, {
chunks: [
{
chunkId: "chunk_1",
type: "text",
content: "Revenue increased.",
sourceTitle: "report.pdf",
pageNums: [1],
},
{
chunkId: "chunk_2",
type: "text",
content: "Operating margin improved.",
sourceTitle: "report.pdf",
pageNums: [2],
},
{
chunkId: "chunk_3",
type: "image",
content: "",
summary: "Margin bridge chart.",
keywords: ["gross margin"],
sourceTitle: "report.pdf",
pageNums: [3],
},
],
selectedSource: "report.pdf",
}),
);

await user.type(
screen.getByRole("searchbox", { name: "Search parsed chunks" }),
"margin",
);

expect(screen.getByText("1/2 chunks · 3 hits")).toBeTruthy();
await waitFor(() => {
expect(
container.querySelector(
'[data-chunk-id="chunk_2"][data-focused-chunk="true"]',
),
).toBeTruthy();
});
expect(
container.querySelectorAll('mark[data-chunk-search-match="true"]').length,
).toBeGreaterThan(0);

await user.click(
screen.getByRole("button", { name: "Next chunk search match" }),
);

await waitFor(() => {
expect(
container.querySelector(
'[data-chunk-id="chunk_3"][data-focused-chunk="true"]',
),
).toBeTruthy();
});
});

it("shows a large upload target when no document is selected", async () => {
const user = userEvent.setup();

Expand Down
2 changes: 1 addition & 1 deletion src/components/workspace-shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ describe("WorkspaceShell", () => {
);
await waitFor(() => {
expect(
countFetchesWithSearch(fetch, "/api/sources/source_1/chunks", "?page=1&pageSize=100"),
countFetchesWithSearch(fetch, "/api/sources/source_1/chunks", "?page=1&pageSize=50"),
).toBeGreaterThan(0);
});

Expand Down
6 changes: 3 additions & 3 deletions src/domains/chat/route-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ describe("chat route services", () => {
generateRetrievalQuery: mocks.generateContextualRetrievalQuery,
generateAnswer: mocks.generateGroundedAnswer,
repository: expect.objectContaining({
appendMessageToThread: mocks.appendMessageToThread,
ensureDefaultChatThread: mocks.ensureDefaultChatThread,
findChatThreadInWorkspace: mocks.findChatThreadInWorkspace,
appendMessageToThread: expect.any(Function),
ensureDefaultChatThread: expect.any(Function),
findChatThreadInWorkspace: expect.any(Function),
listMessagesForThread: expect.any(Function),
}),
}),
Expand Down
7 changes: 4 additions & 3 deletions src/domains/sources/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function makeSource(overrides: Partial<Source>): Source {

async function loadReconcile({
listSourcesForWorkspace,
markSourceFailed = vi.fn(),
markSourceReady = vi.fn(),
saveSourceParseResult = vi.fn(),
markSourceFailed = vi.fn().mockResolvedValue(undefined),
markSourceReady = vi.fn().mockResolvedValue(undefined),
saveSourceParseResult = vi.fn().mockResolvedValue(undefined),
storeParsedResultAssets = vi.fn().mockResolvedValue({
resultBlobUrl: "https://blob.example/result.zip",
assetUrlsByFilePath: {},
Expand Down Expand Up @@ -247,6 +247,7 @@ describe("reconcileSourcesForWorkspace", () => {
workspace.id,
"source_1",
"Parser rejected this document.",
"parsing",
)
})

Expand Down
74 changes: 36 additions & 38 deletions src/domains/workspace/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
import { beforeEach, describe, expect, it, vi } from "vitest"

const { mockRouteClient } = vi.hoisted(() => ({
mockRouteClient: {
getJson: vi.fn(),
postJsonWithStatus: vi.fn(),
postJson: vi.fn(),
patchJson: vi.fn(),
deleteJson: vi.fn(),
},
}))

vi.mock("./route-client", () => ({
workspaceRouteClient: mockRouteClient,
}))

import { workspaceClient } from "./client"

describe("workspaceClient", () => {
beforeEach(() => {
vi.unstubAllGlobals()
vi.clearAllMocks()
})

it("fetches a normalized chunk page with an encoded source id", async () => {
const fetch = vi.fn<typeof globalThis.fetch>(async (input) => {
const requestUrl = new URL(String(input), "http://localhost")

expect(requestUrl.pathname).toBe("/api/sources/source%20one/chunks")
expect(requestUrl.searchParams.get("page")).toBe("2")
expect(requestUrl.searchParams.get("pageSize")).toBe("100")

return Response.json({
chunks: [
{
chunkId: "chunk_1",
type: "text",
content: "Chunk body",
sourceTitle: "source one",
},
],
pagination: {
page: 2,
pageSize: 100,
total: 3,
totalPages: 3,
mockRouteClient.getJson.mockResolvedValue({
chunks: [
{
chunkId: "chunk_1",
type: "text",
content: "Chunk body",
sourceTitle: "source one",
},
})
],
pagination: {
page: 2,
pageSize: 50,
total: 3,
totalPages: 3,
},
})
vi.stubGlobal("fetch", fetch)

const page = await workspaceClient.fetchChunkPage("source one", 2)

expect(mockRouteClient.getJson).toHaveBeenCalledWith(
"/api/sources/source%20one/chunks?page=2&pageSize=50",
)
expect(page).toEqual({
chunks: [
{
Expand All @@ -47,28 +55,18 @@ describe("workspaceClient", () => {
],
pagination: {
page: 2,
pageSize: 100,
pageSize: 50,
total: 3,
totalPages: 3,
},
})
expect(fetch).toHaveBeenCalledOnce()
})

it("throws materialization route errors instead of treating them as empty sources", async () => {
const fetch = vi.fn<typeof globalThis.fetch>(async (input, init) => {
const request = input instanceof Request ? input : new Request(input, init)
const requestUrl = new URL(request.url)

expect(request.method).toBe("POST")
expect(requestUrl.pathname).toBe("/api/demo-sources/materialize")

return Response.json(
{ message: "Demo sources could not be prepared right now." },
{ status: 502 },
)
mockRouteClient.postJsonWithStatus.mockResolvedValue({
status: 502,
body: { message: "Demo sources could not be prepared right now." },
})
vi.stubGlobal("fetch", fetch)

await expect(
workspaceClient.materializeDemoSources({
Expand Down
Loading