diff options
author | 2020-10-12 17:56:49 +0100 | |
---|---|---|
committer | 2020-10-12 17:56:49 +0100 | |
commit | 3adfb0db3493a55276b126bdbcb343da89218601 (patch) | |
tree | e65af73279eb7a4379652d8d664cbfd2e6a9880c | |
parent | Merge pull request #24 from python-discord/sentry/remove-tracing (diff) |
Add many new tests
-rw-r--r-- | src/tests/App.test.tsx | 9 | ||||
-rw-r--r-- | src/tests/api/forms.test.ts | 11 | ||||
-rw-r--r-- | src/tests/components/OAuth2Button.test.tsx | 1 | ||||
-rw-r--r-- | src/tests/components/Tag.test.tsx | 1 | ||||
-rw-r--r-- | src/tests/globalStyles.test.ts | 5 | ||||
-rw-r--r-- | src/tests/pages/CallbackPage.test.tsx | 23 | ||||
-rw-r--r-- | src/tests/pages/FormPage.test.tsx | 32 | ||||
-rw-r--r-- | src/tests/pages/LandingPage.test.tsx | 13 |
8 files changed, 93 insertions, 2 deletions
diff --git a/src/tests/App.test.tsx b/src/tests/App.test.tsx new file mode 100644 index 0000000..e050d4f --- /dev/null +++ b/src/tests/App.test.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { render } from '@testing-library/react'; + +import App from "../App"; + +test('renders app to body', () => { + const { container } = render(<App />); + expect(container).toBeInTheDocument(); +}); diff --git a/src/tests/api/forms.test.ts b/src/tests/api/forms.test.ts new file mode 100644 index 0000000..7c851a7 --- /dev/null +++ b/src/tests/api/forms.test.ts @@ -0,0 +1,11 @@ +import { getForm, getForms } from "../../api/forms"; + +test('fetch a list of all forms', () => { + expect(getForms()).toBeInstanceOf(Array); +}); + +test('fetch a specific form', () => { + expect(getForm("ban-appeals")).resolves.toHaveProperty("title", "Ban Appeals") +}); + +export default null; diff --git a/src/tests/components/OAuth2Button.test.tsx b/src/tests/components/OAuth2Button.test.tsx index 49c0f8a..53875dc 100644 --- a/src/tests/components/OAuth2Button.test.tsx +++ b/src/tests/components/OAuth2Button.test.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { render } from '@testing-library/react'; -import '@testing-library/jest-dom/extend-expect'; import OAuth2Button from "../../components/OAuth2Button"; test('renders oauth2 sign in button text', () => { diff --git a/src/tests/components/Tag.test.tsx b/src/tests/components/Tag.test.tsx index 26c8afb..67f2a85 100644 --- a/src/tests/components/Tag.test.tsx +++ b/src/tests/components/Tag.test.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { render } from '@testing-library/react'; -import '@testing-library/jest-dom/extend-expect'; import Tag from "../../components/Tag"; test('renders tag with specified text', () => { diff --git a/src/tests/globalStyles.test.ts b/src/tests/globalStyles.test.ts new file mode 100644 index 0000000..d44cc51 --- /dev/null +++ b/src/tests/globalStyles.test.ts @@ -0,0 +1,5 @@ +import globalStyles from "../globalStyles"; + +test("global styles emotion css compiles", () => { + expect(globalStyles.styles).not.toBeUndefined(); +}) diff --git a/src/tests/pages/CallbackPage.test.tsx b/src/tests/pages/CallbackPage.test.tsx new file mode 100644 index 0000000..e878577 --- /dev/null +++ b/src/tests/pages/CallbackPage.test.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { render } from '@testing-library/react'; + +import CallbackPage from '../../pages/CallbackPage'; + +test('callback page renders provided code', () => { + global.opener = { + postMessage: jest.fn() + } + + let mockLocation = new URL("https://forms.pythondiscord.com/authorize?code=abcdef"); + + Object.defineProperty(global, "location", {value: mockLocation}) + + let comp = <CallbackPage />; + + const { getByText } = render(comp); + + + let codeText = getByText(/Code is abcdef/); + expect(codeText).toBeInTheDocument(); + expect(global.opener.postMessage).toBeCalledTimes(1) +}); 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(); +}); diff --git a/src/tests/pages/LandingPage.test.tsx b/src/tests/pages/LandingPage.test.tsx new file mode 100644 index 0000000..ba32bab --- /dev/null +++ b/src/tests/pages/LandingPage.test.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { render } from '@testing-library/react'; + +import LandingPage from "../../pages/LandingPage"; + +import { BrowserRouter as Router } from "react-router-dom"; + +test('renders landing page', () => { + const { getByText } = render(<Router><LandingPage /></Router>); + // If we rendered the headerbar we rendered the landing page. + let headerBar = getByText(/Python Discord Forms/); + expect(headerBar).toBeInTheDocument(); +}); |