blob: fadea7a46058ae7cec26993ba3393e2fc70a9be8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/** @jsx jsx */
import Cookies from "universal-cookie";
import { jsx } from "@emotion/react";
import { render } from "@testing-library/react";
import Navigation from "../../../pages/FormPage/Navigation";
import {MemoryRouter} from "react-router-dom";
import { OAuthScopes, CookieNames } from "../../../api/auth";
test("navigation shows submit when form is open and no auth required", () => {
const { getByRole } = render(<Navigation form_state={true} scopes={[]} />, { wrapper: MemoryRouter });
const submitButton = getByRole("button");
expect(submitButton).not.toBeNull();
expect(submitButton.innerHTML).toBe("Submit");
});
test("navigation shows oauth button when form is open and auth is required", () => {
const { getByRole } = render(<Navigation form_state={true} scopes={[OAuthScopes.Identify]} />, { wrapper: MemoryRouter });
const loginButton = getByRole("button");
expect(loginButton).not.toBeNull();
expect(loginButton.textContent).toBe("Login To Submit");
});
test("navigation shows submit button when form is open and auth is present", () => {
new Cookies().set(CookieNames.Scopes, [OAuthScopes.Identify]);
const { getByRole } = render(<Navigation form_state={true} scopes={[OAuthScopes.Identify]} />, { wrapper: MemoryRouter });
const loginButton = getByRole("button");
expect(loginButton).not.toBeNull();
expect(loginButton.textContent).toBe("Submit");
});
test("navigation shows login button when form is open and auth is present but insufficient scopes", () => {
new Cookies().set(CookieNames.Scopes, [OAuthScopes.Identify]);
const { getByRole } = render(<Navigation form_state={true} scopes={[OAuthScopes.Identify, OAuthScopes.Guilds]} />, { wrapper: MemoryRouter });
const loginButton = getByRole("button");
expect(loginButton).not.toBeNull();
expect(loginButton.textContent).toBe("Login To Submit");
});
|