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

Commit

Permalink
Merge branch 'develop' into MAT-7685_PositiveInt
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu authored Oct 22, 2024
2 parents 27cd108 + 4459c3b commit af09e45
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/components/editTestCase/qdm/EditTestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
GroupCoverageResult,
} from "../../../util/cqlCoverageBuilder/CqlCoverageBuilder";
import checkSpecialCharacters from "../../../util/checkSpecialCharacters";
import { GroupPopulation } from "@madie/madie-models/dist/TestCase";

const EditTestCase = () => {
useDocumentTitle("MADiE Edit Measure Edit Test Case");
Expand Down Expand Up @@ -106,7 +107,7 @@ const EditTestCase = () => {
const [selectedDataElement, setSelectedDataElement] = useState<DataElement>();
const [groupCoverageResult, setGroupCoverageResult] =
useState<GroupCoverageResult>();
const [testCaseResults, setTestCaseResults] = useState<any>();
const [testCaseResults, setTestCaseResults] = useState<GroupPopulation[]>();
dayjs.extend(utc);
dayjs.utc().format(); // utc format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Group Populations", () => {
id: "123",
name: PopulationType.INITIAL_POPULATION,
expected: true,
actual: true,
actual: false,
},
],
stratificationValues: [
Expand Down Expand Up @@ -144,7 +144,8 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={true}
groupPopulations={null}
testCaseResults={[]}
groupPopulations={[]}
onChange={jest.fn()}
errors={errors}
/>
Expand All @@ -161,6 +162,7 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={true}
testCaseResults={[]}
groupPopulations={undefined}
onChange={jest.fn()}
errors={errors}
Expand All @@ -178,6 +180,7 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={true}
testCaseResults={[]}
groupPopulations={[]}
onChange={jest.fn()}
errors={errors}
Expand All @@ -203,25 +206,45 @@ describe("Group Populations", () => {
/>
);

const ippRows = screen.getAllByRole("row", {
name: "Initial Population",
});
const ippRow = ippRows[0];
const ippRow = screen.getByRole("row", { name: "Initial Population" });
const ippCbs = within(ippRow).getAllByRole("checkbox");
expect(ippCbs[0]).toBeDisabled();
expect(ippCbs[0]).toBeChecked();
expect(ippCbs[1]).toBeDisabled();
expect(ippCbs[1]).toBeChecked();
expect(ippCbs[1]).not.toBeChecked();
});

