66 lines
2.7 KiB
TypeScript
66 lines
2.7 KiB
TypeScript
import React from "react";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { MockedProvider } from "@apollo/client/testing";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import Main from "./Main";
|
|
import { SnackbarProvider } from "notistack";
|
|
|
|
function renderMainPage() {
|
|
render(
|
|
<MockedProvider>
|
|
<MemoryRouter>
|
|
<SnackbarProvider>
|
|
<Main />
|
|
</SnackbarProvider>
|
|
</MemoryRouter>
|
|
</MockedProvider>
|
|
);
|
|
}
|
|
|
|
describe("The main page", () => {
|
|
test("displays the editors page if an editor is logged in", () => {
|
|
const editorToken =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2FuZHltYXRfZWRpdG9yIiwicGVyc29uX3Jvd19pZCI6MSwiZXhwIjoxNjA5NDEyMTY4LCJpYXQiOjE2MDkyMzkzNjgsImF1ZCI6InBvc3RncmFwaGlsZSIsImlzcyI6InBvc3RncmFwaGlsZSJ9.kxdxmDrQw0vzD4tiXPj2fu-Cr8n7aWMikxntZ1ObF6c";
|
|
localStorage.setItem("token", editorToken);
|
|
renderMainPage();
|
|
|
|
// it renders question and category lists
|
|
const questionListHeadline = screen.queryByText(/Fragen/);
|
|
const categoryListHeadline = screen.queryByText(/Kategorien/);
|
|
expect(questionListHeadline).not.toBeNull();
|
|
expect(categoryListHeadline).not.toBeNull();
|
|
});
|
|
|
|
test("displays the candidates page if a candidate is logged in", () => {
|
|
const candidateToken =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2FuZHltYXRfY2FuZGlkYXRlIiwicGVyc29uX3Jvd19pZCI6MiwiZXhwIjoxNjA5NDEyMTY4LCJpYXQiOjE2MDkyMzkzNjgsImF1ZCI6InBvc3RncmFwaGlsZSIsImlzcyI6InBvc3RncmFwaGlsZSJ9.i66MDTPVWwfAvOawY25WE9OPb5CQ9hidoUruP91ngcg";
|
|
localStorage.setItem("token", candidateToken);
|
|
renderMainPage();
|
|
|
|
const questionListHeadline = screen.queryByText(/Fragen/);
|
|
const categoryListHeadline = screen.queryByText(/Kategorien/);
|
|
expect(questionListHeadline).not.toBeNull();
|
|
expect(categoryListHeadline).toBeNull();
|
|
});
|
|
|
|
test("displays the user page if an normal user is logged in", () => {
|
|
const userToken =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2FuZHltYXRfcGVyc29uIiwicGVyc29uX3Jvd19pZCI6MywiZXhwIjoxNjA5NDEyMTY4LCJpYXQiOjE2MDkyMzkzNjgsImF1ZCI6InBvc3RncmFwaGlsZSIsImlzcyI6InBvc3RncmFwaGlsZSJ9.RWo5USCmyn-OYjgYixq0y6qlObU9Rb0KdsxxvrtlW1o";
|
|
localStorage.setItem("token", userToken);
|
|
renderMainPage();
|
|
|
|
const placeholder = screen.queryByText(/nichts zu sehen/);
|
|
expect(placeholder).not.toBeNull();
|
|
});
|
|
|
|
test("displays a link to the loggin page if something is wrong with the token", () => {
|
|
const invalidToken =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2FuZHOYjgYixq0y6qlObU9Rb0KdsxxvrtlW1o";
|
|
localStorage.setItem("token", invalidToken);
|
|
renderMainPage();
|
|
|
|
const placeholder = screen.queryByRole("link", { name: /Login Seite/ });
|
|
expect(placeholder).not.toBeNull();
|
|
});
|
|
});
|