From 96bb44927bf674aa0cd139ef430921de2d988bc3 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Mon, 28 Sep 2020 04:04:06 +0100 Subject: Add initial tests --- src/App.test.tsx | 9 --------- src/components/HeaderBar/index.tsx | 2 +- src/tests/components/FormListing.test.tsx | 29 +++++++++++++++++++++++++++++ src/tests/components/HeaderBar.test.tsx | 9 +++++++++ src/tests/components/OAuth2Button.test.tsx | 15 +++++++++++++++ src/tests/components/Tag.test.tsx | 30 ++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 10 deletions(-) delete mode 100644 src/App.test.tsx create mode 100644 src/tests/components/FormListing.test.tsx create mode 100644 src/tests/components/HeaderBar.test.tsx create mode 100644 src/tests/components/OAuth2Button.test.tsx create mode 100644 src/tests/components/Tag.test.tsx (limited to 'src') diff --git a/src/App.test.tsx b/src/App.test.tsx deleted file mode 100644 index 4db7ebc..0000000 --- a/src/App.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - const { getByText } = render(); - const linkElement = getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/components/HeaderBar/index.tsx b/src/components/HeaderBar/index.tsx index 200221c..97dbb8c 100644 --- a/src/components/HeaderBar/index.tsx +++ b/src/components/HeaderBar/index.tsx @@ -43,7 +43,7 @@ function HeaderBar() { `}> Python Discord Forms - + } export default HeaderBar; diff --git a/src/tests/components/FormListing.test.tsx b/src/tests/components/FormListing.test.tsx new file mode 100644 index 0000000..26c7c93 --- /dev/null +++ b/src/tests/components/FormListing.test.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import FormListing from "../../components/FormListing"; + +test('renders form listing with specified title', () => { + const { getByText } = render(); + const formListing = getByText(/Example form listing/i); + expect(formListing).toBeInTheDocument(); +}); + +test('renders form listing with specified description', () => { + const { getByText } = render(); + const formListing = getByText(/My form listing/i); + expect(formListing).toBeInTheDocument(); +}); + +test('renders form listing with background green colour for open', () => { + const { container } = render(); + const elem = container.querySelector("div"); + const style = window.getComputedStyle(elem); + expect(style.backgroundColor).toBe("rgb(67, 181, 129)"); +}); + +test('renders form listing with background dark colour for closed', () => { + const { container } = render(); + const elem = container.querySelector("div"); + const style = window.getComputedStyle(elem); + expect(style.backgroundColor).toBe("rgb(44, 47, 51)"); +}); diff --git a/src/tests/components/HeaderBar.test.tsx b/src/tests/components/HeaderBar.test.tsx new file mode 100644 index 0000000..3567d7e --- /dev/null +++ b/src/tests/components/HeaderBar.test.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import HeaderBar from "../../components/HeaderBar"; + +test('renders header bar with title', () => { + const { getByText } = render(); + const formListing = getByText(/Python Discord Forms/i); + expect(formListing).toBeInTheDocument(); +}); diff --git a/src/tests/components/OAuth2Button.test.tsx b/src/tests/components/OAuth2Button.test.tsx new file mode 100644 index 0000000..53875dc --- /dev/null +++ b/src/tests/components/OAuth2Button.test.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import OAuth2Button from "../../components/OAuth2Button"; + +test('renders oauth2 sign in button text', () => { + const { getByText } = render(); + const button = getByText(/Sign in with Discord/i); + expect(button).toBeInTheDocument(); +}); + +test("renders fontawesome discord icon", () => { + const { container } = render(); + const icon = container.querySelector(`[data-icon="discord"]`) + expect(icon).toBeInTheDocument(); +}) diff --git a/src/tests/components/Tag.test.tsx b/src/tests/components/Tag.test.tsx new file mode 100644 index 0000000..67f2a85 --- /dev/null +++ b/src/tests/components/Tag.test.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import Tag from "../../components/Tag"; + +test('renders tag with specified text', () => { + const { getByText } = render(); + const tag = getByText(/Test/i); + expect(tag).toBeInTheDocument(); +}); + +test('renders tag with specified color', () => { + const { getByText } = render(); + const tag = getByText(/Test/i); + const style = window.getComputedStyle(tag); + expect(style.backgroundColor).toBe("rgb(240, 240, 240)"); +}); + +test('renders tag with specified font size', () => { + const { getByText } = render(); + const tag = getByText(/Test/i); + const style = window.getComputedStyle(tag); + expect(style.fontSize).toBe("2em"); +}); + +test('defaults to 0.75em when no tag font size is passed', () => { + const { getByText } = render(); + const tag = getByText(/Test/i); + const style = window.getComputedStyle(tag); + expect(style.fontSize).toBe("0.75em"); +}); -- cgit v1.2.3