Skip to content

Commit

Permalink
🧪 test(general): fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Apr 30, 2024
1 parent 3b9b754 commit 75b4468
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/account/preferences.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("pages/account/preferences", () => {
);

expect(await screen.findByRole("status")).toHaveTextContent(
"Theme Preference Saved Successfully"
"Account Preference Saved Successfully"
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/admin/settings/theme.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("pages/admin/settings/theme", () => {
);

expect((await screen.findAllByRole("status"))[1]).toHaveTextContent(
"Theme Preference Saved Successfully"
"Account Preference Saved Successfully"
);
});

Expand Down
37 changes: 37 additions & 0 deletions src/__tests__/setup/credentials.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BASE_TEST_URL } from "__tests__/_/api-handlers/_utils";
import CredentialsSetup from "pages/setup/credentials";
import userEvent from "@testing-library/user-event";
import { USE_ROUTER_PARAMS } from "__tests__/_/constants";
import { queryCache } from "frontend/lib/data/QueryClient";

const server = setupApiHandlers();

Expand Down Expand Up @@ -270,4 +271,40 @@ describe("pages/setup/credentials", () => {
expect(replaceMock).toHaveBeenCalledWith("/setup/user");
});
});

describe("redirect", () => {
beforeAll(() => {
queryCache.clear();
});

it("should redirect to users page DB credentials is set", async () => {
const replaceMock = jest.fn();

useRouter.mockImplementation(
USE_ROUTER_PARAMS({
replaceMock,
})
);

server.use(
rest.get(BASE_TEST_URL("/api/setup/check"), async (_, res, ctx) => {
return res(
ctx.json({
hasUsers: false,
hasDbCredentials: true,
})
);
})
);

render(
<ApplicationRoot>
<CredentialsSetup />
</ApplicationRoot>
);
await waitFor(() => {
expect(replaceMock).toHaveBeenCalledWith("/setup/user");
});
});
});
});
57 changes: 0 additions & 57 deletions src/__tests__/setup/credentials__users-redirect.spec.tsx

This file was deleted.

22 changes: 5 additions & 17 deletions src/frontend/_layouts/app/__tests__/AppLayout.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AuthActions } from "frontend/hooks/auth/auth.actions";
import userEvent from "@testing-library/user-event";
import { USE_ROUTER_PARAMS } from "__tests__/_/constants";
import { AppLayout } from "..";
import { getAppLayout } from "../getLayout";

setupApiHandlers();

Expand Down Expand Up @@ -80,13 +81,9 @@ describe("AppLayout", () => {
});
});

describe("Sidebar menu", () => {
describe("getAppLayout", () => {
it("should toggle the sidebar and toggle the correct elements", async () => {
render(
<ApplicationRoot>
<AppLayout>Foo</AppLayout>
</ApplicationRoot>
);
render(<ApplicationRoot>{getAppLayout(<p>Foo</p>)}</ApplicationRoot>);

expect(await screen.findByAltText("full logo")).toBeInTheDocument();
expect(screen.queryByAltText("small logo")).not.toBeInTheDocument();
Expand Down Expand Up @@ -124,11 +121,7 @@ describe("AppLayout", () => {
});

it("should open menu items", async () => {
render(
<ApplicationRoot>
<AppLayout>Foo</AppLayout>
</ApplicationRoot>
);
render(<ApplicationRoot>{getAppLayout(<p>Foo</p>)}</ApplicationRoot>);

await userEvent.click(
await screen.findByLabelText("Toggle Profile Menu")
Expand All @@ -145,12 +138,7 @@ describe("AppLayout", () => {
describe("Not Signed In", () => {
it("should redirect to sign in when not authenticated", async () => {
localStorage.removeItem(AuthActions.JWT_TOKEN_STORAGE_KEY);

render(
<ApplicationRoot>
<AppLayout>Foo</AppLayout>
</ApplicationRoot>
);
render(<ApplicationRoot>{getAppLayout(<p>Foo</p>)}</ApplicationRoot>);

await waitFor(() => {
expect(window.location.replace).toHaveBeenCalledWith("/auth");
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/views/settings/Variables/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function BaseManageVariables() {
);

const credentialsDomainMessages = useDomainMessages(
INTEGRATIONS_GROUP_CRUD_CONFIG.constants.domainDiction
INTEGRATIONS_GROUP_CRUD_CONFIG.credentials.domainDiction
);

return (
Expand Down

0 comments on commit 75b4468

Please sign in to comment.