2020-05-07 08:03:30 +02:00
|
|
|
import React from 'react'
|
|
|
|
import { render, fireEvent } from '@testing-library/react'
|
2020-07-01 18:13:32 +02:00
|
|
|
import Search from '../../../src/components/templates/Search'
|
2020-06-30 16:22:22 +02:00
|
|
|
import {
|
|
|
|
createHistory,
|
|
|
|
createMemorySource,
|
|
|
|
LocationProvider
|
|
|
|
} from '@reach/router'
|
2020-05-07 08:03:30 +02:00
|
|
|
|
|
|
|
describe('Search', () => {
|
|
|
|
it('renders without crashing', async () => {
|
2020-06-30 16:22:22 +02:00
|
|
|
const history = createHistory(createMemorySource('/search?text=water'))
|
2021-01-13 10:15:50 +01:00
|
|
|
const setTotalResults = (totalResults: number) => {
|
|
|
|
const results = totalResults
|
|
|
|
}
|
2020-06-30 16:22:22 +02:00
|
|
|
|
2020-05-07 08:03:30 +02:00
|
|
|
const { container } = render(
|
2020-06-30 16:22:22 +02:00
|
|
|
<LocationProvider history={history}>
|
2021-01-13 10:15:50 +01:00
|
|
|
<Search
|
|
|
|
location={{ search: '?text=water' } as any}
|
|
|
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
|
|
|
/>
|
2020-06-30 16:22:22 +02:00
|
|
|
</LocationProvider>
|
2020-05-07 08:03:30 +02:00
|
|
|
)
|
|
|
|
expect(container.firstChild).toBeInTheDocument()
|
|
|
|
|
|
|
|
// interact with search bar
|
|
|
|
const form = container.querySelector('form')
|
|
|
|
const input = container.querySelector('form input')
|
|
|
|
const button = container.querySelector('form button')
|
|
|
|
|
|
|
|
input &&
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: {
|
|
|
|
value: 'Changed Hello'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
button && fireEvent.click(button)
|
|
|
|
form && fireEvent.submit(form)
|
|
|
|
})
|
|
|
|
})
|