Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7372 CQL Library: Unable to draft a library #148

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading