Skip to content

Commit

Permalink
MAT-7796: Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Dec 17, 2024
1 parent ff1fa3a commit 2c17201
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/CqlBuilderPanel/functionsSection/FunctionsSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,85 @@ describe("FunctionsSection", () => {
expect(screen.getByText("Edit")).toBeInTheDocument();
});
});

it("Should open edit dialog on click", async () => {
render(<FunctionsSection {...props} isCQLUnchanged={true} />);
const funct = await screen.findByTestId("function-tab");
const savedfunctions = await screen.findByText("Saved Functions (2)");
expect(funct).toBeInTheDocument();
expect(savedfunctions).toBeInTheDocument();
await waitFor(() => {
expect(funct).toHaveAttribute("aria-selected", "true");
});
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "false");
});
userEvent.click(savedfunctions);
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "true");
});
const editButon0 = screen.getByTestId("edit-button-0");
userEvent.click(editButon0);
await waitFor(() => {
expect(screen.getByText("Edit")).toBeInTheDocument();
});
});

it("Should close discard dialog on click", async () => {
render(<FunctionsSection {...props} isCQLUnchanged={false} />);
const funct = await screen.findByTestId("function-tab");
const savedfunctions = await screen.findByText("Saved Functions (2)");
expect(funct).toBeInTheDocument();
expect(savedfunctions).toBeInTheDocument();
await waitFor(() => {
expect(funct).toHaveAttribute("aria-selected", "true");
});
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "false");
});
userEvent.click(savedfunctions);
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "true");
});
const editButon0 = screen.getByTestId("edit-button-0");
userEvent.click(editButon0);
expect(screen.getByTestId("discard-dialog")).toBeInTheDocument();
expect(screen.getByText("Discard Changes?")).toBeInTheDocument();
const cancelBtn = screen.getByTestId("discard-dialog-cancel-button");
expect(cancelBtn).toBeInTheDocument();
userEvent.click(cancelBtn);

await waitFor(() => {
expect(screen.queryByTestId("discard-dialog")).not.toBeInTheDocument();
});
});

it("Should close edit dialog on click", async () => {
render(<FunctionsSection {...props} isCQLUnchanged={true} />);
const funct = await screen.findByTestId("function-tab");
const savedfunctions = await screen.findByText("Saved Functions (2)");
expect(funct).toBeInTheDocument();
expect(savedfunctions).toBeInTheDocument();
await waitFor(() => {
expect(funct).toHaveAttribute("aria-selected", "true");
});
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "false");
});
userEvent.click(savedfunctions);
await waitFor(() => {
expect(savedfunctions).toHaveAttribute("aria-selected", "true");
});
const editButon0 = screen.getByTestId("edit-button-0");
userEvent.click(editButon0);
await waitFor(() => {
expect(screen.getByText("Edit")).toBeInTheDocument();
});
const closeButton = screen.getByRole("button", { name: "Close" });
expect(closeButton).toBeInTheDocument();
userEvent.click(closeButton);
await waitFor(() => {
expect(screen.queryByTestId("discard-dialog")).not.toBeInTheDocument();
});
});
});

0 comments on commit 2c17201

Please sign in to comment.