aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/pages/FormPage.test.tsx
blob: f7ecc327200fee889ea7fc13fc329ca1813f9bf6 (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
import React from "react";
import { render } from "@testing-library/react";

import { createMemoryHistory } from "history";

import { Route, BrowserRouter as Router } from "react-router-dom";
import FormPage from "../../pages/FormPage";

import * as forms from "../../api/forms";

test("renders specific form page with loading bar", () => {
    const history = createMemoryHistory();
    history.push("/form/route");

    const { getByText } = render(<Router><Route history={history} ><FormPage /></Route></Router>);
    // If we rendered the headerbar we rendered the forms page.
    const headerBar = getByText(/Loading.../);
    expect(headerBar).toBeInTheDocument();
});

test("calls api method to load form", () => {
    const history = createMemoryHistory();
    history.push("/form/ban-appeals");

    const oldImpl = forms.getForm;

    Object.defineProperty(forms, "getForm", {value: jest.fn(oldImpl)});

    render(<Router><Route history={history}><FormPage /></Route></Router>);
    
    expect(forms.getForm).toBeCalled();
});