diff --git a/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__mocks__/MolecularAnalysisRunViewMocks.ts b/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__mocks__/MolecularAnalysisRunViewMocks.ts new file mode 100644 index 000000000..3d3f7dc59 --- /dev/null +++ b/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__mocks__/MolecularAnalysisRunViewMocks.ts @@ -0,0 +1,34 @@ +import { PersistedResource } from "kitsu"; +import { MolecularAnalysisRun } from "../../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRun"; +import { Metadata } from "../../../../types/objectstore-api"; + +export const TEST_MOLECULAR_ANALYSIS_RUN_ID = + "b4c78082-61a8-4784-a116-8601f76c85d7"; + +export const TEST_MOLECULAR_ANALYSIS_RUN: PersistedResource = + { + id: TEST_MOLECULAR_ANALYSIS_RUN_ID, + type: "molecular-analysis-run", + name: "Run Name 1", + attachments: [ + { + id: "7f3eccfa-3bc1-412f-9385-bb00e2319ac6", + type: "metadata" + } + ] + }; + +export const TEST_METADATA: PersistedResource = { + id: "7f3eccfa-3bc1-412f-9385-bb00e2319ac6", + type: "metadata", + createdOn: "2024-12-03T14:56:51.439016Z", + bucket: "aafc", + fileIdentifier: "01938d06-12e5-793c-aecf-cadc6b18d6c2", + fileExtension: ".jpg", + dcFormat: "image/jpeg", + dcType: "IMAGE", + acCaption: "japan.jpg", + originalFilename: "japan.jpg", + publiclyReleasable: true, + group: "aafc" +}; diff --git a/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__tests__/view.test.tsx b/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__tests__/view.test.tsx index 58364c81d..8297072ce 100644 --- a/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__tests__/view.test.tsx +++ b/packages/dina-ui/page-tests/seqdb/molecular-analysis-run/__tests__/view.test.tsx @@ -1,11 +1,55 @@ import { mountWithAppContext } from "common-ui"; import MolecularAnalysisRunViewPage from "../../../../pages/seqdb/molecular-analysis-run/view"; import "@testing-library/jest-dom"; +import { waitForElementToBeRemoved } from "@testing-library/react"; +import { + TEST_METADATA, + TEST_MOLECULAR_ANALYSIS_RUN, + TEST_MOLECULAR_ANALYSIS_RUN_ID +} from "../__mocks__/MolecularAnalysisRunViewMocks"; -const apiContext: any = { apiClient: {} }; +const mockGet = jest.fn(async (path) => { + switch (path) { + // Molecular Analysis Run + case "seqdb-api/molecular-analysis-run/" + TEST_MOLECULAR_ANALYSIS_RUN_ID: + return { data: TEST_MOLECULAR_ANALYSIS_RUN }; + + // Attachments + case "objectstore-api/metadata": + case "seqdb-api/molecular-analysis-run/" + + TEST_MOLECULAR_ANALYSIS_RUN_ID + + "/attachments": + return { + data: [TEST_METADATA] + }; + + // Blob storage + case "": + return {}; + + default: + return { data: [] }; + } +}); + +const mockBulkGet = jest.fn(async (paths) => { + return paths.map((path: string) => { + switch (path) { + // Attachments + case "metadata/7f3eccfa-3bc1-412f-9385-bb00e2319ac6?include=derivatives": + case "metadata/7f3eccfa-3bc1-412f-9385-bb00e2319ac6?include=acMetadataCreator,derivatives": + return TEST_METADATA; + } + }); +}); + +const apiContext: any = { + apiClient: { get: mockGet }, + bulkGet: mockBulkGet +}; jest.mock("next/router", () => ({ - useRouter: () => ({ query: { id: "100" } }), + useRouter: () => ({ query: { id: "b4c78082-61a8-4784-a116-8601f76c85d7" } }), withRouter: (fn) => fn })); @@ -19,15 +63,20 @@ describe("Molecular Analysis Run View", () => { expect(wrapper.getByText(/loading\.\.\./i)); }); - // it("Render the molecular analysis run details for generic molecular analysis", async () => { - // const wrapper = mountWithAppContext(, { - // apiContext - // }); + it("Renders the molecular analysis run details for generic molecular analysis", async () => { + const wrapper = mountWithAppContext(, { + apiContext + }); + await waitForElementToBeRemoved(wrapper.getByText(/loading\.\.\./i)); - // // Wait for the page to load. - // await new Promise(setImmediate); + // Ensure the title is displayed of the run. + expect(wrapper.getAllByText(/run name 1/i)[0]).toBeInTheDocument(); - // // Expect loading spinner to not be in the UI - // expect(wrapper.queryByText(/loading\.\.\./i)).not.toBeInTheDocument(); - // }); + // Ensure attachment appears. + expect( + wrapper.getByRole("heading", { + name: /sequencing run attachments \(1\)/i + }) + ).toBeInTheDocument(); + }); });