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

Feature/mat 7667 #756

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MAT-7667 Added useBlocker to handle user confirmation when internal n…
…avigation is triggered in madie-patient and the current form is empty
  • Loading branch information
RohitKandimalla authored and mcmcphillips committed Nov 13, 2024
commit c95e3cebb74b9ca10043cd7c950046b5c0bc7f22
13 changes: 5 additions & 8 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Suspense, useEffect, useState } from "react";
import { BrowserRouter } from "react-router-dom";
import RoutesWrapper from "./routes/RoutesWrapper";
import { ServiceConfig, ApiContextProvider } from "../api/ServiceContext";
import axios from "../api/axios-instance";
@@ -32,13 +31,11 @@ export default function Home() {
const loadingState = <div>Loading...</div>;

const loadedState = (
<BrowserRouter>
<ApiContextProvider value={serviceConfig}>
<Suspense fallback={<div>loading</div>}>
<RoutesWrapper />
</Suspense>
</ApiContextProvider>
</BrowserRouter>
<ApiContextProvider value={serviceConfig}>
<Suspense fallback={<div>loading</div>}>
<RoutesWrapper />
</Suspense>
</ApiContextProvider>
);

let result = serviceConfig === null ? loadingState : loadedState;
72 changes: 63 additions & 9 deletions src/components/routes/qdm/TestCaseRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import * as React from "react";
import { render, screen, within } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import {
createMemoryRouter,
MemoryRouter,
RouterProvider,
} from "react-router-dom";
import TestCaseRoutes from "./TestCaseRoutes";
import axios from "../../../api/axios-instance";
import { ApiContextProvider, ServiceConfig } from "../../../api/ServiceContext";
import { Model, PopulationType } from "@madie/madie-models";
import useCqmConversionService, {
CqmConversionService,
} from "../../../api/CqmModelConversionService";
import RedirectToList from "../RedirectToList";
import EditTestCase from "../../editTestCase/qdm/EditTestCase";
import TestCaseLandingWrapper from "../../testCaseLanding/common/TestCaseLandingWrapper";
import SDEPage from "../../testCaseConfiguration/sde/SDEPage";
import Expansion from "../../testCaseConfiguration/expansion/Expansion";
import TestCaseData from "../../testCaseConfiguration/testCaseData/TestCaseData";
import NotFound from "../../notfound/NotFound";

jest.mock("../../../api/axios-instance");
global.ResizeObserver = jest.fn().mockImplementation(() => ({
@@ -32,6 +43,9 @@ const serviceConfig: ServiceConfig = {
fhirElmTranslationService: {
baseUrl: "fhir-elmTranslationService.com",
},
fhirService: {
baseUrl: "fhirService.com",
},
excelExportService: {
baseUrl: "excelexport.com",
},
@@ -68,6 +82,35 @@ const mockMeasure = {
createdBy: MEASURE_CREATEDBY,
};

const routesConfig = [
{
children: [
{
path: "/measures/:measureId/edit/test-cases",
element: <RedirectToList />,
},
{
path: "/measures/:measureId/edit/test-cases/:id",
element: <EditTestCase />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page/sde",
element: <TestCaseLandingWrapper qdm children={<SDEPage />} />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page/expansion",
element: <TestCaseLandingWrapper qdm children={<Expansion />} />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page/test-case-data",
element: <TestCaseLandingWrapper qdm children={<TestCaseData />} />,
},
{ path: "/404", element: <NotFound /> },
{ path: "*", element: <NotFound /> },
],
},
];

jest.mock("@madie/madie-util", () => ({
useDocumentTitle: jest.fn(),
measureStore: {
@@ -116,6 +159,23 @@ CQMConversionMock.mockImplementation(() => {
return useCqmConversionServiceMockResolved;
});

const renderComponentViaRouter = (
initialEntries = ["/measures/m1234/edit/test-cases/list-page/sde"]
) => {
const router = createMemoryRouter(routesConfig, {
initialEntries,
});
// const router = createMemoryRouter(routesConfig, {
// initialEntries,
// });

return render(
<ApiContextProvider value={serviceConfig}>
<RouterProvider router={router} />
</ApiContextProvider>
);
};

describe("TestCaseRoutes", () => {
it("should render the test case list component", async () => {
mockedAxios.get.mockImplementation(() => {
@@ -132,14 +192,8 @@ describe("TestCaseRoutes", () => {
],
});
});
render(
<MemoryRouter initialEntries={["/measures/m1234/edit/test-cases"]}>
<ApiContextProvider value={serviceConfig}>
<TestCaseRoutes />
</ApiContextProvider>
</MemoryRouter>
);

const { debug } = renderComponentViaRouter();
debug();
const testCaseListTable = (await screen.findByTestId(
"test-case-tbl"
)) as HTMLTableElement;
84 changes: 67 additions & 17 deletions src/components/routes/qdm/TestCaseRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useEffect, useCallback, useRef, useState } from "react";
import { Route, Routes } from "react-router-dom";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import TestCaseLandingQdm from "../../testCaseLanding/qdm/TestCaseLanding";
import EditTestCase from "../../editTestCase/qdm/EditTestCase";
import NotFound from "../../notfound/NotFound";
import StatusHandler from "../../statusHandler/StatusHandler";
import { Measure, TestCaseImportOutcome } from "@madie/madie-models";
import { measureStore, useFeatureFlags } from "@madie/madie-util";
import { measureStore } from "@madie/madie-util";
import { CqmMeasure, ValueSet } from "cqm-models";
import useCqmConversionService from "../../../api/CqmModelConversionService";
import useTerminologyServiceApi from "../../../api/useTerminologyServiceApi";
@@ -23,7 +23,6 @@ const TestCaseRoutes = () => {
[]
);
const [importErrors, setImportErrors] = useState<Array<string>>([]);
const featureFlags = useFeatureFlags();
const [executionContextReady, setExecutionContextReady] =
useState<boolean>(false);
const [executing, setExecuting] = useState<boolean>();
@@ -169,6 +168,68 @@ const TestCaseRoutes = () => {
}
};

const routesConfig = [
{
children: [
{
path: "/measures/:measureId/edit/test-cases",
element: <RedirectToList />,
},
{
path: "/measures/:measureId/edit/test-cases/:id",
element: <EditTestCase />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page",
element: (
<TestCaseLandingWrapper
qdm
children={
<TestCaseLandingQdm
errors={cqmMeasureErrors}
setErrors={setCqmMeasureErrors}
setWarnings={setImportWarnings}
setImportErrors={setImportErrors}
/>
}
/>
),
},
{
path: "/measures/:measureId/edit/test-cases/list-page/:criteriaId",
element: (
<TestCaseLandingWrapper
qdm
children={
<TestCaseLandingQdm
errors={cqmMeasureErrors}
setErrors={setCqmMeasureErrors}
setWarnings={setImportWarnings}
setImportErrors={setImportErrors}
/>
}
/>
),
},
{
path: "/measures/:measureId/edit/test-cases/list-page/sde",
element: <TestCaseLandingWrapper qdm children={<SDEPage />} />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page/expansion",
element: <TestCaseLandingWrapper qdm children={<Expansion />} />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page/test-case-data",
element: <TestCaseLandingWrapper qdm children={<TestCaseData />} />,
},
{ path: "/404", element: <NotFound /> },
{ path: "*", element: <NotFound /> },
],
},
];

const router = createBrowserRouter(routesConfig);
return (
<QdmExecutionContextProvider
value={{
@@ -201,7 +262,7 @@ const TestCaseRoutes = () => {
testDataId="import-warning-messages"
/>
)}
<Routes>
{/* <Routes>
<Route path="/measures/:measureId/edit/test-cases/list-page">
<Route
path="/measures/:measureId/edit/test-cases/list-page/sde"
@@ -247,20 +308,9 @@ const TestCaseRoutes = () => {
/>
}
/>
</Route>

<Route
path="/measures/:measureId/edit/test-cases"
element={<RedirectToList />}
/>

<Route path="/measures/:measureId/edit/test-cases/:id">
<Route index element={<EditTestCase />} />
<Route path=":id" index element={<EditTestCase />} />
</Route>
</Route> */}

<Route path="*" element={<NotFound />} />
</Routes>
<RouterProvider router={router} />
</QdmExecutionContextProvider>
);
};
65 changes: 60 additions & 5 deletions src/components/routes/qiCore/TestCaseRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useRef, useState } from "react";
import { Route, Routes } from "react-router-dom";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import TestCaseLanding from "../../testCaseLanding/qiCore/TestCaseLanding";
import EditTestCase from "../../editTestCase/qiCore/EditTestCase";
import NotFound from "../../notfound/NotFound";
import { measureStore, useFeatureFlags } from "@madie/madie-util";
import { measureStore } from "@madie/madie-util";
import { Bundle, ValueSet } from "fhir/r4";
import useTerminologyServiceApi from "../../../api/useTerminologyServiceApi";
import { ExecutionContextProvider } from "./ExecutionContext";
@@ -23,7 +23,6 @@ export const CQL_RETURN_TYPES_MISMATCH_ERROR =
"One or more Population Criteria has a mismatch with CQL return types. Test Cases cannot be executed until this is resolved.";

const TestCaseRoutes = () => {
const featureFlags = useFeatureFlags();
const [measureBundle, setMeasureBundle] = useState<Bundle>();
const [valueSets, setValueSets] = useState<ValueSet[]>();
const [errors, setErrors] = useState<Array<string>>([]);
@@ -111,6 +110,61 @@ const TestCaseRoutes = () => {
setExecutionContextReady(!!measureBundle && !!valueSets && !!measure);
}, [measureBundle, measure, valueSets]);

const routesConfig = [
{
children: [
{
path: "/measures/:measureId/edit/test-cases",
element: <RedirectToList />,
},
{
path: "/measures/:measureId/edit/test-cases/:id",
element: <EditTestCase errors={errors} setErrors={setErrors} />,
},
{
path: "/measures/:measureId/edit/test-cases/list-page",
element: (
<TestCaseLandingWrapper
qdm={false}
children={
<TestCaseLanding
errors={errors}
setErrors={setErrors}
setWarnings={setImportWarnings}
/>
}
/>
),
},
{
path: "/measures/:measureId/edit/test-cases/list-page/:criteriaId",
element: (
<TestCaseLandingWrapper
qdm={false}
children={
<TestCaseLanding
errors={errors}
setErrors={setErrors}
setWarnings={setImportWarnings}
/>
}
/>
),
},
{
path: "/measures/:measureId/edit/test-cases/list-page/test-case-data",
element: (
<TestCaseLandingWrapper qdm={false} children={<TestCaseData />} />
),
},
{ path: "/404", element: <NotFound /> },
{ path: "*", element: <NotFound /> },
],
},
];

const router = createBrowserRouter(routesConfig);

return (
<ExecutionContextProvider
value={{
@@ -133,7 +187,7 @@ const TestCaseRoutes = () => {
{importWarnings && importWarnings.length > 0 && (
<StatusHandler importWarnings={importWarnings} />
)}
<Routes>
{/* <Routes>
<Route path="/measures/:measureId/edit/test-cases/list-page">
<Route
index
@@ -191,7 +245,8 @@ const TestCaseRoutes = () => {
</Route>

<Route path="*" element={<NotFound />} />
</Routes>
</Routes> */}
<RouterProvider router={router} />
</ExecutionContextProvider>
);
};
Loading