Skip to content

Commit

Permalink
MAT-7870: Add Model selection to Draft dialog.
Browse files Browse the repository at this point in the history
Limit model selection to QI-Core only.

Feature flag: qiCore6.
  • Loading branch information
jkotanchik-SB committed Nov 1, 2024
1 parent ad54c9e commit 45d8e22
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@babel/runtime": "^7.14.6",
"@madie/madie-models": "^1.4.14",
"@madie/madie-models": "^1.4.15",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
5 changes: 3 additions & 2 deletions src/api/useCqlLibraryServiceApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ export class CqlLibraryServiceApi {

async createDraft(
cqlLibraryId: string,
cqlLibraryName: string
cqlLibraryName: string,
model: string
): Promise<void> {
return await axios.post(
`${this.baseUrl}/cql-libraries/draft/${cqlLibraryId}`,
{ cqlLibraryName: cqlLibraryName },
{ cqlLibraryName: cqlLibraryName, model: model },
{
headers: {
Authorization: `Bearer ${this.getAccessToken()}`,
Expand Down
15 changes: 15 additions & 0 deletions src/components/cqlLibraryList/CqlLibraryList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jest.mock("@madie/madie-util", () => ({
checkUserCanDelete: jest.fn(() => {
return true;
}),
useFeatureFlags: jest.fn().mockReturnValue({
qiCore6: true,
}),
}));

const mockPush = jest.fn();
Expand All @@ -43,6 +46,7 @@ const cqlLibrary: CqlLibrary[] = [
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
librarySet: {
id: "1",
librarySetId: "librarySetId1",
Expand All @@ -62,6 +66,7 @@ const cqlLibrary: CqlLibrary[] = [
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
librarySet: {
id: "2",
librarySetId: "librarySetId2",
Expand Down Expand Up @@ -210,6 +215,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];

Expand Down Expand Up @@ -691,6 +697,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -726,6 +733,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
{
id: "650359394b0427f896ced541",
Expand All @@ -740,6 +748,7 @@ describe("CqlLibrary List component", () => {
version: "1.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -784,6 +793,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -844,6 +854,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -903,6 +914,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
{
id: "650359394b0427f896ced541",
Expand All @@ -917,6 +929,7 @@ describe("CqlLibrary List component", () => {
version: "1.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -961,6 +974,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down Expand Up @@ -998,6 +1012,7 @@ describe("CqlLibrary List component", () => {
version: "0.0.000",
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'",
cqlErrors: false,
active: true,
},
];
render(
Expand Down
8 changes: 4 additions & 4 deletions src/components/cqlLibraryList/CqlLibraryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom";
import { CqlLibrary } from "@madie/madie-models";
import CreatVersionDialog from "../createVersionDialog/CreateVersionDialog";
import useCqlLibraryServiceApi from "../../api/useCqlLibraryServiceApi";
import CreatDraftDialog from "../createDraftDialog/CreateDraftDialog";
import CreateDraftDialog from "../createDraftDialog/CreateDraftDialog";
import Snackbar from "@mui/material/Snackbar";
import MuiAlert, { AlertProps } from "@mui/material/Alert";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
Expand Down Expand Up @@ -108,9 +108,9 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) {
});
};

const createDraft = async (cqlLibrary: CqlLibrary) => {
const createDraft = async (cqlLibrary: CqlLibrary, model: string) => {
await cqlLibraryServiceApi
.createDraft(cqlLibrary.id, cqlLibrary.cqlLibraryName)
.createDraft(cqlLibrary.id, cqlLibrary.cqlLibraryName, model)
.then(async () => {
handleDialogClose();
await onListUpdate();
Expand Down Expand Up @@ -246,7 +246,7 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) {
cqlLibraryError={createVersionDialog.cqlLibraryError}
isCqlPresent={createVersionDialog.isCqlPresent}
/>
<CreatDraftDialog
<CreateDraftDialog
open={createDraftDialog.open}
onClose={handleDialogClose}
onSubmit={createDraft}
Expand Down
96 changes: 75 additions & 21 deletions src/components/createDraftDialog/CreateDraftDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { CqlLibrary, Model } from "@madie/madie-models";
import CreatDraftDialog from "./CreateDraftDialog";
import CreateDraftDialog from "./CreateDraftDialog";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import clearAllMocks = jest.clearAllMocks;
Expand All @@ -18,16 +18,23 @@ const cqlLibrary: CqlLibrary = {
draft: true,
version: "0.0.000",
cql: "library TestLib version '0.0.000'\nusing QICore version '4.1.1'\n",
active: true,
};

jest.mock("@madie/madie-util", () => ({
useFeatureFlags: jest.fn().mockReturnValue({
qiCore6: true,
}),
}));

describe("Create Draft Dialog component", () => {
beforeEach(() => {
clearAllMocks();
});

it("should render Draft dialog with cql library name", () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -42,7 +49,7 @@ describe("Create Draft Dialog component", () => {

it("should generate field level error for required Cql Library name", async () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -60,9 +67,50 @@ describe("Create Draft Dialog component", () => {
});
});

it("should display a model version option for QI-Core measures", async () => {
render(
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
cqlLibrary={cqlLibrary}
/>
);
const cqlLibraryName = (await screen.findByRole("textbox", {
name: "CQL Library Name",
})) as HTMLInputElement;
expect(cqlLibraryName.value).toEqual(cqlLibrary.cqlLibraryName);
expect(await screen.findByText("Create Draft")).toBeInTheDocument();
expect(await screen.findByText("Update Model Version")).toBeInTheDocument();
expect(await screen.findByText("QI-Core v4.1.1")).toBeInTheDocument();

expect(screen.getByTestId("create-draft-continue-button")).toBeEnabled();
});

it("should not display a model version option for QDM measures", async () => {
const qdmLibrary = Object.assign({}, cqlLibrary);
qdmLibrary.model = Model.QDM_5_6;
render(
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
cqlLibrary={qdmLibrary}
/>
);
expect(await screen.findByText("Create Draft")).toBeInTheDocument();
const cqlLibraryName = (await screen.findByRole("textbox", {
name: "CQL Library Name",
})) as HTMLInputElement;
expect(cqlLibraryName.value).toEqual(cqlLibrary.cqlLibraryName);
expect(screen.queryByText("Update Model Version")).not.toBeInTheDocument();

expect(screen.getByTestId("create-draft-continue-button")).toBeEnabled();
});

it("should generate field level error for at least one alphabet in cql library name", async () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -85,7 +133,7 @@ describe("Create Draft Dialog component", () => {

it("should generate field level error for underscore in cql library name", async () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -108,7 +156,7 @@ describe("Create Draft Dialog component", () => {

it("should generate field level error for library name starting with lower case", async () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -131,7 +179,7 @@ describe("Create Draft Dialog component", () => {

it("should generate field level error for library name with a space", async () => {
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={jest.fn()}
Expand All @@ -155,7 +203,7 @@ describe("Create Draft Dialog component", () => {
it("should navigate to cql library home page on cancel", async () => {
const onCloseFn = jest.fn();
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={onCloseFn}
onSubmit={jest.fn()}
Expand All @@ -169,7 +217,7 @@ describe("Create Draft Dialog component", () => {
it("should not change cql but continue drafting by calling onSubmit when user does not rename library", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={onSubmitFn}
Expand All @@ -182,14 +230,14 @@ describe("Create Draft Dialog component", () => {
expect(cqlLibraryNameInput.value).toBe(cqlLibrary.cqlLibraryName);
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalledWith(cqlLibrary);
expect(onSubmitFn).toHaveBeenCalledWith(cqlLibrary, cqlLibrary.model);
});
});

it("should update the cql and continue drafting by calling onSubmit when user renames the library", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={onSubmitFn}
Expand All @@ -203,16 +251,19 @@ describe("Create Draft Dialog component", () => {
userEvent.type(cqlLibraryNameInput, "TestingLibraryName12");
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalledWith({
...cqlLibrary,
cqlLibraryName: "TestingLibraryName12",
});
expect(onSubmitFn).toHaveBeenCalledWith(
{
...cqlLibrary,
cqlLibraryName: "TestingLibraryName12",
},
"QI-Core v4.1.1"
);
});
});
it("should not update cql even if user renames library when there is no cql", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
<CreateDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={onSubmitFn}
Expand All @@ -226,11 +277,14 @@ describe("Create Draft Dialog component", () => {
userEvent.type(cqlLibraryNameInput, "TestingLibraryName12");
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalledWith({
...cqlLibrary,
cqlLibraryName: "TestingLibraryName12",
cql: null,
});
expect(onSubmitFn).toHaveBeenCalledWith(
{
...cqlLibrary,
cqlLibraryName: "TestingLibraryName12",
cql: null,
},
"QI-Core v4.1.1"
);
});
});
});
Loading

0 comments on commit 45d8e22

Please sign in to comment.