Skip to content

Commit

Permalink
test: add tests for components
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Jul 23, 2022
1 parent 8112686 commit df4aa05
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Admonition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Admonition = ({
className = ``,
title = ``,
children = null,
onClick = null,
onClick = () => null,
}) => {
const [shouldHide, setShouldHide] = useState(false)
const dismissAdmonition = useCallback((event) => {
Expand All @@ -20,7 +20,7 @@ const Admonition = ({
className,
onClick ? `cursor-pointer hover:bg-100` : ``,
)}
onClick={onClick ? onClick : () => {}}
onClick={onClick}
>
<div className="grow">
<div className="inline-flex flex-row">
Expand Down
4 changes: 3 additions & 1 deletion src/components/AnimatedLoading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const AnimatedLoading = () => {
import type { FunctionComponent } from "preact"

const AnimatedLoading: FunctionComponent = () => {
return (
<div className="inline-flex flex-row items-center">
<div className="ml-[0.2rem]">Loading...</div>
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/Admonition.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Admonition from "components/Admonition"
import { render } from '@testing-library/preact'

describe(`Admonition`, () => {
it(`should render without errors`, () => {
const tree = render(
<Admonition title="Warning">
<p>
Fun will now commence
</p>
</Admonition>,
)
expect(tree).toMatchSnapshot()
})
})
11 changes: 11 additions & 0 deletions src/components/__tests__/AnimatedLoading.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import AnimatedLoading from 'components/AnimatedLoading'
import { render } from '@testing-library/preact'

describe(`AnimatedLoading`, () => {
it(`should render without errors`, () => {
const tree = render(
<AnimatedLoading />,
)
expect(tree).toMatchSnapshot()
})
})
26 changes: 26 additions & 0 deletions src/components/__tests__/SelectInput.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import SelectInput from "components/SelectInput"
import { render } from '@testing-library/preact'

const OPTIONS = [
{ content: `Jack Cloth`, value: `cloth` },
{ content: `Anne Oldman`, value: `oldman` },
{ content: `Tom Boss`, value: `boss` },
{ content: `Asap Qureshi`, value: `qureshi` },
]

const ON_CHANGE = jest.fn()

describe(`SelectInput`, () => {

it(`should render without errors`, () => {
const tree = render(
<SelectInput
options={OPTIONS}
value={OPTIONS[0].value}
onChange={ON_CHANGE}
defaultValue={OPTIONS[0].value}
/>,
)
expect(tree).toMatchSnapshot()
})
})
114 changes: 114 additions & 0 deletions src/components/__tests__/__snapshots__/Admonition.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Admonition should render without errors 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class="border border-solid border-gray-400 px-2 py-1 flex flex-row hover:bg-gray-100 cursor-pointer hover:bg-100"
>
<div
class="grow"
>
<div
class="inline-flex flex-row"
>
<strong>
Warning
</strong>
</div>
<div>
<p>
Fun will now commence
</p>
</div>
</div>
<div
class="cursor-pointer text-xs p-1"
>
</div>
</div>
</div>
</body>,
"container": <div>
<div
class="border border-solid border-gray-400 px-2 py-1 flex flex-row hover:bg-gray-100 cursor-pointer hover:bg-100"
>
<div
class="grow"
>
<div
class="inline-flex flex-row"
>
<strong>
Warning
</strong>
</div>
<div>
<p>
Fun will now commence
</p>
</div>
</div>
<div
class="cursor-pointer text-xs p-1"
>
</div>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AnimatedLoading should render without errors 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class="inline-flex flex-row items-center"
>
<div
class="ml-[0.2rem]"
>
Loading...
</div>
<div
class="inline-block relative w-[80px] h-[10px] loading-container"
>
<div />
<div />
<div />
<div />
</div>
</div>
</div>
</body>,
"container": <div>
<div
class="inline-flex flex-row items-center"
>
<div
class="ml-[0.2rem]"
>
Loading...
</div>
<div
class="inline-block relative w-[80px] h-[10px] loading-container"
>
<div />
<div />
<div />
<div />
</div>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Loading

0 comments on commit df4aa05

Please sign in to comment.