Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Jul 22, 2022
1 parent 9f74e83 commit d52116b
Show file tree
Hide file tree
Showing 15 changed files with 606 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Popup/ExternalLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FunctionComponent, ComponentChildren } from 'preact'
import type { FunctionComponent } from 'preact'
import { useEffect, useState , useCallback } from 'preact/hooks'
import Constants from '../utils/Constants'
import OptionsStorage from '../utils/OptionsStorage'
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions src/Popup/__tests__/ClipboardSuggestion.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render } from '@testing-library/preact'
import ClipboardSuggestion from 'Popup/ClipboardSuggestion'
import Clipboard from 'utils/Clipboard'
import OptionsStorage from 'utils/OptionsStorage'

jest.mock(`utils/Clipboard`)
const getPopupSearchText = Clipboard.getPopupSearchText as jest.Mock

jest.mock(`utils/OptionsStorage`)
const clipboardPasteGet = OptionsStorage.clipboardPaste.get as jest.Mock

const QUERY = `abc123`
const CLIPBOARD_TEXT = `xyz789`
const applyClipboardText = () => {}

describe(`ExternalLinks`, () => {
it(`renders without error`, () => {
getPopupSearchText.mockImplementation(() => Promise.resolve(CLIPBOARD_TEXT))
clipboardPasteGet.mockImplementation(() => Promise.resolve(true))
const tree = render(
<ClipboardSuggestion
query={QUERY}
applyClipboardText={applyClipboardText}
/>,
)
expect(tree).toMatchSnapshot()
})
})
55 changes: 55 additions & 0 deletions src/Popup/__tests__/ExternalLinks.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { render } from '@testing-library/preact'
import ExternalLinks from 'Popup/ExternalLinks'
import { Constants } from 'utils'
import OptionsStorage from 'utils/OptionsStorage'
import SearcherStorage from 'ContentScript/Searcher/SearcherStorage'

jest.mock(`utils/OptionsStorage`)
const institutionalLoginGet = OptionsStorage.institutionalLogin.get as jest.Mock

jest.mock(`ContentScript/Searcher/SearcherStorage`)
const storeLawNetQuery = SearcherStorage.storeLawNetQuery as jest.Mock

const TYPE: Law.Type = `case-name`
const QUERY = `abc123`

describe(`ExternalLinks`, () => {

beforeAll(() => {
institutionalLoginGet.mockImplementation(() => Promise.resolve(`None`))
storeLawNetQuery.mockImplementation(() => Promise.resolve())
})

it(`renders without error for UK`, () => {
const tree = render(
<ExternalLinks
jurisdiction={Constants.JURISDICTIONS.UK.id}
type={TYPE}
query={QUERY}
/>,
)
expect(tree).toMatchSnapshot()
})

it(`renders without error for Singapore`, () => {
const tree = render(
<ExternalLinks
jurisdiction={Constants.JURISDICTIONS.SG.id}
type={TYPE}
query={QUERY}
/>,
)
expect(tree).toMatchSnapshot()
})

it(`renders without error for EU`, () => {
const tree = render(
<ExternalLinks
jurisdiction={Constants.JURISDICTIONS.EU.id}
type={TYPE}
query={QUERY}
/>,
)
expect(tree).toMatchSnapshot()
})
})
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExternalLinks renders without error 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div />
</body>,
"container": <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 d52116b

Please sign in to comment.