|
1 | 1 | import { act, renderHook } from '@testing-library/react-hooks'; |
2 | 2 | import { ChangeEvent } from 'react'; |
| 3 | +import { Binding } from '../bindings'; |
3 | 4 | import { |
4 | 5 | defaultTypeOperationsMap, |
5 | 6 | defaultOperationLabels, |
6 | 7 | mapOperationToSelectOption, |
7 | 8 | OperationType, |
8 | 9 | } from '../operations'; |
| 10 | +import { Filter } from '../types'; |
9 | 11 | import { useQueryFilters, HookProps } from './useQueryFilters'; |
10 | 12 |
|
11 | 13 | const properties: HookProps['properties'] = [ |
@@ -53,6 +55,27 @@ describe('useQueryFilters', () => { |
53 | 55 | createTestFilter(); |
54 | 56 | }); |
55 | 57 |
|
| 58 | + it('should initialize using a given initial state', () => { |
| 59 | + const initialValue: Filter[] = [ |
| 60 | + { |
| 61 | + id: '35f924a2-9e1d-423c-8565-41619a5b8e8e', |
| 62 | + field: 'name', |
| 63 | + operation: OperationType.IS, |
| 64 | + value: 'Artemis', |
| 65 | + type: 'string', |
| 66 | + }, |
| 67 | + { |
| 68 | + id: '91f7e872-f0e9-4fdf-8db1-6b51c0670817', |
| 69 | + binding: Binding.AND, |
| 70 | + }, |
| 71 | + ]; |
| 72 | + const { result } = renderHook(() => |
| 73 | + useQueryFilters({ initialValue, properties }) |
| 74 | + ); |
| 75 | + |
| 76 | + expect(result.current.filters).toStrictEqual(initialValue); |
| 77 | + }); |
| 78 | + |
56 | 79 | describe('createFilterRowProps', () => { |
57 | 80 | it('should return the string operation choices by default if the filter has no field selected', () => { |
58 | 81 | const result = createTestFilter(); |
|
0 commit comments