From 3adfb0db3493a55276b126bdbcb343da89218601 Mon Sep 17 00:00:00 2001
From: Joe Banks <joseph@josephbanks.me>
Date: Mon, 12 Oct 2020 17:56:49 +0100
Subject: Add many new tests

---
 src/tests/pages/FormPage.test.tsx | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 src/tests/pages/FormPage.test.tsx

(limited to 'src/tests/pages/FormPage.test.tsx')

diff --git a/src/tests/pages/FormPage.test.tsx b/src/tests/pages/FormPage.test.tsx
new file mode 100644
index 0000000..7bfc763
--- /dev/null
+++ b/src/tests/pages/FormPage.test.tsx
@@ -0,0 +1,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.
+    let headerBar = getByText(/Loading.../);
+    expect(headerBar).toBeInTheDocument();
+});
+
+test('calls api method to load form', () => {
+    const history = createMemoryHistory();
+    history.push("/form/ban-appeals");
+
+    let oldImpl = forms.getForm;
+
+    Object.defineProperty(forms, "getForm", {value: jest.fn(oldImpl)});
+
+    render(<Router><Route history={history}><FormPage /></Route></Router>);
+    
+    expect(forms.getForm).toBeCalled();
+});
-- 
cgit v1.2.3

