Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
MAT-7667 Fixed unit test cases in TestCaseList.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitKandimalla committed Nov 6, 2024
1 parent 7f56f46 commit bccf5da
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions src/components/testCaseLanding/qiCore/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ import EditTestCase from "../../editTestCase/qiCore/EditTestCase";
const createZipFile = async (
patientIds: string[],
jsonBundle?: string[],
jsonFileName?: string[],
zipFileName = "CMS136FHIR-v0.0.000-FHIR4-TestCases"
jsonFileName?: string[]
) => {
try {
const zip = new JSZip();
Expand Down Expand Up @@ -476,11 +475,9 @@ jest.mock("../../../api/CalculationService");
const calculationServiceMock =
calculationService as jest.Mock<CalculationService>;

const mockProcessTestCaseResults = jest
.fn()
.mockImplementation((testCase, groups, results) => {
return failingTestCaseResults.find((tc) => tc.id === testCase.id);
});
const mockProcessTestCaseResults = jest.fn().mockImplementation((testCase) => {
return failingTestCaseResults.find((tc) => tc.id === testCase.id);
});
const mockGetPassingPercentageForTestCases = jest
.fn()
.mockReturnValue({ passPercentage: 50, passFailRatio: "1/2" });
Expand Down Expand Up @@ -702,9 +699,7 @@ describe("TestCaseList component", () => {
});

renderTestCaseListComponent();
expect(
await screen.queryByTestId("display-tests-error")
).not.toBeInTheDocument();
expect(screen.queryByTestId("display-tests-error")).not.toBeInTheDocument();
});

it("should render delete dialogue on Test Case list page when delete button is clicked", async () => {
Expand Down Expand Up @@ -938,7 +933,7 @@ describe("TestCaseList component", () => {
fireEvent.click(executeAllTestCasesButton);

const errorMessage = screen.queryByTestId("display-tests-error");
await expect(errorMessage).not.toBeInTheDocument();
expect(errorMessage).not.toBeInTheDocument();
});
});

Expand Down Expand Up @@ -1122,23 +1117,43 @@ describe("TestCaseList component", () => {
measureGroupTypes: [],
},
];

mockProcessTestCaseResults.mockClear().mockImplementation((testCase) => {
return {
...failingTestCaseResults.find((tc) => tc.id === testCase.id),
executionStatus: "pass",
};
});

mockGetPassingPercentageForTestCases
.mockClear()
.mockReturnValue({ passPercentage: 66, passFailRatio: "2/3" });
renderTestCaseListComponent();

// wait for pop criteria to load
await waitFor(() => {
expect(screen.getByText("Population Criteria 1")).toBeInTheDocument();
expect(
screen.getByRole("tab", { name: "Population Criteria 1" })
).toBeInTheDocument();
expect(
screen.getByRole("tab", { name: "Population Criteria 2" })
).toBeInTheDocument();
// what is N/A ?
expect(screen.getAllByText("N/A").length).toEqual(2);
});

// wait for execution context to be ready
const executeButton = screen.getByRole("button", {
const executeButton = await screen.findByRole("button", {
name: "Run Test(s)",
});

await waitFor(() => expect(executeButton).not.toBeDisabled());

userEvent.click(executeButton);
await waitFor(() => expect(screen.getByText("75%")).toBeInTheDocument());
// Coverage percentage
await waitFor(() => {
const coverageTab = screen.getByTestId("coverage-tab");
expect(coverageTab).toHaveTextContent("75%");
});
const table = await screen.findByTestId("test-case-tbl");
const tableRows = table.querySelectorAll("tbody tr");
await waitFor(() => {
Expand All @@ -1147,19 +1162,6 @@ describe("TestCaseList component", () => {
expect(tableRows[0]).toHaveTextContent("Invalid");
});

mockProcessTestCaseResults
.mockClear()
.mockImplementation((testCase, groups, results) => {
return {
...failingTestCaseResults.find((tc) => tc.id === testCase.id),
executionStatus: "pass",
};
});

mockGetPassingPercentageForTestCases
.mockClear()
.mockReturnValue({ passPercentage: 66, passFailRatio: "2/3" });

const popCriteria2 = screen.getByText("Population Criteria 2");
expect(popCriteria2).toBeInTheDocument();
userEvent.click(popCriteria2);
Expand All @@ -1174,9 +1176,8 @@ describe("TestCaseList component", () => {
expect(tableRows2[0]).toHaveTextContent("Invalid");
});

expect(screen.getByText("Passing (2/3)")).toBeInTheDocument();
expect(screen.getByText("100%")).toBeInTheDocument();
expect(screen.getByTestId("sr-div")).toBeInTheDocument();
const passingTab = await screen.findByTestId("passing-tab");
expect(passingTab).toHaveTextContent("Passing (2/3)");
});

it("should hide the button for import test cases from bonnie when feature is disabled", async () => {
Expand All @@ -1186,7 +1187,7 @@ describe("TestCaseList component", () => {
}));

renderTestCaseListComponent();
const importBtn = await screen.queryByRole("button", {
const importBtn = screen.queryByRole("button", {
name: /Import From Bonnie/i,
});
expect(importBtn).not.toBeInTheDocument();
Expand Down Expand Up @@ -1245,9 +1246,7 @@ describe("TestCaseList component", () => {
});
expect(importBtn).toBeInTheDocument();
userEvent.click(importBtn);
const removedImportDialog = await screen.queryByTestId(
"test-case-import-dialog"
);
const removedImportDialog = screen.queryByTestId("test-case-import-dialog");
expect(removedImportDialog).not.toBeInTheDocument();
expect(nextState).toEqual([]);
});
Expand Down Expand Up @@ -1287,9 +1286,7 @@ describe("TestCaseList component", () => {
name: "Import",
});
userEvent.click(importBtn);
const removedImportDialog = await screen.queryByTestId(
"test-case-import-dialog"
);
const removedImportDialog = screen.queryByTestId("test-case-import-dialog");
expect(removedImportDialog).not.toBeInTheDocument();
await waitFor(() => expect(setError).toHaveBeenCalledTimes(2));
expect(nextState).toEqual([IMPORT_ERROR]);
Expand Down Expand Up @@ -1319,9 +1316,7 @@ describe("TestCaseList component", () => {
});
expect(cancelBtn).toBeInTheDocument();
userEvent.click(cancelBtn);
const removedImportDialog = await screen.queryByTestId(
"test-case-import-dialog"
);
const removedImportDialog = screen.queryByTestId("test-case-import-dialog");
expect(removedImportDialog).not.toBeInTheDocument();
expect(setError).toHaveBeenCalled();
expect(nextState).toEqual([]);
Expand Down

0 comments on commit bccf5da

Please sign in to comment.