Skip to content

Commit

Permalink
MAT-7935 add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Dec 31, 2024
1 parent 028d691 commit b0aa405
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/CqlBuilderPanel/definitionsSection/DefinitionsSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ describe("DefinitionsSection", () => {
expect(screen.queryByTestId("edit-button-1")).not.toBeInTheDocument();

expect(screen.queryByTestId("view-button-0")).toBeInTheDocument();
// check if view dialog is editable
userEvent.click(screen.queryByTestId("view-button-0"));
const definitionName = screen.getByTestId("definition-name-text-input");
expect(definitionName).toHaveValue("SDE Sex");
expect(definitionName).toHaveAttribute("disabled");
});

it("Should render edit definition dialog on edit button click", async () => {
Expand Down Expand Up @@ -204,5 +209,51 @@ describe("DefinitionsSection", () => {
);
const returnType = screen.getByTestId("return-type");
expect(returnType).toHaveTextContent(getCqlDefinitionReturnTypes().sdeSex);
// close the dialog
const button = screen.getByRole("button", { name: "Close" });
userEvent.click(button);

// perform delete action, should display delete confirmation dialog
userEvent.click(screen.queryByTestId("delete-button-0"));
expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
userEvent.click(screen.getByRole("button", { name: "Yes, Delete" }));
expect(props.handleDefinitionDelete).toHaveBeenCalled();
});

it("Should show discard dialog if CQL is dirty on edit btn click", async () => {
const getCqlDefinitionReturnTypes = () => {
return {
sdeSex: "PatientCharacteristicSex",
};
};
render(
<DefinitionsSection
{...props}
isCQLUnchanged={false}
cql={
'/*\n this is SDE Sex definition\n*/ \ndefine "SDE Sex":\n SDE."SDE Sex"'
}
cqlBuilderLookupsTypes={cqlBuilderLookup}
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
/>
);
// go to saved definitions tab
const savedDefinitionsTab = screen.getByRole("tab", {
name: /Saved Definitions/i,
});
expect(savedDefinitionsTab).toBeInTheDocument();
userEvent.click(savedDefinitionsTab);
const table = screen.getByRole("table");
expect(table).toBeInTheDocument();

// perform delete if cql is dirty, should display discard confirmation
userEvent.click(screen.queryByTestId("delete-button-0"));
expect(screen.getByTestId("discard-dialog")).toBeInTheDocument();
userEvent.click(
screen.getByRole("button", { name: "Yes, Discard All Changes" })
);
expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
userEvent.click(screen.getByRole("button", { name: "Yes, Delete" }));
expect(props.handleDefinitionDelete).toHaveBeenCalled();
});
});

0 comments on commit b0aa405

Please sign in to comment.