From 4f92a7e88e04eb33730e6e725b2453555f2e78ae Mon Sep 17 00:00:00 2001 From: adongare Date: Wed, 26 Jun 2024 18:21:00 -0400 Subject: [PATCH 1/5] MAT-7372 CQL Library: Unable to draft a library --- src/components/cqlLibraryList/CqlLibraryList.tsx | 1 - .../createDraftDialog/CreateDraftDialog.test.tsx | 6 ++++++ src/components/createDraftDialog/CreateDraftDialog.tsx | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/cqlLibraryList/CqlLibraryList.tsx b/src/components/cqlLibraryList/CqlLibraryList.tsx index 128f7f2..32b72bd 100644 --- a/src/components/cqlLibraryList/CqlLibraryList.tsx +++ b/src/components/cqlLibraryList/CqlLibraryList.tsx @@ -15,7 +15,6 @@ import { Button, MadieDeleteDialog, } from "@madie/madie-design-system/dist/react"; -import _ from "lodash"; const Alert = React.forwardRef(function Alert( props, diff --git a/src/components/createDraftDialog/CreateDraftDialog.test.tsx b/src/components/createDraftDialog/CreateDraftDialog.test.tsx index 4fcc956..fa95eb3 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.test.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.test.tsx @@ -20,6 +20,12 @@ const cqlLibrary: CqlLibrary = { cql: null, }; +jest.mock("@madie/madie-editor", () => ({ + synchingEditorCqlContent: jest.fn().mockResolvedValue({ + cql: "library testing1 version '0.0.000'", + }), +})); + describe("Create Draft Dialog component", () => { beforeEach(() => { clearAllMocks(); diff --git a/src/components/createDraftDialog/CreateDraftDialog.tsx b/src/components/createDraftDialog/CreateDraftDialog.tsx index b26894c..1a36d57 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.tsx @@ -41,7 +41,7 @@ const CreatDraftDialog = ({ const submitForm = async (cqlLibraryName: string) => { const cqlModelInfo: string[] = _.split(cqlLibrary?.model, " v", 2); - const inSyncCql = await synchingEditorCqlContent( + const editorContents = await synchingEditorCqlContent( "", cqlLibrary?.cql, cqlLibraryName, @@ -51,7 +51,11 @@ const CreatDraftDialog = ({ cqlModelInfo[1], "draftDialog" ); - return onSubmit({ ...cqlLibrary, cqlLibraryName, cql: inSyncCql }); + return onSubmit({ + ...cqlLibrary, + cqlLibraryName, + cql: editorContents?.cql, + }); }; return ( From 5138811de9a5bc60b3f06a809300c3d8696ae620 Mon Sep 17 00:00:00 2001 From: adongare Date: Wed, 26 Jun 2024 18:56:18 -0400 Subject: [PATCH 2/5] MAT-7372 CQL Library: Unable to draft a library --- src/components/createDraftDialog/CreateDraftDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/createDraftDialog/CreateDraftDialog.tsx b/src/components/createDraftDialog/CreateDraftDialog.tsx index 1a36d57..02ed997 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.tsx @@ -54,7 +54,7 @@ const CreatDraftDialog = ({ return onSubmit({ ...cqlLibrary, cqlLibraryName, - cql: editorContents?.cql, + cql: editorContents?.cql || editorContents, }); }; From 636c8d703889e5e4b5ddb0ec43916b9dfd6879b2 Mon Sep 17 00:00:00 2001 From: adongare Date: Thu, 27 Jun 2024 08:40:47 -0400 Subject: [PATCH 3/5] MAT-7372 CQL Library: Unable to draft a library --- .../CreateDraftDialog.test.tsx | 41 +++++++++++++------ .../createDraftDialog/CreateDraftDialog.tsx | 24 +++++------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/components/createDraftDialog/CreateDraftDialog.test.tsx b/src/components/createDraftDialog/CreateDraftDialog.test.tsx index fa95eb3..4170557 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.test.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.test.tsx @@ -9,7 +9,7 @@ const cqlLibrary: CqlLibrary = { cqlErrors: false, librarySetId: "", id: "622e1f46d1fd3729d861e6cb", - cqlLibraryName: "testing1", + cqlLibraryName: "TestLib", model: Model.QICORE, createdAt: null, createdBy: null, @@ -17,15 +17,9 @@ const cqlLibrary: CqlLibrary = { lastModifiedBy: null, draft: true, version: "0.0.000", - cql: null, + cql: "library TestLib version '0.0.000'\nusing QICore version '4.1.1'\n", }; -jest.mock("@madie/madie-editor", () => ({ - synchingEditorCqlContent: jest.fn().mockResolvedValue({ - cql: "library testing1 version '0.0.000'", - }), -})); - describe("Create Draft Dialog component", () => { beforeEach(() => { clearAllMocks(); @@ -43,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 () => { @@ -184,7 +178,27 @@ describe("Create Draft Dialog component", () => { expect(onCloseFn).toHaveBeenCalled(); }); - it("should continue drafting by calling onSubmit", async () => { + it("should not change cql but continue drafting by calling onSubmit when user does not rename library", async () => { + const onSubmitFn = jest.fn(); + render( + + ); + 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 update the cql and continue drafting by calling onSubmit when user renames the library", async () => { const onSubmitFn = jest.fn(); render( { }); 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", + }); }); }); }); diff --git a/src/components/createDraftDialog/CreateDraftDialog.tsx b/src/components/createDraftDialog/CreateDraftDialog.tsx index 02ed997..803ae10 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.tsx @@ -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; @@ -40,21 +38,19 @@ const CreatDraftDialog = ({ }); const submitForm = async (cqlLibraryName: string) => { - const cqlModelInfo: string[] = _.split(cqlLibrary?.model, " v", 2); - const editorContents = await synchingEditorCqlContent( - "", - cqlLibrary?.cql, - cqlLibraryName, - cqlLibrary?.cqlLibraryName, - cqlLibrary?.version, - cqlModelInfo[0], - cqlModelInfo[1], - "draftDialog" - ); + 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?.includes(cqlLibrary.cqlLibraryName) + ) { + cql = cql.replace(previousLibraryName, cqlLibraryName); + } return onSubmit({ ...cqlLibrary, cqlLibraryName, - cql: editorContents?.cql || editorContents, + cql, }); }; From 3c3361b9f701587052e62b8ff082e73fbaefc24b Mon Sep 17 00:00:00 2001 From: adongare Date: Thu, 27 Jun 2024 08:43:39 -0400 Subject: [PATCH 4/5] MAT-7372 delete redundant test case --- .../createDraftDialog/CreateDraftDialog.test.tsx | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/components/createDraftDialog/CreateDraftDialog.test.tsx b/src/components/createDraftDialog/CreateDraftDialog.test.tsx index 4170557..dc81893 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.test.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.test.tsx @@ -152,18 +152,6 @@ describe("Create Draft Dialog component", () => { }); }); - it("should have continue button disabled until form is valid", async () => { - render( - - ); - expect(screen.getByRole("button", { name: "Continue" })).not.toBeDisabled(); - }); - it("should navigate to cql library home page on cancel", async () => { const onCloseFn = jest.fn(); render( From b1c69afe6fb1d8705e9f1ea70f83449bf72c5130 Mon Sep 17 00:00:00 2001 From: adongare Date: Thu, 27 Jun 2024 09:08:03 -0400 Subject: [PATCH 5/5] MAT-7372 CQL Library: Unable to draft a library --- .../CreateDraftDialog.test.tsx | 24 +++++++++++++++++++ .../createDraftDialog/CreateDraftDialog.tsx | 7 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/createDraftDialog/CreateDraftDialog.test.tsx b/src/components/createDraftDialog/CreateDraftDialog.test.tsx index dc81893..b84c99e 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.test.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.test.tsx @@ -210,4 +210,28 @@ describe("Create Draft Dialog component", () => { }); }); }); + it("should not update cql even if user renames library when there is no cql", async () => { + const onSubmitFn = jest.fn(); + render( + + ); + 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, + }); + }); + }); }); diff --git a/src/components/createDraftDialog/CreateDraftDialog.tsx b/src/components/createDraftDialog/CreateDraftDialog.tsx index 803ae10..5b23e41 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.tsx @@ -38,14 +38,17 @@ const CreatDraftDialog = ({ }); const submitForm = async (cqlLibraryName: string) => { + 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?.includes(cqlLibrary.cqlLibraryName) + cql && + cqlContents[0].includes(cqlLibrary.cqlLibraryName) ) { - cql = cql.replace(previousLibraryName, cqlLibraryName); + cqlContents[0] = `library ${cqlLibraryName} version '${cqlLibrary.version}'`; + cql = cqlContents.join("\n"); } return onSubmit({ ...cqlLibrary,