Update app routes test
This commit is contained in:
@@ -1,8 +1,78 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from '.';
|
||||
jest.mock("../Contexts/UserContext");
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
import { render, screen, cleanup, waitFor } from "@testing-library/react"
|
||||
import { setToken } from "../Contexts/UserContext";
|
||||
import App from ".";
|
||||
|
||||
const TEST_TOKEN = { accessToken: { jwtToken: "TEST" }};
|
||||
|
||||
describe.only("App", () => {
|
||||
|
||||
it ("Route / unauthenticated", async () => {
|
||||
setToken(null);
|
||||
window.history.pushState({}, "", "/");
|
||||
const { container } = render(<App />);
|
||||
// need 2 cycles to render due to routes
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Sign in");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it ("Route /signup unauthenticated", async () => {
|
||||
setToken(null);
|
||||
window.history.pushState({}, "", "/signup");
|
||||
const { container } = render(<App />);
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Sign up");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it ("Route /home unauthenticated", async () => {
|
||||
setToken(null);
|
||||
window.history.pushState({}, "", "/home");
|
||||
const { container } = render(<App />);
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Sign in");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it ("Route / authenticated", async () => {
|
||||
setToken(TEST_TOKEN);
|
||||
window.history.pushState({}, "", "/");
|
||||
const { container } = render(<App />);
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it ("Route /signup authenticated", async () => {
|
||||
setToken(TEST_TOKEN);
|
||||
window.history.pushState({}, "", "/signup");
|
||||
const { container } = render(<App />);
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it ("Route /home authenticated", async () => {
|
||||
setToken(TEST_TOKEN);
|
||||
window.history.pushState({}, "", "/home");
|
||||
const { container } = render(<App />);
|
||||
await waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user