-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(form-actions): improve test coverage
- Loading branch information
1 parent
e6051a4
commit 8bc3507
Showing
24 changed files
with
262 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { waitFor, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
export const closeAllToasts = async () => { | ||
const toast = screen.getByRole("button", { | ||
name: "Close Toast", | ||
}); | ||
|
||
await userEvent.click(toast); | ||
|
||
await waitFor( | ||
() => { | ||
expect(toast).not.toBeInTheDocument(); | ||
}, | ||
{ timeout: 20000 } | ||
); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
/* eslint-disable testing-library/no-node-access */ | ||
/* eslint-disable testing-library/no-container */ | ||
import React from "react"; | ||
import { render, screen, within } from "@testing-library/react"; | ||
import { ApplicationRoot } from "frontend/components/ApplicationRoot"; | ||
import userEvent from "@testing-library/user-event"; | ||
import EntityFormActionsSettings from "pages/admin/[entity]/config/actions"; | ||
|
||
import { setupApiHandlers } from "__tests__/_/setupApihandlers"; | ||
import { getTableRows } from "__tests__/_/utiis/getTableRows"; | ||
import { getTableRows } from "__tests__/_/utils/getTableRows"; | ||
import { closeAllToasts } from "__tests__/_/utils/closeAllToasts"; | ||
|
||
setupApiHandlers(); | ||
|
||
|
@@ -23,7 +22,7 @@ describe("pages/admin/[entity]/config/actions", () => { | |
})); | ||
}); | ||
|
||
it.skip("should list entity form actions", async () => { | ||
it("should list entity form actions", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings />x | ||
|
@@ -89,11 +88,6 @@ describe("pages/admin/[entity]/config/actions", () => { | |
"Hello how are you" | ||
); | ||
|
||
await userEvent.type( | ||
within(dialog).getByLabelText("Slack: Message"), | ||
"Hello how are you" | ||
); | ||
|
||
await userEvent.click(screen.getByLabelText("Slack: Should Notify")); | ||
|
||
await userEvent.click( | ||
|
@@ -124,100 +118,185 @@ describe("pages/admin/[entity]/config/actions", () => { | |
"SlackCreateSend Message", | ||
] | ||
`); | ||
|
||
await closeAllToasts(); | ||
}); | ||
|
||
it("should delete form action successfully", async () => { | ||
it("should show the correct form values", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings /> | ||
</ApplicationRoot> | ||
); | ||
|
||
await userEvent.click(screen.getByRole("button", { name: "Close Toast" })); | ||
|
||
expect(await screen.findByRole("table")).toBeInTheDocument(); | ||
|
||
const tableRows = await screen.findAllByRole("row"); | ||
|
||
expect(tableRows).toHaveLength(5); | ||
await userEvent.click( | ||
within(tableRows[4]).getByRole("button", { | ||
name: "Edit Form Action", | ||
}) | ||
); | ||
|
||
const dialog = screen.getByRole("dialog"); | ||
// | ||
expect( | ||
within(dialog).getByTestId("react-select__trigger") | ||
).toHaveTextContent("On Create"); | ||
|
||
expect( | ||
within(dialog).getByRole("option", { selected: true }) | ||
).toHaveTextContent("Slack"); | ||
|
||
expect( | ||
within(dialog).getByTestId("react-select__action") | ||
).toHaveTextContent("Send Message - slack"); | ||
|
||
expect(await within(dialog).findByLabelText("Slack: Channel")).toHaveValue( | ||
"{ CONSTANTS.SLACK_CHANNEL }}" | ||
); | ||
expect(within(dialog).getByLabelText("Slack: Message")).toHaveValue( | ||
"Hello how are you" | ||
); | ||
expect(within(dialog).getByLabelText("Slack: Should Notify")).toBeChecked(); | ||
}); | ||
|
||
it("should update the actions form", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings /> | ||
</ApplicationRoot> | ||
); | ||
|
||
expect(await screen.findByRole("table")).toBeInTheDocument(); | ||
|
||
const tableRows = await screen.findAllByRole("row"); | ||
|
||
await userEvent.click( | ||
within(tableRows[1]).getByRole("button", { | ||
name: "Delete Form Action", | ||
within(tableRows[4]).getByRole("button", { | ||
name: "Edit Form Action", | ||
}) | ||
); | ||
|
||
const confirmBox = await screen.findByRole("alertdialog", { | ||
name: "Confirm Delete", | ||
}); | ||
const dialog = screen.getByRole("dialog"); | ||
|
||
await userEvent.type(within(dialog).getByLabelText("Trigger"), "On Delete"); | ||
await userEvent.keyboard("{Enter}"); | ||
|
||
await userEvent.click(within(dialog).getByRole("option", { name: "SMTP" })); | ||
|
||
await userEvent.type(within(dialog).getByLabelText("Action"), "Send Mail"); | ||
await userEvent.keyboard("{Enter}"); | ||
|
||
await userEvent.type( | ||
await within(dialog).findByLabelText("SMTP: From"), | ||
"{{ CONSTANTS.MAIL_FROM }}" | ||
); | ||
|
||
await userEvent.type( | ||
within(dialog).getByLabelText("SMTP: To"), | ||
"[email protected]" | ||
); | ||
|
||
await userEvent.click( | ||
await within(confirmBox).findByRole("button", { name: "Confirm" }) | ||
within(dialog).getByRole("button", { name: "Update Form Action" }) | ||
); | ||
|
||
expect(await screen.findByRole("status")).toHaveTextContent( | ||
"Form Action Deleted Successfully" | ||
"Form Action Updated Successfully" | ||
); | ||
|
||
expect(await screen.findAllByRole("row")).toHaveLength(4); | ||
await closeAllToasts(); | ||
|
||
expect(await getTableRows(screen.getByRole("table"))) | ||
.toMatchInlineSnapshot(` | ||
[ | ||
"Integration | ||
Trigger | ||
Action | ||
Action", | ||
"HttpCreatePost", | ||
"SmtpUpdateSend Mail", | ||
"SlackDeleteSend Message", | ||
"SmtpDeleteSend Mail", | ||
] | ||
`); | ||
}); | ||
|
||
it.skip("should show the correct value on the update form", async () => { | ||
const { container } = render( | ||
it("should show the correct form values", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings /> | ||
</ApplicationRoot> | ||
); | ||
|
||
await userEvent.click(screen.getByRole("button", { name: "Close Toast" })); | ||
|
||
expect(await screen.findByRole("table")).toBeInTheDocument(); | ||
|
||
const tableRows = await screen.findAllByRole("row"); | ||
|
||
await userEvent.click( | ||
within(tableRows[1]).getByRole("button", { | ||
within(tableRows[4]).getByRole("button", { | ||
name: "Edit Form Action", | ||
}) | ||
); | ||
|
||
const dialog = screen.getByRole("dialog"); | ||
// | ||
expect( | ||
within(dialog).getByTestId("react-select__trigger") | ||
).toHaveTextContent("On Delete"); | ||
|
||
const dialog = screen.getByRole("dialog"); | ||
expect( | ||
within(dialog).getByRole("option", { selected: true }) | ||
).toHaveTextContent("SMTP"); | ||
|
||
expect( | ||
within(dialog).getByTestId("react-select__action") | ||
).toHaveTextContent("Send Mail - smtp"); | ||
|
||
expect(await within(dialog).findByLabelText("SMTP: From")).toHaveValue( | ||
"[email protected]" | ||
"{ CONSTANTS.MAIL_FROM }}" | ||
); | ||
expect(within(dialog).getByLabelText("SMTP: To")).toHaveValue( | ||
"[email protected]" | ||
); | ||
}); | ||
|
||
expect(container.querySelector(`input[name="trigger"]`)).toHaveValue( | ||
"update" | ||
it("should delete form action successfully", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings /> | ||
</ApplicationRoot> | ||
); | ||
|
||
expect( | ||
within(dialog).getByRole("option", { selected: true }) | ||
).toHaveTextContent("SMTP"); | ||
expect(await screen.findByRole("table")).toBeInTheDocument(); | ||
|
||
expect( | ||
within(dialog).getByRole("option", { selected: true }) | ||
).toHaveTextContent("Send Mail"); | ||
}); | ||
const tableRows = await screen.findAllByRole("row"); | ||
|
||
expect(tableRows).toHaveLength(5); | ||
|
||
await userEvent.click( | ||
within(tableRows[1]).getByRole("button", { | ||
name: "Delete Form Action", | ||
}) | ||
); | ||
|
||
const confirmBox = await screen.findByRole("alertdialog", { | ||
name: "Confirm Delete", | ||
}); | ||
|
||
// it("should display updated diction values", async () => { | ||
// render( | ||
// <ApplicationRoot> | ||
// <EntityDictionSettings /> | ||
// </ApplicationRoot> | ||
// ); | ||
// await waitFor(() => { | ||
// expect(screen.getByLabelText("Plural")).toHaveValue( | ||
// "Plural entity-1Updated" | ||
// ); | ||
// }); | ||
// expect(screen.getByLabelText("Singular")).toHaveValue( | ||
// "Singular entity-1Updated" | ||
// ); | ||
// }); | ||
await userEvent.click( | ||
await within(confirmBox).findByRole("button", { name: "Confirm" }) | ||
); | ||
|
||
expect(await screen.findByRole("status")).toHaveTextContent( | ||
"Form Action Deleted Successfully" | ||
); | ||
|
||
expect(await screen.findAllByRole("row")).toHaveLength(4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.