Skip to content

Commit

Permalink
Merge pull request #148 from MeasureAuthoringTool/MAT-7372
Browse files Browse the repository at this point in the history
MAT-7372 CQL Library: Unable to draft a library
  • Loading branch information
adongare authored Jun 27, 2024
2 parents 9b7d388 + b1c69af commit 40b2cc3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/components/cqlLibraryList/CqlLibraryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Button,
MadieDeleteDialog,
} from "@madie/madie-design-system/dist/react";
import _ from "lodash";

const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
props,
Expand Down
65 changes: 50 additions & 15 deletions src/components/createDraftDialog/CreateDraftDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const cqlLibrary: CqlLibrary = {
cqlErrors: false,
librarySetId: "",
id: "622e1f46d1fd3729d861e6cb",
cqlLibraryName: "testing1",
cqlLibraryName: "TestLib",
model: Model.QICORE,
createdAt: null,
createdBy: null,
lastModifiedAt: null,
lastModifiedBy: null,
draft: true,
version: "0.0.000",
cql: null,
cql: "library TestLib version '0.0.000'\nusing QICore version '4.1.1'\n",
};

describe("Create Draft Dialog component", () => {
Expand All @@ -37,7 +37,7 @@ describe("Create Draft Dialog component", () => {
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(
screen.getByRole("textbox", { name: "CQL Library Name" })
).toHaveValue("testing1");
).toHaveValue(cqlLibrary.cqlLibraryName);
});

it("should generate field level error for required Cql Library name", async () => {
Expand Down Expand Up @@ -152,33 +152,41 @@ describe("Create Draft Dialog component", () => {
});
});

it("should have continue button disabled until form is valid", async () => {
it("should navigate to cql library home page on cancel", async () => {
const onCloseFn = jest.fn();
render(
<CreatDraftDialog
open={true}
onClose={jest.fn()}
onClose={onCloseFn}
onSubmit={jest.fn()}
cqlLibrary={cqlLibrary}
/>
);
expect(screen.getByRole("button", { name: "Continue" })).not.toBeDisabled();
userEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(onCloseFn).toHaveBeenCalled();
});

it("should navigate to cql library home page on cancel", async () => {
const onCloseFn = jest.fn();
it("should not change cql but continue drafting by calling onSubmit when user does not rename library", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
open={true}
onClose={onCloseFn}
onSubmit={jest.fn()}
onClose={jest.fn()}
onSubmit={onSubmitFn}
cqlLibrary={cqlLibrary}
/>
);
userEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(onCloseFn).toHaveBeenCalled();
const cqlLibraryNameInput = screen.getByRole("textbox", {
name: "CQL Library Name",
}) as HTMLInputElement;
expect(cqlLibraryNameInput.value).toBe(cqlLibrary.cqlLibraryName);
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalledWith(cqlLibrary);
});
});

it("should continue drafting by calling onSubmit", async () => {
it("should update the cql and continue drafting by calling onSubmit when user renames the library", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
Expand All @@ -193,10 +201,37 @@ describe("Create Draft Dialog component", () => {
});
userEvent.clear(cqlLibraryNameInput);
userEvent.type(cqlLibraryNameInput, "TestingLibraryName12");
expect(screen.getByRole("button", { name: "Continue" })).not.toBeDisabled();
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalled();
expect(onSubmitFn).toHaveBeenCalledWith({
...cqlLibrary,
cql: "library TestingLibraryName12 version '0.0.000'\nusing QICore version '4.1.1'\n",
cqlLibraryName: "TestingLibraryName12",
});
});
});
it("should not update cql even if user renames library when there is no cql", async () => {
const onSubmitFn = jest.fn();
render(
<CreatDraftDialog
open={true}
onClose={jest.fn()}
onSubmit={onSubmitFn}
cqlLibrary={{ ...cqlLibrary, cql: null }}
/>
);
const cqlLibraryNameInput = screen.getByRole("textbox", {
name: "CQL Library Name",
});
userEvent.clear(cqlLibraryNameInput);
userEvent.type(cqlLibraryNameInput, "TestingLibraryName12");
userEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => {
expect(onSubmitFn).toHaveBeenCalledWith({
...cqlLibrary,
cqlLibraryName: "TestingLibraryName12",
cql: null,
});
});
});
});
29 changes: 16 additions & 13 deletions src/components/createDraftDialog/CreateDraftDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { DialogContent, Box, Typography } from "@mui/material";
import { useFormik } from "formik";
import * as Yup from "yup";
import { CqlLibrary } from "@madie/madie-models";
import { synchingEditorCqlContent } from "@madie/madie-editor";
import { MadieDialog, TextField } from "@madie/madie-design-system/dist/react";
import _ from "lodash";

interface CreateDraftDialogProps {
open: boolean;
Expand Down Expand Up @@ -40,18 +38,23 @@ const CreatDraftDialog = ({
});

const submitForm = async (cqlLibraryName: string) => {
const cqlModelInfo: string[] = _.split(cqlLibrary?.model, " v", 2);
const inSyncCql = await synchingEditorCqlContent(
"",
cqlLibrary?.cql,
const cqlContents = cqlLibrary?.cql?.split("\n");
let cql = cqlLibrary?.cql;
const previousLibraryName = cqlLibrary?.cqlLibraryName;
// make sure cql is updated with new library name, if it is changed
if (
previousLibraryName !== cqlLibraryName &&
cql &&
cqlContents[0].includes(cqlLibrary.cqlLibraryName)
) {
cqlContents[0] = `library ${cqlLibraryName} version '${cqlLibrary.version}'`;
cql = cqlContents.join("\n");
}
return onSubmit({
...cqlLibrary,
cqlLibraryName,
cqlLibrary?.cqlLibraryName,
cqlLibrary?.version,
cqlModelInfo[0],
cqlModelInfo[1],
"draftDialog"
);
return onSubmit({ ...cqlLibrary, cqlLibraryName, cql: inSyncCql });
cql,
});
};

return (
Expand Down

0 comments on commit 40b2cc3

Please sign in to comment.