79 lines
2.6 KiB
JavaScript
79 lines
2.6 KiB
JavaScript
jest.mock("../Contexts/UserContext");
|
|
jest.mock("../Contexts/FileUploadContext");
|
|
|
|
import { render, screen, cleanup, waitForElementToBeRemoved, waitFor } from "@testing-library/react"
|
|
import { setToken } from "../Contexts/UserContext";
|
|
import App from ".";
|
|
|
|
const TEST_TOKEN = { idToken: { jwtToken: "TEST" }};
|
|
const LOADING_STATUS = "Loading...";
|
|
|
|
const renderRoute = async (route) => {
|
|
window.history.pushState({}, "", route);
|
|
const { container } = render(<App />);
|
|
if (screen.queryByText(LOADING_STATUS)) {
|
|
await waitForElementToBeRemoved(() => screen.getByText(LOADING_STATUS));
|
|
}
|
|
return container;
|
|
};
|
|
|
|
describe("App", () => {
|
|
|
|
afterEach(() => {
|
|
setToken(null);
|
|
cleanup();
|
|
});
|
|
|
|
it("Route / unauthenticated", async () => {
|
|
const container = await renderRoute("/");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Sign in");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /signup unauthenticated", async () => {
|
|
const container = await renderRoute("/signup");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Sign up");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /home unauthenticated", async () => {
|
|
const container = await renderRoute("/home");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Sign in");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route / authenticated", async () => {
|
|
setToken(TEST_TOKEN);
|
|
const container = await renderRoute("/");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /signup authenticated", async () => {
|
|
setToken(TEST_TOKEN);
|
|
const container = await renderRoute("/signup");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /home authenticated", async () => {
|
|
setToken(TEST_TOKEN);
|
|
const container = await renderRoute("/home");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Upload file");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /page-not-found unauthenticated", async () => {
|
|
const container = await renderRoute("/page-not-found");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Page Not Found");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it("Route /page-not-found authenticated", async () => {
|
|
setToken(TEST_TOKEN);
|
|
const container = await renderRoute("/page-not-found");
|
|
expect(container.querySelector("h1").innerHTML).toEqual("Page Not Found");
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
}) |