Skip to content

Commit

Permalink
🧪 test(actions): fe test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Mar 4, 2024
1 parent 00e8760 commit 29980c6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ yarn-error.log*

tsconfig.tsbuildinfo

.config-data/**/*.json
.config-data

dist/

Expand Down
7 changes: 5 additions & 2 deletions src/__tests__/admin/[entity]/config/crud__tab.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { rest } from "msw";

import { setupApiHandlers } from "__tests__/_/setupApihandlers";
import { BASE_TEST_URL } from "__tests__/_/api-handlers/_utils";
import { sluggify } from "shared/lib/strings";

const server = setupApiHandlers();

Expand Down Expand Up @@ -80,7 +81,9 @@ describe("pages/admin/[entity]/config/crud", () => {
})
).toBeVisible();

expect(replaceMock).toHaveBeenCalledWith(`/hello-there?foo=bar&tab=${tab}`);
expect(replaceMock).toHaveBeenCalledWith(
`/hello-there?foo=bar&tab=${sluggify(tab)}`
);
});

it("should default to the tab from query and be to go back to table", async () => {
Expand Down Expand Up @@ -132,6 +135,6 @@ describe("pages/admin/[entity]/config/crud", () => {
})
).toHaveTextContent("Table");

expect(replaceMock$1).toHaveBeenCalledWith("/?tab=Table");
expect(replaceMock$1).toHaveBeenCalledWith("/?tab=table");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe("/api/dashboards/[dashboardId]/[widgetId]/index", () => {
expect(deleteRequest.res._getStatusCode()).toBe(400);
expect(deleteRequest.res._getJSONData()).toMatchInlineSnapshot(`
{
"message": "This service is not available on the demo site",
"message": "This action is not available on the demo site",
"method": "DELETE",
"name": "BadRequestError",
"path": "",
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/api/dashboards/[dashboardId]/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("/api/dashboards/[dashboardId]/index", () => {

describe("/api/dashboards/[dashboardId]/index generation", () => {
beforeAll(async () => {
await setupAllTestData(["schema", "app-config"]);
await setupAllTestData(["schema", "app-config", "credentials"]);
await setupDashboardTestData([]);
});

Expand All @@ -203,7 +203,6 @@ describe("/api/dashboards/[dashboardId]/index generation", () => {

await handler(req, res);

expect(res._getStatusCode()).toBe(200);
expect(res._getJSONData()).toMatchInlineSnapshot(`
[
{
Expand Down
56 changes: 56 additions & 0 deletions src/__tests__/integrations/actions/[key].spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { ApplicationRoot } from "frontend/components/ApplicationRoot";

import ActionsIntegrations from "pages/integrations/actions/[key]";

import { setupApiHandlers } from "__tests__/_/setupApihandlers";
// import userEvent from "@testing-library/user-event";
// import { closeAllToasts } from "__tests__/_/utils/closeAllToasts";

setupApiHandlers();

describe("pages/integrations/actions/[key]", () => {
const useRouter = jest.spyOn(require("next/router"), "useRouter");
beforeAll(() => {
useRouter.mockImplementation(() => ({
asPath: "/",
query: {
key: "slack",
},
isReady: true,
}));
});

describe("list", () => {
it("should show the list of actions", async () => {
render(
<ApplicationRoot>
<ActionsIntegrations />
</ApplicationRoot>
);

expect(
await screen.findByRole("link", { name: "Slack" })
).toBeInTheDocument();
expect(screen.getByRole("link", { name: "HTTP" })).toBeInTheDocument();
expect(
screen.getByRole("link", { name: "Non Activated Actions" })
).toBeInTheDocument();
});

// it("should show the configure UI for activated actions", async () => {
// render(
// <ApplicationRoot>
// <ActionsIntegrations />
// </ApplicationRoot>
// );

// await waitFor(() => {
// expect(
// screen.getByRole("option", { selected: true })
// ).toHaveTextContent("Slack");
// });
// });
});
});
22 changes: 16 additions & 6 deletions src/__tests__/integrations/variables__credentials.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ describe("pages/integrations/variables => credentials", () => {
await screen.findByRole("tab", { name: "Secrets" })
);

const table = screen.getByRole("table");
const table = within(
screen.getByRole("tabpanel", { name: "Secrets" })
).getByRole("table");

expect(
await within(table).findByRole("row", {
Expand Down Expand Up @@ -183,7 +185,9 @@ describe("pages/integrations/variables => credentials", () => {
"Invalid Password"
);

const table = screen.getByRole("table");
const table = within(
screen.getByRole("tabpanel", { name: "Secrets" })
).getByRole("table");

expect(
await within(table).findByRole("row", {
Expand Down Expand Up @@ -223,7 +227,9 @@ describe("pages/integrations/variables => credentials", () => {
})
);

const table = screen.getByRole("table");
const table = within(
screen.getByRole("tabpanel", { name: "Secrets" })
).getByRole("table");

expect(
await within(table).findByRole("row", {
Expand Down Expand Up @@ -323,7 +329,9 @@ describe("pages/integrations/variables => credentials", () => {
await screen.findByRole("tab", { name: "Secrets" })
);

const table = screen.getByRole("table");
const table = within(
screen.getByRole("tabpanel", { name: "Secrets" })
).getByRole("table");

expect(
await within(table).findByRole(
Expand Down Expand Up @@ -436,7 +444,9 @@ describe("pages/integrations/variables => credentials", () => {
await screen.findByRole("tab", { name: "Secrets" })
);

const tableRows = await screen.findAllByRole("row");
const table = screen.getByRole("tabpanel", { name: "Secrets" });

const tableRows = await within(table).findAllByRole("row");

expect(tableRows).toHaveLength(5);

Expand All @@ -454,7 +464,7 @@ describe("pages/integrations/variables => credentials", () => {
await within(confirmBox).findByRole("button", { name: "Confirm" })
);

expect(await screen.findAllByRole("row")).toHaveLength(4);
expect(await within(table).findAllByRole("row")).toHaveLength(4);

expect((await screen.findAllByRole("status"))[0]).toHaveTextContent(
"Secret Deleted Successfully"
Expand Down

0 comments on commit 29980c6

Please sign in to comment.