|
| 1 | +import React from 'react'; |
| 2 | +import {Provider} from "react-redux"; |
| 3 | + |
| 4 | +import {act, fireEvent, render, screen} from '@testing-library/react'; |
| 5 | +import configureStore from 'redux-mock-store'; |
| 6 | + |
| 7 | +import SearchBox from '../../components/SearchBox'; |
| 8 | + |
| 9 | +const mockStore = configureStore(); |
| 10 | + |
| 11 | +const searchProviders = { |
| 12 | + testing: { |
| 13 | + onSearch: (text, searchParams, callback) => callback({ |
| 14 | + results: [ |
| 15 | + { |
| 16 | + id: 'layer1', |
| 17 | + title: 'Layer 1', |
| 18 | + items: [ |
| 19 | + { |
| 20 | + id: 'item1', |
| 21 | + text: 'Item 1' |
| 22 | + }, |
| 23 | + { |
| 24 | + id: 'item2', |
| 25 | + text: 'Item 2' |
| 26 | + } |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + id: 'layer2', |
| 31 | + title: 'Layer 2', |
| 32 | + items: [ |
| 33 | + { |
| 34 | + id: 'item3', |
| 35 | + text: 'Item 3' |
| 36 | + } |
| 37 | + ] |
| 38 | + } |
| 39 | + ] |
| 40 | + }) |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +// eslint-disable-next-line new-cap |
| 45 | +const Search = SearchBox(searchProviders); |
| 46 | + |
| 47 | +test('search results are visible', () => { |
| 48 | + const store = mockStore({ |
| 49 | + map: { projection: 'EPSG:4326' }, |
| 50 | + layers: { flat: [] }, |
| 51 | + theme: { current: { searchProviders: ['testing'] } } |
| 52 | + }); |
| 53 | + |
| 54 | + const searchOptions = { |
| 55 | + allowSearchFilters: false |
| 56 | + }; |
| 57 | + |
| 58 | + render( |
| 59 | + <Provider store={store}> |
| 60 | + <Search searchOptions={searchOptions} /> |
| 61 | + </Provider> |
| 62 | + ); |
| 63 | + |
| 64 | + const input = screen.getByRole('input'); |
| 65 | + expect(input).toHaveValue(''); |
| 66 | + |
| 67 | + fireEvent.change(input, { target: { value: 'Test' } }); |
| 68 | + act(() => input.focus()); |
| 69 | + |
| 70 | + expect(input).toHaveValue('Test'); |
| 71 | + expect(screen.getByText('Layer 1')).toBeInTheDocument(); |
| 72 | + expect(screen.getByText('Layer 2')).toBeInTheDocument(); |
| 73 | + expect(screen.getByText('Item 1')).toBeInTheDocument(); |
| 74 | + expect(screen.getByText('Item 2')).toBeInTheDocument(); |
| 75 | + expect(screen.getByText('Item 3')).toBeInTheDocument(); |
| 76 | +}); |
0 commit comments