Skip to content

Commit

Permalink
MAT-7372 CQL Library: Unable to draft a library
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Jun 27, 2024
1 parent 3c3361b commit b1c69af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/components/createDraftDialog/CreateDraftDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<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,
});
});
});
});
7 changes: 5 additions & 2 deletions src/components/createDraftDialog/CreateDraftDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b1c69af

Please sign in to comment.