-
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(actions): add more tests for form actions
- Loading branch information
1 parent
4fa4962
commit b988c5b
Showing
13 changed files
with
293 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { rest } from "msw"; | ||
import { BASE_TEST_URL } from "./_utils"; | ||
|
||
const FORM_ACTIONS = [ | ||
{ | ||
id: "1", | ||
integration: "http", | ||
entity: "test-entity-1", | ||
trigger: "create", | ||
action: "POST", | ||
configuration: { | ||
url: "http://localhost:3000", | ||
method: "GET", | ||
}, | ||
}, | ||
{ | ||
id: "2", | ||
integration: "smtp", | ||
entity: "test-entity-1", | ||
trigger: "update", | ||
action: "SEND_MAIL", | ||
configuration: { | ||
url: "http://localhost:3000", | ||
method: "GET", | ||
}, | ||
}, | ||
{ | ||
id: "3", | ||
integration: "slack", | ||
entity: "test-entity-1", | ||
trigger: "delete", | ||
action: "SEND_MESSAGE", | ||
configuration: { | ||
url: "http://localhost:3000", | ||
method: "GET", | ||
}, | ||
}, | ||
]; | ||
|
||
export const formActionsApiHandlers = [ | ||
rest.get(BASE_TEST_URL("/api/form-actions/:entity"), async (_, res, ctx) => { | ||
return res(ctx.json(FORM_ACTIONS)); | ||
}), | ||
rest.post(BASE_TEST_URL("/api/form-actions"), async (req, res, ctx) => { | ||
const newFormAction = await req.json(); | ||
FORM_ACTIONS.push(newFormAction); | ||
if ( | ||
JSON.stringify(newFormAction) === | ||
'{"configuration":{"channel":"{ CONSTANTS.SLACK_CHANNEL }}","message":"Hello how are youHello how are you","shouldNotify":true},"entity":"test-entity","trigger":"create","integration":"slack","action":"send_message"}' | ||
) { | ||
return res(ctx.status(204)); | ||
} | ||
return res(ctx.status(400)); | ||
}), | ||
rest.patch( | ||
BASE_TEST_URL("/api/form-actions/:formActionId"), | ||
async (req, res, ctx) => { | ||
const formActionId = req.params.formActionId as string; | ||
const formAction = await req.json(); | ||
|
||
const index = FORM_ACTIONS.findIndex(({ id }) => id === formActionId); | ||
|
||
FORM_ACTIONS[index] = formAction; | ||
|
||
return res(ctx.status(204)); | ||
} | ||
), | ||
rest.delete( | ||
BASE_TEST_URL("/api/form-actions/:formActionId"), | ||
async (req, res, ctx) => { | ||
const formActionId = req.params.formActionId as string; | ||
|
||
FORM_ACTIONS.splice( | ||
FORM_ACTIONS.findIndex(({ id }) => id === formActionId), | ||
1 | ||
); | ||
|
||
return res(ctx.status(204)); | ||
} | ||
), | ||
]; |
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
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,125 @@ | ||
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"; | ||
|
||
setupApiHandlers(); | ||
|
||
describe("pages/admin/[entity]/config/actions", () => { | ||
beforeAll(() => { | ||
const useRouter = jest.spyOn(require("next/router"), "useRouter"); | ||
useRouter.mockImplementation(() => ({ | ||
asPath: "/", | ||
query: { | ||
entity: "test-entity", | ||
}, | ||
isReady: true, | ||
})); | ||
}); | ||
|
||
it.skip("should list entity form actions", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings />x | ||
</ApplicationRoot> | ||
); | ||
|
||
expect(await screen.findByRole("table")).toBeInTheDocument(); | ||
|
||
expect(await getTableRows(screen.getByRole("table"))) | ||
.toMatchInlineSnapshot(` | ||
[ | ||
"Integration | ||
Trigger | ||
Action | ||
Action", | ||
"HttpCreatePost", | ||
"SmtpUpdateSend Mail", | ||
"SlackDeleteSend Message", | ||
] | ||
`); | ||
}); | ||
|
||
it("should create new form action successfully", async () => { | ||
render( | ||
<ApplicationRoot> | ||
<EntityFormActionsSettings /> | ||
</ApplicationRoot> | ||
); | ||
|
||
await userEvent.click( | ||
await screen.findByRole("button", { name: "Add New Form Action" }) | ||
); | ||
|
||
const dialog = screen.getByRole("dialog"); | ||
|
||
await userEvent.type(within(dialog).getByLabelText("Trigger"), "On Create"); | ||
await userEvent.keyboard("{Enter}"); | ||
|
||
await userEvent.click( | ||
within(dialog).getByRole("option", { name: "Slack" }) | ||
); | ||
|
||
expect( | ||
within(dialog).queryByRole("option", { name: "SMTP" }) | ||
).not.toBeInTheDocument(); | ||
|
||
await userEvent.type( | ||
within(dialog).getByLabelText("Action"), | ||
"Send Message" | ||
); | ||
await userEvent.keyboard("{Enter}"); | ||
|
||
await userEvent.type( | ||
await within(dialog).findByLabelText("Slack: Channel"), | ||
"{{ CONSTANTS.SLACK_CHANNEL }}" | ||
); | ||
|
||
await userEvent.type( | ||
within(dialog).getByLabelText("Slack: Message"), | ||
"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( | ||
within(dialog).getByRole("button", { name: "Create Form Action" }) | ||
); | ||
|
||
expect(await screen.findByRole("status")).toHaveTextContent( | ||
"Form Action Created Successfully" | ||
); | ||
|
||
expect( | ||
screen.queryByRole("button", { name: "Create Form Action" }) | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
// 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" | ||
// ); | ||
// }); | ||
}); |
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
Oops, something went wrong.