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

Commit

Permalink
some minor refactoring and test case writing
Browse files Browse the repository at this point in the history
  • Loading branch information
ethankaplan committed Nov 22, 2023
1 parent 26e9ab0 commit 6f08eb3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React from "react";
interface Props {
population: string;
populationText: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import _, { isEmpty } from "lodash";
import _ from "lodash";
import CoverageTab from "./CoverageTab";

import { MappedCql } from "../../../../../util/GroupCoverageHelpers";
Expand All @@ -12,9 +12,7 @@ interface Props {

const CoverageTabList = ({ groupPopulations, mappedCql }: Props) => {
return (
<>
<div tw="border-b pb-2">{}</div>

<div data-testid="coverage-tab-list">
{mappedCql &&
groupPopulations.map((pop) => {
return (
Expand All @@ -28,7 +26,7 @@ const CoverageTabList = ({ groupPopulations, mappedCql }: Props) => {
<div tw="flex-none w-1/5"></div>
<div></div>
</div>
</>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React from "react";
// import QdmGroupCoverage from "../../../groupCoverage/QdmGroupCoverage";
import { isEmpty } from "lodash";
import { MadieAlert } from "@madie/madie-design-system/dist/react";
import { mapCql, mapCoverageCql } from "../../../../util/GroupCoverageHelpers";
import { mapCoverageCql } from "../../../../util/GroupCoverageHelpers";
import "twin.macro";
import "styled-components/macro";
import CoverageTabList from "./CoverageTabs/CoverageTabList";

const TestCaseCoverage = ({
calculationResults,
groupPopulations,
measureCql,
measureGroups,
calculationErrors,
}) => {
const TestCaseCoverage = ({ groupPopulations, measureCql }) => {
return (
<div tw="p-5" style={{ paddingRight: ".25rem" }}>
<CoverageTabList
data-testid="coverage-tab-list"
groupPopulations={groupPopulations.populations.filter(
(pop) => pop.definition
)}
Expand Down
48 changes: 37 additions & 11 deletions src/components/testCaseLanding/qdm/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { ValueSet } from "cqm-models";
import qdmCalculationService, {
QdmCalculationService,
} from "../../../api/QdmCalculationService";
import { measureCql } from "../../editTestCase/groupCoverage/_mocks_/QdmMeasureCql";

const serviceConfig: ServiceConfig = {
elmTranslationService: { baseUrl: "translator.url" },
Expand All @@ -55,13 +56,31 @@ const serviceConfig: ServiceConfig = {
baseUrl: "http.com",
},
};

const mappedCql = {
initialPopulation: {
id: "0223850b-df35-4d0d-98f1-df993f7de328",
text: 'define "Initial Population":\r\n ["Encounter, Performed": "Emergency Department Visit"]',
},
denominator: {
id: "91ae58e2-aa5a-4163-ad39-835ff7d0822b",
text: 'define "IP2":\r\n ["Encounter, Performed"] E',
},
numerator: {
id: "dc788738-8c66-4538-990c-7a57430c55e3",
text: 'define "IP2":\r\n ["Encounter, Performed"] E',
},
};
const MEASURE_CREATEDBY = "testuser";
// Mock data for Measure retrieved from MeasureService
const measure = {
id: "1",
measureName: "measureName",
createdBy: MEASURE_CREATEDBY,
cqlLibraryName: "testLibrary",
cmsId: "1234",
measureSetId: "1234",

scoring: MeasureScoring.PROPORTION,
groups: [
{
id: "1",
Expand All @@ -88,6 +107,7 @@ const measure = {
],
model: Model.QDM_5_6,
acls: [{ userId: "[email protected]", roles: ["SHARED_WITH"] }],
cql: { measureCql },
} as unknown as Measure;

jest.mock("@madie/madie-util", () => ({
Expand All @@ -102,6 +122,9 @@ jest.mock("@madie/madie-util", () => ({
})),
}));

jest.mock("../../../util/GroupCoverageHelpers", () => ({
mapCoverageCql: jest.fn().mockImplementation(() => mappedCql),
}));
let importingTestCases = [];
jest.mock(
"../common/import/TestCaseImportFromBonnieDialogQDM",
Expand Down Expand Up @@ -486,7 +509,7 @@ const useMeasureServiceMockResolved = {

const getAccessToken = jest.fn();
let cqmConversionService = new CqmConversionService("url", getAccessToken);
const cqmMeasure = cqmConversionService.convertToCqmMeasure(measure);
const cqmMeasure = {};
const valueSets = [] as ValueSet[];
const setMeasure = jest.fn();
const setCqmMeasure = jest.fn();
Expand Down Expand Up @@ -731,15 +754,21 @@ describe("TestCaseList component", () => {
});

userEvent.click(screen.getByTestId("coverage-tab"));
await waitFor(() => {
expect(
screen.getByTestId("code-coverage-highlighting")
).toBeInTheDocument();
});
userEvent.click(screen.getByTestId("passing-tab"));
expect(screen.getByTestId("test-case-tbl")).toBeInTheDocument();
});

it("accordions for cql parts", async () => {
measure.createdBy = MEASURE_CREATEDBY;
renderTestCaseListComponent();

const table = await screen.findByTestId("test-case-tbl");

userEvent.click(screen.getByTestId("coverage-tab"));
const coverageTabList = await screen.findByTestId("coverage-tab-list");
expect(coverageTabList).toBeInTheDocument();
});

it("Run Test Cases button should be disabled if no valid test cases", async () => {
measure.createdBy = MEASURE_CREATEDBY;
testCases[0].validResource = false;
Expand Down Expand Up @@ -876,9 +905,6 @@ describe("TestCaseList component", () => {

it("should render New Test Case button and navigate to the Create New Test Case page when button clicked", async () => {
const { getByTestId } = renderTestCaseListComponent();

const codeCoverageTabs = await screen.findByTestId("code-coverage-tabs");
expect(codeCoverageTabs).toBeInTheDocument();
const passingTab = await screen.findByTestId("passing-tab");
expect(passingTab).toBeInTheDocument();
const testCaseList = await screen.findByTestId("test-case-tbl");
Expand Down Expand Up @@ -953,7 +979,7 @@ describe("TestCaseList component", () => {
});

userEvent.click(executeButton);
await waitFor(() => expect(screen.getByText("50%")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("0%")).toBeInTheDocument());

const table = await screen.findByTestId("test-case-tbl");
const tableRows = table.querySelectorAll("tbody tr");
Expand Down
33 changes: 6 additions & 27 deletions src/components/testCaseLanding/qdm/TestCaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,6 @@ const TestCaseList = (props: TestCaseListProps) => {
useEffect(() => {
const validTestCases = testCases?.filter((tc) => tc.validResource);
if (validTestCases && calculationOutput) {
// Pull Clause Coverage from coverage HTML
setCoveragePercentage(
getCoverageValueFromHtml(
calculationOutput["groupClauseCoverageHTML"],
selectedPopCriteria.id
)
);
setCoverageHTML(
removeHtmlCoverageHeader(calculationOutput["groupClauseCoverageHTML"])
);
const executionResults: CqmExecutionResultsByPatient = calculationOutput;

validTestCases.forEach((testCase) => {
Expand Down Expand Up @@ -244,7 +234,6 @@ const TestCaseList = (props: TestCaseListProps) => {
return null;
}
const validTestCases = testCases?.filter((tc) => tc.validResource);

if (validTestCases && validTestCases.length > 0 && cqmMeasure) {
setExecuting(true);
try {
Expand All @@ -255,7 +244,6 @@ const TestCaseList = (props: TestCaseListProps) => {
cqmMeasure,
patients
);

setCalculationOutput(calculationOutput);
} catch (error) {
console.error("calculateTestCases: error.message = " + error.message);
Expand Down Expand Up @@ -408,22 +396,13 @@ const TestCaseList = (props: TestCaseListProps) => {
</div>
)}
{activeTab === "coverage" && (
<div>
{coverageHTML && (
<CodeCoverageHighlighting
coverageHTML={coverageHTML[selectedPopCriteria.id]}
<div tw="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div tw="py-2 inline-block min-w-full sm:px-6 lg:px-8">
<TestCaseCoverage
data-testid="test-case-coverage"
groupPopulations={selectedPopCriteria}
measureCql={measure.cql}
/>
)}
<div tw="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div tw="py-2 inline-block min-w-full sm:px-6 lg:px-8">
<TestCaseCoverage
calculationResults={calculationOutput}
groupPopulations={selectedPopCriteria}
measureCql={measure.cql}
calculationErrors={errors}
measureGroups={measure?.groups}
/>
</div>
</div>
</div>
)}
Expand Down

0 comments on commit 6f08eb3

Please sign in to comment.