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

Mat 7844 reset execution results after change #749

Merged
merged 7 commits into from
Oct 30, 2024
2 changes: 1 addition & 1 deletion src/api/CalculationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class CalculationService {
strata.strataCode === strataResult.strataCode) ||
(strata.strataId && strata.strataId === strataResult.strataId)
);
return population.result && stratification.result;
return population?.result && stratification?.result;
}
);
// adjust the episode count for strata & associated population
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const ExpectedActual = ({
onChange,
onStratificationChange,
errors,
executionRun = false,
isTestCaseExecuted = false,
clearTestResults,
groupsStratificationAssociationMap,
}) => {
return (
Expand All @@ -22,7 +23,8 @@ const ExpectedActual = ({
onChange={onChange}
onStratificationChange={onStratificationChange}
errors={errors}
executionRun={executionRun}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={clearTestResults}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/editTestCase/qdm/EditTestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ const EditTestCase = () => {
canEdit={canEdit}
testCaseGroups={formik?.values?.groupPopulations}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
errors={formik.errors.groupPopulations}
groupCoverageResult={groupCoverageResult}
testCaseResults={testCaseResults}
Expand Down
2 changes: 2 additions & 0 deletions src/components/editTestCase/qdm/RightPanel/RightPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const RightPanel = ({
testCaseGroups,
testCaseResults,
isTestCaseExecuted,
setIsTestCaseExecuted,
errors,
groupCoverageResult,
calculationErrors,
Expand Down Expand Up @@ -56,6 +57,7 @@ const RightPanel = ({
onChange={onChange}
errors={errors}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
/>
)}
{activeTab === "details" && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe("Group Populations", () => {
it("should handle checkbox changes", () => {
testCaseGroups[0].scoring = MeasureScoring.CONTINUOUS_VARIABLE;
const handleChange = jest.fn();
const setIsTestCaseExecuted = jest.fn();
const updatedTestCaseGroups = [
{
groupId: "Group1_ID",
Expand Down Expand Up @@ -246,6 +247,7 @@ describe("Group Populations", () => {
isTestCaseExecuted={true}
testCaseResults={testCaseGroups}
groupPopulations={testCaseGroups}
setIsTestCaseExecuted={setIsTestCaseExecuted}
onChange={handleChange}
errors={errors}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface GroupPopulationsProps {
disableExpected: boolean;
testCaseResults: GroupPopulation[];
isTestCaseExecuted: boolean;
setIsTestCaseExecuted?: (isTestCaseExecuted: boolean) => void;
groupPopulations: GroupPopulation[];
onChange?: (
groupPopulations: GroupPopulation[],
Expand All @@ -30,6 +31,7 @@ interface GroupPopulationsProps {
const GroupPopulations = ({
disableExpected = false,
isTestCaseExecuted = false,
setIsTestCaseExecuted,
testCaseResults,
groupPopulations = [],
onChange,
Expand All @@ -56,6 +58,7 @@ const GroupPopulations = ({
errors={errors?.[groupIndex]}
disableExpected={disableExpected}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
populations={gp.populationValues}
populationResults={
testCaseResults
Expand Down Expand Up @@ -96,6 +99,7 @@ const GroupPopulations = ({
scoring={gp.scoring}
disableExpected={disableExpected}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
populations={strat.populationValues}
populationResults={
testCaseResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TestCasePopulationProps {
i?: number;
strat?: boolean;
isTestCaseExecuted?: boolean;
setIsTestCaseExecuted?: (isTestCaseExecuted: boolean) => void;
}

const TestCasePopulation = ({
Expand All @@ -31,6 +32,7 @@ const TestCasePopulation = ({
strat,
i,
isTestCaseExecuted,
setIsTestCaseExecuted,
}: TestCasePopulationProps) => {
const populationNameTemplate = (prop) => {
if (prop === PopulationType.INITIAL_POPULATION) {
Expand Down Expand Up @@ -80,9 +82,10 @@ const TestCasePopulation = ({
aria-labelledby={`${population.name}-expected`}
name={population.name}
expectedValue={population.expected}
onChange={(expectedValue) =>
onChange({ ...population, expected: expectedValue })
}
onChange={(expectedValue) => {
setIsTestCaseExecuted(false);
return onChange({ ...population, expected: expectedValue });
}}
populationBasis={populationBasis}
disabled={disableExpected}
data-testid={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MemoryRouter } from "react-router-dom";
import TestCasePopulationList from "./TestCasePopulationList";
import { MeasureScoring, PopulationType } from "@madie/madie-models";
import userEvent from "@testing-library/user-event";
import { act } from "react-dom/test-utils";

describe("TestCasePopulationList component", () => {
afterEach(() => {
Expand Down Expand Up @@ -77,13 +78,17 @@ describe("TestCasePopulationList component", () => {
actual: true,
},
];
const handleChange = jest.fn();
const handle1Change = jest.fn((arg1, arg2) => {});

const setIsTestCaseExecuted = jest.fn();

render(
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
onChange={handleChange}
onChange={handle1Change}
setIsTestCaseExecuted={setIsTestCaseExecuted}
disableExpected={false}
populationBasis="true"
content="population"
Expand All @@ -103,10 +108,11 @@ describe("TestCasePopulationList component", () => {
"test-population-initialPopulation-expected"
);
expect(ippCb).toBeInTheDocument();
userEvent.click(ippCb);
await waitFor(() => {
expect(handleChange).toHaveBeenCalled();

await act(async () => {
userEvent.click(ippCb);
});
await waitFor(() => expect(handle1Change).toHaveBeenCalled());
});

it("should handle stratification changes for the test case population", async () => {
Expand All @@ -126,6 +132,7 @@ describe("TestCasePopulationList component", () => {
};
const handleChange = jest.fn();
const handleStratificationChange = jest.fn();
const setIsTestCaseExecuted = jest.fn();

render(
<MemoryRouter>
Expand All @@ -141,6 +148,7 @@ describe("TestCasePopulationList component", () => {
content="population"
groupIndex={0}
scoring="Proportion"
setIsTestCaseExecuted={setIsTestCaseExecuted}
/>
</MemoryRouter>
);
Expand Down Expand Up @@ -177,6 +185,7 @@ describe("TestCasePopulationList component", () => {
};
const handleChange = jest.fn();
const handleStratificationChange = jest.fn();
const setIsTestCaseExecuted = jest.fn();

render(
<MemoryRouter>
Expand All @@ -193,6 +202,7 @@ describe("TestCasePopulationList component", () => {
groupIndex={0}
scoring="Proportion"
isTestCaseExecuted={true}
setIsTestCaseExecuted={setIsTestCaseExecuted}
/>
</MemoryRouter>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface TestCasePopulationListProps {
populationBasis: string;
disableExpected?: boolean;
isTestCaseExecuted?: boolean;
setIsTestCaseExecuted?: (isTestCaseExecuted: boolean) => void;
onChange?: (
populations: DisplayPopulationValue[],
changedPopulation: DisplayPopulationValue
Expand All @@ -57,6 +58,7 @@ const TestCasePopulationList = ({
populationBasis,
disableExpected = true,
isTestCaseExecuted = false,
setIsTestCaseExecuted,
onChange,
onStratificationChange,
errors,
Expand Down Expand Up @@ -236,6 +238,7 @@ const TestCasePopulationList = ({
index={groupIndex}
QDM={true}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
strataCode={stratification?.name}
stratification={stratification}
stratResult={stratResult}
Expand All @@ -251,6 +254,7 @@ const TestCasePopulationList = ({
<TestCasePopulation
i={j}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
strat={!_.isEmpty(stratification)}
population={population}
populationResult={populationResults ? populationResults[j] : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const determineGroupResult = (
}
for (let i = 0; i < populations?.length; i++) {
const population = populations[i];
const { actual } = populationResult[i];
//const { actual } = populationResult[i];
const actual =
populationResult[i] === undefined ? "" : populationResult[i].actual;
const { expected } = population;
if (populationBasis === "boolean" && expected != actual) {
return "fail";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import userEvent from "@testing-library/user-event";
import TestCaseStratification from "./TestCaseStratification";

describe("Test Case Stratification Component", () => {
const setIsTestCaseExecuted = jest.fn();
const { findByTestId, findByText, getByTestId } = screen;
const renderStrats = (
strataCode,
Expand All @@ -24,7 +25,8 @@ describe("Test Case Stratification Component", () => {
render(
<TestCaseStratification
strataCode={strataCode}
executionRun={executionRun}
isTestCaseExecuted={executionRun}
setIsTestCaseExecuted={setIsTestCaseExecuted}
stratification={stratification}
stratResult={stratification}
populationBasis={populationBasis}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TestCaseStratificationProps {
QDM?: boolean;
index?: number;
isTestCaseExecuted?: boolean;
setIsTestCaseExecuted?: (isTestCaseExecuted: boolean) => void;
}

const TestCaseStratification = ({
Expand All @@ -23,6 +24,7 @@ const TestCaseStratification = ({
populationBasis,
disableExpected = false,
onStratificationChange,
setIsTestCaseExecuted,
index,
QDM = false,
isTestCaseExecuted = false,
Expand All @@ -41,12 +43,13 @@ const TestCaseStratification = ({
<ExpectActualInput
id={`${stratification.name}-expected-cb`}
expectedValue={stratification.expected}
onChange={(expectedValue) =>
onChange={(expectedValue) => {
setIsTestCaseExecuted(false);
onStratificationChange({
...stratification,
expected: expectedValue,
})
}
});
}}
populationBasis={populationBasis}
disabled={disableExpected}
data-testid={
Expand Down
5 changes: 4 additions & 1 deletion src/components/editTestCase/qiCore/EditTestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,10 @@ const EditTestCase = (props: EditTestCaseProps) => {
<ExpectedActual
canEdit={canEdit}
groupPopulations={groupPopulations}
executionRun={!_.isNil(populationGroupResults)}
isTestCaseExecuted={!_.isNil(populationGroupResults)}
clearTestResults={() => {
setPopulationGroupResults(undefined);
}}
errors={formik.errors.groupPopulations}
groupsStratificationAssociationMap={stratificationsMap}
onChange={(
Expand Down
12 changes: 8 additions & 4 deletions src/components/populations/GroupPopulations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("Group Populations", () => {
const handleChange = jest.fn();
render(
<GroupPopulations
executionRun
isTestCaseExecuted={true}
groupPopulations={groupPopulations}
onChange={handleChange}
/>
Expand Down Expand Up @@ -139,11 +139,13 @@ describe("Group Populations", () => {
});

it("should handle null groupPopulation input", () => {
const mockExecute = jest.fn();
render(
<GroupPopulations
groupPopulations={null}
onChange={jest.fn()}
executionRun
isTestCaseExecuted
setIsTestCaseExecuted={mockExecute}
/>
);
expect(
Expand Down Expand Up @@ -188,7 +190,7 @@ describe("Group Populations", () => {
render(
<GroupPopulations
disableExpected={true}
executionRun
isTestCaseExecuted={true}
groupPopulations={testCaseGroups}
onChange={handleChange}
groupsStratificationAssociationMap={groupStratificationsMap}
Expand All @@ -206,10 +208,12 @@ describe("Group Populations", () => {
it("should handle checkbox changes", () => {
testCaseGroups[0].scoring = MeasureScoring.CONTINUOUS_VARIABLE;
const handleChange = jest.fn();
const setIsTestCaseExecuted = jest.fn();
const handleStratificationChange = jest.fn();
render(
<GroupPopulations
executionRun
isTestCaseExecuted={true}
setIsTestCaseExecuted={setIsTestCaseExecuted}
groupPopulations={testCaseGroups}
onChange={handleChange}
onStratificationChange={handleStratificationChange}
Expand Down
12 changes: 8 additions & 4 deletions src/components/populations/GroupPopulations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import * as _ from "lodash";
export interface PopulationsProps {
disableExpected?: boolean;
// we dont need disable actual as it's always disabled.
executionRun?: boolean;
isTestCaseExecuted?: boolean;
setIsTestCaseExecuted?: (isTestCaseExecuted) => void;
groupPopulations: DisplayGroupPopulation[];
onChange?: (
groupPopulations: GroupPopulation[],
Expand All @@ -33,7 +34,8 @@ const GroupPopulations = ({
disableExpected = false,
groupsStratificationAssociationMap,
// Execution run determines weather we display one of 3 views.
executionRun = false,
isTestCaseExecuted = false,
setIsTestCaseExecuted,
groupPopulations = [],
onChange,
onStratificationChange,
Expand All @@ -50,7 +52,8 @@ const GroupPopulations = ({
scoring={gp.scoring}
errors={errors?.[i]}
disableExpected={disableExpected}
executionRun={executionRun}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
populations={gp.populationValues}
populationBasis={gp?.populationBasis}
onChange={(populations, type, changedPopulation) => {
Expand Down Expand Up @@ -81,7 +84,8 @@ const GroupPopulations = ({
}
scoring={gp.scoring}
disableExpected={disableExpected}
executionRun={executionRun}
isTestCaseExecuted={isTestCaseExecuted}
setIsTestCaseExecuted={setIsTestCaseExecuted}
populations={null}
populationBasis={gp.populationBasis}
onStratificationChange={(
Expand Down
Loading
Loading