mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 09:44:53 +01:00
b5f6f9c9c1
* displayed search results count * updated unit test for Search component * account for singular & plural, display message if there's no result
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import React from 'react'
|
|
import { render, fireEvent } from '@testing-library/react'
|
|
import Search from '../../../src/components/templates/Search'
|
|
import {
|
|
createHistory,
|
|
createMemorySource,
|
|
LocationProvider
|
|
} from '@reach/router'
|
|
|
|
describe('Search', () => {
|
|
it('renders without crashing', async () => {
|
|
const history = createHistory(createMemorySource('/search?text=water'))
|
|
const setTotalResults = (totalResults: number) => {
|
|
const results = totalResults
|
|
}
|
|
|
|
const { container } = render(
|
|
<LocationProvider history={history}>
|
|
<Search
|
|
location={{ search: '?text=water' } as any}
|
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
|
/>
|
|
</LocationProvider>
|
|
)
|
|
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)
|
|
})
|
|
})
|