Skip to content

Commit

Permalink
Support #35538 - Molecular Analysis Run view page bug and test coverage
Browse files Browse the repository at this point in the history
- More progress on the new test, and reviewing all the code for the view hook.
  • Loading branch information
brandonandre committed Jan 14, 2025
1 parent 9d96b9c commit c609a70
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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<MolecularAnalysisRun> =
{
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<Metadata> = {
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"
};
Original file line number Diff line number Diff line change
@@ -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
}));

Expand All @@ -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(<MolecularAnalysisRunViewPage />, {
// apiContext
// });
it("Renders the molecular analysis run details for generic molecular analysis", async () => {
const wrapper = mountWithAppContext(<MolecularAnalysisRunViewPage />, {
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();
});
});

0 comments on commit c609a70

Please sign in to comment.