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

Commit

Permalink
add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Nov 30, 2023
1 parent 0567fb6 commit 8e8da90
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/routes/qdm/TestCaseRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const TestCaseRoutes = () => {
const [importWarnings, setImportWarnings] = useState<TestCaseImportOutcome[]>(
[]
);

const [executionContextReady, setExecutionContextReady] =
useState<boolean>(true);
const [executing, setExecuting] = useState<boolean>();
Expand Down Expand Up @@ -111,7 +112,10 @@ const TestCaseRoutes = () => {
/>
)}
{importWarnings && importWarnings.length > 0 && (
<StatusHandler importWarnings={importWarnings} />
<StatusHandler
importWarnings={importWarnings}
testDataId="import-warning-messages"
/>
)}
<Routes>
<Route path="/measures/:measureId/edit/test-cases">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const TestCaseImportFromBonnieDialogQDM = ({ open, handleClose, onImport }) => {
</div>
);
};

return (
<Dialog
open={open}
Expand All @@ -159,7 +158,12 @@ const TestCaseImportFromBonnieDialogQDM = ({ open, handleClose, onImport }) => {
fullWidth={true}
maxWidth="md"
>
<DialogTitle id="responsive-dialog-title">Test Case Import</DialogTitle>
<DialogTitle
id="responsive-dialog-title"
data-testid="responsive-dialog-title"
>
Test Case Import
</DialogTitle>
<DialogContent>
<DialogContent>
<Alert severity="warning" style={{ marginBottom: 10 }}>
Expand Down
112 changes: 112 additions & 0 deletions src/components/testCaseLanding/qdm/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
PopulationType,
TestCase,
AggregateFunctionType,
TestCaseImportOutcome,
} from "@madie/madie-models";
import useTestCaseServiceApi, {
TestCaseServiceApi,
Expand All @@ -38,11 +39,18 @@ import { buildMeasureBundle } from "../../../util/CalculationTestHelpers";
import { QdmExecutionContextProvider } from "../../routes/qdm/QdmExecutionContext";
import { checkUserCanEdit, useFeatureFlags } from "@madie/madie-util";
import { CqmConversionService } from "../../../api/CqmModelConversionService";
import { ScanValidationDto } from "../../../api/models/ScanValidationDto";
import { ValueSet } from "cqm-models";
import qdmCalculationService, {
QdmCalculationService,
} from "../../../api/QdmCalculationService";

const mockScanResult: ScanValidationDto = {
fileName: "testcaseExample.json",
valid: true,
error: null,
};

const serviceConfig: ServiceConfig = {
elmTranslationService: { baseUrl: "translator.url" },
testCaseService: {
Expand Down Expand Up @@ -1162,6 +1170,110 @@ describe("TestCaseList component", () => {
expect(nextState).toEqual([IMPORT_ERROR]);
});

it("should display warning messages when importTestCasesQDM call succeeds with warnings", async () => {
(checkUserCanEdit as jest.Mock).mockClear().mockImplementation(() => true);
(useFeatureFlags as jest.Mock).mockClear().mockImplementation(() => ({
importTestCases: true,
}));

const useTestCaseServiceMockRejected = {
getTestCasesByMeasureId: jest.fn().mockResolvedValue(testCases),
getTestCaseSeriesForMeasure: jest
.fn()
.mockResolvedValue(["Series 1", "Series 2"]),
importTestCasesQDM: jest.fn().mockResolvedValue({
data: [
{
message:
"The measure populations do not match the populations in the import file. The Test Case has been imported, but no expected values have been set.",
patientId: "testid1",
successful: true,
},
{
message:
"The measure populations do not match the populations in the import file. The Test Case has been imported, but no expected values have been set.",
patientId: "testid2",
successful: true,
},
],
}),
} as unknown as TestCaseServiceApi;

useTestCaseServiceMock.mockImplementation(() => {
return useTestCaseServiceMockRejected;
});

let nextState;
setError.mockImplementation((callback) => {
nextState = callback([]);
});

renderTestCaseListComponent();
const showImportBtn = await screen.findByRole("button", {
name: /import test cases/i,
});
await waitFor(() => expect(showImportBtn).not.toBeDisabled());
userEvent.click(showImportBtn);
const importDialog = await screen.findByTestId("test-case-import-dialog");
expect(importDialog).toBeInTheDocument();

await waitFor(async () => {
const importBtn = within(importDialog).getByRole("button", {
name: "Import",
});
expect(importBtn).toBeEnabled();
userEvent.click(importBtn);
expect(setWarnings).toHaveBeenCalled();
});
});

it("should display success message when importTestCasesQDM call succeeds without", async () => {
(checkUserCanEdit as jest.Mock).mockClear().mockImplementation(() => true);
(useFeatureFlags as jest.Mock).mockClear().mockImplementation(() => ({
importTestCases: true,
}));

const useTestCaseServiceMockRejected = {
getTestCasesByMeasureId: jest.fn().mockResolvedValue(testCases),
getTestCaseSeriesForMeasure: jest
.fn()
.mockResolvedValue(["Series 1", "Series 2"]),
importTestCasesQDM: jest.fn().mockResolvedValue({
data: [
{ patientId: "testid1", successful: true },
{ patientId: "testid2", successful: true },
],
}),
} as unknown as TestCaseServiceApi;

useTestCaseServiceMock.mockImplementation(() => {
return useTestCaseServiceMockRejected;
});

let nextState;
setError.mockImplementation((callback) => {
nextState = callback([]);
});

renderTestCaseListComponent();
const showImportBtn = await screen.findByRole("button", {
name: /import test cases/i,
});
await waitFor(() => expect(showImportBtn).not.toBeDisabled());
userEvent.click(showImportBtn);
const importDialog = await screen.findByTestId("test-case-import-dialog");
expect(importDialog).toBeInTheDocument();

await waitFor(async () => {
const importBtn = within(importDialog).getByRole("button", {
name: "Import",
});
expect(importBtn).toBeEnabled();
userEvent.click(importBtn);
expect(screen.getByText("(2) Test cases imported successfully"));
});
});

it("should close import dialog when cancel button is clicked", async () => {
(checkUserCanEdit as jest.Mock).mockClear().mockImplementation(() => true);
(useFeatureFlags as jest.Mock).mockClear().mockImplementation(() => ({
Expand Down

0 comments on commit 8e8da90

Please sign in to comment.