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

Commit

Permalink
Merge pull request #502 from MeasureAuthoringTool/feature/MAT-5974
Browse files Browse the repository at this point in the history
MAT-5974 Added Dirty checks to Codes, Attributes and Negation Rationa…
  • Loading branch information
RohitKandimalla authored Nov 27, 2023
2 parents 05ffeb8 + 8747162 commit e9ce2af
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ const valueSets = [

let handleDiagnosisChange = jest.fn();

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("Diagnosis Component", () => {
beforeEach(() => {
handleDiagnosisChange = jest.fn((diagnoses) => {
Expand Down Expand Up @@ -183,7 +195,7 @@ describe("Diagnosis Component", () => {

const rankInput = screen.getByTestId(
"integer-input-field-Rank"
) as HTMLElement;
) as HTMLInputElement;
expect(rankInput).toBeInTheDocument();
expect(rankInput.value).toBe("");

Expand Down Expand Up @@ -288,7 +300,7 @@ describe("Diagnosis Component", () => {

const rankInput = screen.getByTestId(
"integer-input-field-Rank"
) as HTMLElement;
) as HTMLInputElement;
expect(rankInput).toBeInTheDocument();
expect(rankInput.value).toBe("");

Expand Down Expand Up @@ -444,7 +456,7 @@ describe("Diagnosis Component", () => {

const rankInput = screen.getByTestId(
"integer-input-field-Rank"
) as HTMLElement;
) as HTMLInputElement;
expect(rankInput).toBeInTheDocument();
expect(rankInput.value).toBe("");

Expand Down Expand Up @@ -533,7 +545,7 @@ describe("Diagnosis Component", () => {

const rankInput = screen.getByTestId(
"integer-input-field-Rank"
) as HTMLElement;
) as HTMLInputElement;
expect(rankInput).toBeInTheDocument();
expect(rankInput.value).toBe("");

Expand Down
12 changes: 12 additions & 0 deletions src/components/common/codeInput/CodeInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ const valueSets = [
},
];

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("CodeInput Component", () => {
it("Should render Code Input component", async () => {
render(
Expand Down
21 changes: 20 additions & 1 deletion src/components/common/codeInput/CodeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React, { useEffect, useState } from "react";
import "twin.macro";
import "styled-components/macro";
import { Select, TextField } from "@madie/madie-design-system/dist/react";
import {
Select,
TextField,
MadieDiscardDialog,
} from "@madie/madie-design-system/dist/react";
import { MenuItem } from "@mui/material";
import { CQL, ValueSet, Concept } from "cqm-models";
import { routeHandlerStore } from "@madie/madie-util";

type CodeSystems = {
[name: string]: string;
Expand Down Expand Up @@ -38,6 +43,9 @@ const CodeInput = ({
const [isCustom, setCustom] = useState<boolean>(false);
const [customCode, setCustomCode] = useState<string>();

const { updateRouteHandlerState } = routeHandlerStore;
const [discardDialogOpen, setDiscardDialogOpen] = useState(false);

useEffect(() => {
if (selectedCodeSystemName && customCode) {
const cqlCode = new CQL.Code(
Expand All @@ -51,6 +59,10 @@ const CodeInput = ({
}, [selectedCodeSystemName, customCode]);

Check warning on line 59 in src/components/common/codeInput/CodeInput.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has a missing dependency: 'handleChange'. Either include it or remove the dependency array. If 'handleChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

const handleValueSetChange = (event) => {
updateRouteHandlerState({
canTravel: false,
pendingRoute: "",
});
const oid = event.target.value;
// clear value set, code systems, code concepts and selected code
setSelectedValueSet(undefined);
Expand Down Expand Up @@ -251,6 +263,13 @@ const CodeInput = ({
)}
</div>
)}
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
setDiscardDialogOpen(false);
}}
onClose={() => setDiscardDialogOpen(false)}
/>
</div>
);
};
Expand Down
12 changes: 12 additions & 0 deletions src/components/common/componentDataType/ComponentType.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ const mockFormik: FormikContextType<any> = {
},
};

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("Component Type Component", () => {
let assessmentPerformed;
beforeEach(() => {
Expand Down
18 changes: 17 additions & 1 deletion src/components/common/facilityLocation/FacilityLocation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,26 @@ export const mockValueSets = [
];
const mockOnChange = jest.fn();

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("FacilityLocation Component", () => {
it("should render FacilityLocation view", () => {
render(
<FacilityLocation onChange={mockOnChange} valueSets={mockValueSets} />
<FacilityLocation
onChange={mockOnChange}
valueSets={mockValueSets}
canEdit
/>
);
expect(screen.getByTestId("value-set-selector")).toBeInTheDocument();
expect(screen.getByTestId("location-period-start")).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ let selectedDataElement = {
const handleChange = jest.fn();
const deleteCode = jest.fn();

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("Codes section", () => {
it("Should render Codes component with provided props", async () => {
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Select,
TextField,
Button,
MadieDiscardDialog,
} from "@madie/madie-design-system/dist/react";
import { MenuItem, Chip } from "@mui/material";
import _ from "lodash";
Expand All @@ -18,6 +19,7 @@ import {
Code,
} from "cqm-models";
import { makeStyles } from "@mui/styles";
import { routeHandlerStore } from "@madie/madie-util";

interface Chip {
title: String;
Expand Down Expand Up @@ -69,6 +71,9 @@ const Codes = ({

const [chips, setChips] = useState([]);

const { updateRouteHandlerState } = routeHandlerStore;
const [discardDialogOpen, setDiscardDialogOpen] = useState(false);

// filters out the appropriate value set for the selected data element and gets all code concepts
// Also creates an object for CodeSystems oid as key and display name as value
useEffect(() => {
Expand Down Expand Up @@ -126,6 +131,10 @@ const Codes = ({
};

const handleCodeSystemChange = (event) => {
updateRouteHandlerState({
canTravel: false,
pendingRoute: "",
});
setSelectedCodeConcept(null);
const selectedCodeSystemName = event.target.value;
setSelectedCodeSystemName(selectedCodeSystemName);
Expand Down Expand Up @@ -171,9 +180,9 @@ const Codes = ({
const existingCode = _.find(chips, _.matches({ id: newCodeId }));
if (_.isEmpty(existingCode)) {
handleChange(savedCode);
setSelectedCodeSystemName("");
setSelectedCodeConcept(null);
}
setSelectedCodeSystemName("");
setSelectedCodeConcept(null);
}
};

Expand Down Expand Up @@ -327,6 +336,13 @@ const Codes = ({
);
})}
</div>
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
setDiscardDialogOpen(false);
}}
onClose={() => setDiscardDialogOpen(false)}
/>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,18 @@ export const testValueSets = [

const mockOnChange = jest.fn();

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

const renderDataElementsCard = (
activeTab,
setCardActiveTab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ const mockCqmMeasure = {
value_sets: [],
};

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("AttributeSection", () => {
let encounterElement;
let assessmentElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import { useFormik } from "formik";
import DisplayAttributeInputs from "./DisplayAttributeInputs";
import AttributeChipList from "../AttributeChipList";
import { MadieDiscardDialog } from "@madie/madie-design-system/dist/react";
import { routeHandlerStore } from "@madie/madie-util";

export interface Chip {
title?: String;
Expand Down Expand Up @@ -46,6 +48,17 @@ const AttributeSection = ({
onAddClicked(values.attribute, values.type, values.attributeValue);
},
});
const { resetForm } = formik;

const { updateRouteHandlerState } = routeHandlerStore;
const [discardDialogOpen, setDiscardDialogOpen] = useState(false);

useEffect(() => {
updateRouteHandlerState({
canTravel: !formik.dirty,
pendingRoute: "",
});
}, [formik.dirty]);

useEffect(() => {
if (selectedDataElement && selectedDataElement.schema) {
Expand Down Expand Up @@ -127,6 +140,14 @@ const AttributeSection = ({
canEdit={canEdit}
onDeleteAttributeChip={onDeleteAttributeChip}
/>
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
resetForm();
setDiscardDialogOpen(false);
}}
onClose={() => setDiscardDialogOpen(false)}
/>
</form>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ const mockFormik: FormikContextType<any> = {
},
};

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("DisplayAttributeInputs component", () => {
let encounterElement;
let assessmentElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ const valueSets = [
},
];

jest.mock("@madie/madie-util", () => ({
routeHandlerStore: {
subscribe: (set) => {
set();
return { unsubscribe: () => null };
},
updateRouteHandlerState: () => null,
state: { canTravel: true, pendingPath: "" },
initialState: { canTravel: true, pendingPath: "" },
},
}));

describe("QdmEntity Component", () => {
beforeEach(() => {});

Expand Down

0 comments on commit e9ce2af

Please sign in to comment.