2021-01-09 12:32:17 +01:00
|
|
|
import React from "react";
|
2021-02-08 00:00:12 +01:00
|
|
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
2021-01-09 12:32:17 +01:00
|
|
|
import { MockedProvider } from "@apollo/client/testing";
|
|
|
|
import { MemoryRouter } from "react-router-dom";
|
2020-12-31 11:36:23 +01:00
|
|
|
import Main from "./Main";
|
2021-01-09 12:32:17 +01:00
|
|
|
import { SnackbarProvider } from "notistack";
|
2021-02-07 22:18:05 +01:00
|
|
|
import { JwtPayload } from "../jwt/jwt";
|
2021-02-08 00:00:12 +01:00
|
|
|
import { queryAllMenuIconButtons } from "../integration-tests/test-helper";
|
2020-12-31 11:36:23 +01:00
|
|
|
|
2021-02-07 22:18:05 +01:00
|
|
|
function renderMainPage(jwt: JwtPayload) {
|
2021-01-09 12:32:17 +01:00
|
|
|
render(
|
|
|
|
<MockedProvider>
|
|
|
|
<MemoryRouter>
|
|
|
|
<SnackbarProvider>
|
2021-06-13 12:17:44 +02:00
|
|
|
<Main userRole={jwt.role} loggedInUserRowId={jwt.person_row_id} />
|
2021-01-09 12:32:17 +01:00
|
|
|
</SnackbarProvider>
|
|
|
|
</MemoryRouter>
|
|
|
|
</MockedProvider>
|
|
|
|
);
|
2020-12-31 11:36:23 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 22:18:05 +01:00
|
|
|
const baseJwt: JwtPayload = {
|
|
|
|
aud: "postgraphile",
|
|
|
|
exp: 0,
|
|
|
|
iat: 0,
|
|
|
|
iss: "postgraphile",
|
2022-02-02 13:13:34 +01:00
|
|
|
role: "kandimat_person",
|
2021-02-07 22:18:05 +01:00
|
|
|
person_row_id: 3,
|
|
|
|
};
|
|
|
|
|
2021-02-08 00:00:12 +01:00
|
|
|
describe("As an editor, the main page", () => {
|
|
|
|
const jwt: JwtPayload = {
|
|
|
|
...baseJwt,
|
2022-02-02 13:13:34 +01:00
|
|
|
role: "kandimat_editor",
|
2021-02-08 00:00:12 +01:00
|
|
|
person_row_id: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
test("displays the editor's home page", () => {
|
2021-02-07 22:18:05 +01:00
|
|
|
renderMainPage(jwt);
|
2020-12-31 11:36:23 +01:00
|
|
|
|
|
|
|
// it renders question and category lists
|
2021-02-07 22:18:05 +01:00
|
|
|
const questionListHeadline = screen.queryAllByText(/Fragen/);
|
2020-12-31 11:36:23 +01:00
|
|
|
const categoryListHeadline = screen.queryByText(/Kategorien/);
|
2021-02-07 22:18:05 +01:00
|
|
|
expect(questionListHeadline.length).toBeGreaterThan(0);
|
2020-12-31 11:36:23 +01:00
|
|
|
expect(categoryListHeadline).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
2021-02-08 00:00:12 +01:00
|
|
|
test("has a menu with two entries", async () => {
|
|
|
|
renderMainPage(jwt);
|
|
|
|
|
|
|
|
const menuButton = queryAllMenuIconButtons();
|
|
|
|
expect(menuButton).toHaveLength(1);
|
|
|
|
fireEvent.click(menuButton[0]);
|
|
|
|
|
|
|
|
// renders the two menu entries for an editor
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(
|
|
|
|
screen.queryAllByRole("button", { name: /fragen|benutzer/i })
|
|
|
|
).toHaveLength(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("As a candidate, the main page", () => {
|
|
|
|
test("displays the candidate's home page ", () => {
|
2021-02-07 22:18:05 +01:00
|
|
|
const jwt: JwtPayload = {
|
|
|
|
...baseJwt,
|
2022-02-02 13:13:34 +01:00
|
|
|
role: "kandimat_candidate",
|
2021-02-07 22:18:05 +01:00
|
|
|
person_row_id: 2,
|
|
|
|
};
|
|
|
|
renderMainPage(jwt);
|
2020-12-31 11:36:23 +01:00
|
|
|
|
2021-02-08 00:00:12 +01:00
|
|
|
const questionListHeadline = screen.queryAllByText(/Fragen/);
|
2021-01-05 18:28:24 +01:00
|
|
|
const categoryListHeadline = screen.queryByText(/Kategorien/);
|
2021-02-08 00:00:12 +01:00
|
|
|
expect(questionListHeadline.length).toBeGreaterThan(0);
|
2021-01-05 18:28:24 +01:00
|
|
|
expect(categoryListHeadline).toBeNull();
|
2020-12-31 11:36:23 +01:00
|
|
|
});
|
2021-02-08 00:00:12 +01:00
|
|
|
});
|
2020-12-31 11:36:23 +01:00
|
|
|
|
2021-02-08 00:00:12 +01:00
|
|
|
describe("As a simple user, the main page", () => {
|
|
|
|
test("displays the user's home page.", () => {
|
2021-02-07 22:18:05 +01:00
|
|
|
const jwt: JwtPayload = {
|
|
|
|
...baseJwt,
|
2022-02-02 13:13:34 +01:00
|
|
|
role: "kandimat_person",
|
2021-02-07 22:18:05 +01:00
|
|
|
person_row_id: 3,
|
|
|
|
};
|
|
|
|
renderMainPage(jwt);
|
2020-12-31 11:36:23 +01:00
|
|
|
|
|
|
|
const placeholder = screen.queryByText(/nichts zu sehen/);
|
|
|
|
expect(placeholder).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|