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

MAT-5974 Added Dirty checks to Codes, Attributes and Negation Rationa… #502

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 [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 @@ -48,9 +56,13 @@
);
handleChange(cqlCode);
}
}, [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 @@
)}
</div>
)}
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
setDiscardDialogOpen(false);

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

View check run for this annotation

Codecov / codecov/patch

src/components/common/codeInput/CodeInput.tsx#L269

Added line #L269 was not covered by tests
}}
onClose={() => setDiscardDialogOpen(false)}

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

View check run for this annotation

Codecov / codecov/patch

src/components/common/codeInput/CodeInput.tsx#L271

Added line #L271 was not covered by tests
/>
</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
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 @@
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 @@
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 [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 handleCodeSystemChange = (event) => {
updateRouteHandlerState({
canTravel: false,
pendingRoute: "",
});
setSelectedCodeConcept(null);
const selectedCodeSystemName = event.target.value;
setSelectedCodeSystemName(selectedCodeSystemName);
Expand Down Expand Up @@ -171,9 +180,9 @@
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 @@
);
})}
</div>
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
setDiscardDialogOpen(false);

Check warning on line 342 in src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/Codes/Codes.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/Codes/Codes.tsx#L342

Added line #L342 was not covered by tests
}}
onClose={() => setDiscardDialogOpen(false)}

Check warning on line 344 in src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/Codes/Codes.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/Codes/Codes.tsx#L344

Added line #L344 was not covered by tests
/>
</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 { 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 @@
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 @@
canEdit={canEdit}
onDeleteAttributeChip={onDeleteAttributeChip}
/>
<MadieDiscardDialog
open={discardDialogOpen}
onContinue={() => {
resetForm();
setDiscardDialogOpen(false);

Check warning on line 147 in src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx#L146-L147

Added lines #L146 - L147 were not covered by tests
}}
onClose={() => setDiscardDialogOpen(false)}

Check warning on line 149 in src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx#L149

Added line #L149 was not covered by tests
/>
</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
Loading