-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): correctly display document information in explore view…
… details (#781) * stringify json values and render within pre tags so react can render them * run prettier * add tests for first document * prettier * return 'Not Available' instead of 'null' string * don't render objects in document details; add tests * remove newlines from imports
- Loading branch information
Showing
2 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
frontend/app/explore/DocumentItem/__tests__/DocumentData.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { BrainConfigProvider } from "@/lib/context/BrainConfigProvider"; | ||
import DocumentData from "../DocumentData"; | ||
|
||
const useSupabaseMock = vi.fn(() => ({ | ||
session: { user: {} }, | ||
})); | ||
|
||
vi.mock("@/lib/context/SupabaseProvider", () => ({ | ||
useSupabase: () => useSupabaseMock(), | ||
})); | ||
|
||
vi.mock("@/lib/hooks", async () => { | ||
const actual = await vi.importActual<typeof import("@/lib/hooks")>( | ||
"@/lib/hooks" | ||
); | ||
|
||
return { | ||
...actual, | ||
useAxios: () => ({ | ||
axiosInstance: { | ||
get: vi.fn().mockResolvedValue({ | ||
data: { | ||
documents: [ | ||
{ | ||
file_name: "mock_file_name.pdf", | ||
file_size: "0", | ||
file_extension: null, | ||
file_url: null, | ||
content: "foo,bar\nbaz,bat", | ||
brains_vectors: [ | ||
{ | ||
brain_id: "mock_brain_id", | ||
vector_id: "mock_vector_id_1", | ||
}, | ||
], | ||
}, | ||
{ | ||
file_name: "mock_file_name.pdf", | ||
file_size: "0", | ||
file_extension: null, | ||
file_url: null, | ||
content: "foo,bar\nbaz,bat", | ||
brains_vectors: [ | ||
{ | ||
brain_id: "mock_brain_id", | ||
vector_id: "mock_vector_id_2", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}), | ||
}, | ||
}), | ||
}; | ||
}); | ||
|
||
describe("DocumentData", () => { | ||
it("should render document data", async () => { | ||
const documentName = "Test document"; | ||
render( | ||
<BrainConfigProvider> | ||
<DocumentData documentName={documentName} /> | ||
</BrainConfigProvider> | ||
); | ||
|
||
expect(screen.getByText(documentName)).toBeDefined(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("content")).toBeDefined(); | ||
expect(screen.getByText("foo,bar", { exact: false })).toBeDefined(); | ||
expect(screen.getByText("baz,bat", { exact: false })).toBeDefined(); | ||
}); | ||
}); | ||
}); |