it.skip("should handle checkbox changes", () => {
it("should handle checkbox changes", () => {
testCaseGroups[0].scoring = MeasureScoring.CONTINUOUS_VARIABLE;
const handleChange = jest.fn();
const handleStratificationChange = jest.fn();
const updatedTestCaseGroups = [
{
groupId: "Group1_ID",
scoring: MeasureScoring.CONTINUOUS_VARIABLE,
populationBasis: "true",
populationValues: [
{
id: "123",
name: PopulationType.INITIAL_POPULATION,
expected: false,
actual: false,
},
],
stratificationValues: [
{
id: "321",
name: "strata-1 Initial Population",
expected: true,
actual: false,
},
],
},
];
render(
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={true}
testCaseResults={testCaseGroups}
groupPopulations={testCaseGroups}
onChange={handleChange}
errors={errors}
Expand All @@ -233,32 +256,15 @@ describe("Group Populations", () => {
expect(ippCbs[0]).not.toBeDisabled();
expect(ippCbs[0]).toBeChecked();
expect(ippCbs[1]).toBeDisabled();
expect(ippCbs[1]).toBeChecked();
expect(ippCbs[1]).not.toBeChecked();

userEvent.click(ippCbs[0]);
expect(handleChange).toHaveBeenNthCalledWith(
1,
testCaseGroups,
updatedTestCaseGroups,
"Group1_ID",
{ actual: true, expected: false, id: "123", name: "initialPopulation" }
{ actual: false, expected: false, id: "123", name: "initialPopulation" }
);

userEvent.click(ippCbs[0]);
expect(handleChange).toHaveBeenNthCalledWith(
2,
testCaseGroups,
"Group1_ID",
{ actual: true, expected: false, id: "123", name: "initialPopulation" }
);

const stratRow = screen.getByRole("row", {
name: "strata-1 Initial Population",
});
const stratCbs = within(stratRow).getAllByRole("checkbox");
expect(stratCbs[0]).not.toBeDisabled();
expect(stratCbs[0]).toBeChecked();
userEvent.click(stratCbs[0]);
expect(handleStratificationChange).toHaveBeenCalledTimes(1);
});

it("should display empty on non run", () => {
Expand All @@ -267,6 +273,7 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={false}
testCaseResults={testCaseGroups}
groupPopulations={testCaseGroups}
onChange={handleChange}
errors={errors}
Expand Down Expand Up @@ -301,6 +308,7 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={false}
testCaseResults={[]}
groupPopulations={groupPopulations}
onChange={handleChange}
errors={errors}
Expand All @@ -317,6 +325,7 @@ describe("Group Populations", () => {
<GroupPopulations
disableExpected={false}
isTestCaseExecuted={false}
testCaseResults={testCaseGroups}
groupPopulations={testCaseGroups}
onChange={handleChange}
errors={errors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GroupPopulation } from "@madie/madie-models/dist/TestCase";

interface GroupPopulationsProps {
disableExpected: boolean;
testCaseResults: any;
testCaseResults: GroupPopulation[];
isTestCaseExecuted: boolean;
groupPopulations: GroupPopulation[];
onChange?: (
Expand Down Expand Up @@ -101,7 +101,8 @@ const GroupPopulations = ({
testCaseResults
? testCaseResults.find(
(pop) => pop.groupId === gp.groupId
)?.populationValues
)?.stratificationValues[stratIndex]
?.populationValues
: []
}
stratification={strat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ describe("TestCasePopulationList component", () => {
render(
<MemoryRouter>
<TestCasePopulationList
populationBasis="boolean"
content="Measure Group 1"
scoring="Proportion"
populations={testCasePopulations}
content="population"
populationResults={testCasePopulations}
populationBasis="boolean"
groupIndex={0}
scoring="Proportion"
/>
</MemoryRouter>
);
Expand Down Expand Up @@ -81,6 +82,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
onChange={handleChange}
disableExpected={false}
populationBasis="true"
Expand Down Expand Up @@ -129,6 +131,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
stratification={testCaseStratification}
stratResult={testCaseStratification}
onChange={handleChange}
Expand Down Expand Up @@ -179,6 +182,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
stratification={testCaseStratification}
stratResult={testCaseStratification}
onChange={handleChange}
Expand Down Expand Up @@ -258,6 +262,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
onChange={handleChange}
disableExpected={false}
populationBasis="boolean"
Expand Down Expand Up @@ -334,6 +339,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
onChange={handleChange}
disableExpected={false}
populationBasis="boolean"
Expand Down Expand Up @@ -388,6 +394,7 @@ describe("TestCasePopulationList component", () => {
<MemoryRouter>
<TestCasePopulationList
populations={testCasePopulations}
populationResults={testCasePopulations}
onChange={handleChange}
disableExpected={false}
populationBasis="boolean"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DisplayStratificationValue,
StratificationExpectedValue,
PopulationType,
PopulationExpectedValue,
} from "@madie/madie-models";
import classNames from "classnames";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand All @@ -26,7 +27,7 @@ export interface TestCasePopulationListProps {
groupIndex?: number;
scoring: string;
populations: DisplayPopulationValue[];
populationResults: any;
populationResults: PopulationExpectedValue[];
stratification?: StratificationExpectedValue;
stratResult?: any;
populationBasis: string;
Expand Down Expand Up @@ -150,21 +151,20 @@ const TestCasePopulationList = ({
};

// Determines the result of each PopulationCriteria
// If stratification fails, then we skip verifying populations as the PC is failed
// if stratification pass, then we determine its populations result
// If the PC is not stratified, then we determine the PC results only based on its populations.
// If the PC is stratified then we determine the result based on stratResult and its populationValues (stratResult.populationValues)
// If the PC is not stratified, then we determine the PC results only based on its populationResults.
const [view, setView] = useState<string>();
useEffect(() => {
let localView = view;
if (stratification) {
localView = determineGroupResultStratification(
populationBasis,
stratification,
stratResult,
isTestCaseExecuted
setView(
determineGroupResultStratification(
populationBasis,
stratification,
stratResult,
isTestCaseExecuted
)
);
}
if (populationResults?.length > 0) {
} else if (populationResults?.length > 0) {
setView(
determineGroupResult(
populationBasis,
Expand All @@ -173,8 +173,6 @@ const TestCasePopulationList = ({
isTestCaseExecuted
)
);
} else {
setView(localView);
}
}, [
isTestCaseExecuted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const determineGroupResult = (
};

// Determines if stratification expected and actual value matches along with all its populations
// If Stratification didn't fail, then we proceed to check the groupResults
export const determineGroupResultStratification = (
populationBasis: string,
stratification: StratificationExpectedValue,
Expand All @@ -65,5 +66,10 @@ export const determineGroupResultStratification = (
return "fail";
}
}
return "pass";
return determineGroupResult(
populationBasis,
stratification.populationValues,
stratificationResult?.populationValues,
isTestCaseExecuted
);
};

0 comments on commit af09e45

Please sign in to comment.