From 8e8da90b494fef82407d542da0a033b4dc3f0ee4 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Thu, 30 Nov 2023 10:18:36 -0800 Subject: [PATCH] add testing --- src/components/routes/qdm/TestCaseRoutes.tsx | 6 +- .../TestCaseImportFromBonnieDialogQDM.tsx | 8 +- .../testCaseLanding/qdm/TestCaseList.test.tsx | 112 ++++++++++++++++++ 3 files changed, 123 insertions(+), 3 deletions(-) diff --git a/src/components/routes/qdm/TestCaseRoutes.tsx b/src/components/routes/qdm/TestCaseRoutes.tsx index dcf16e473..df65d38dd 100644 --- a/src/components/routes/qdm/TestCaseRoutes.tsx +++ b/src/components/routes/qdm/TestCaseRoutes.tsx @@ -17,6 +17,7 @@ const TestCaseRoutes = () => { const [importWarnings, setImportWarnings] = useState( [] ); + const [executionContextReady, setExecutionContextReady] = useState(true); const [executing, setExecuting] = useState(); @@ -111,7 +112,10 @@ const TestCaseRoutes = () => { /> )} {importWarnings && importWarnings.length > 0 && ( - + )} diff --git a/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx b/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx index 018c319f4..6afe45e76 100644 --- a/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx +++ b/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx @@ -149,7 +149,6 @@ const TestCaseImportFromBonnieDialogQDM = ({ open, handleClose, onImport }) => { ); }; - return ( { fullWidth={true} maxWidth="md" > - Test Case Import + + Test Case Import + diff --git a/src/components/testCaseLanding/qdm/TestCaseList.test.tsx b/src/components/testCaseLanding/qdm/TestCaseList.test.tsx index b2101d96b..ba72e415a 100644 --- a/src/components/testCaseLanding/qdm/TestCaseList.test.tsx +++ b/src/components/testCaseLanding/qdm/TestCaseList.test.tsx @@ -26,6 +26,7 @@ import { PopulationType, TestCase, AggregateFunctionType, + TestCaseImportOutcome, } from "@madie/madie-models"; import useTestCaseServiceApi, { TestCaseServiceApi, @@ -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: { @@ -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(() => ({