1 | import useFilters from '.';
|
2 | import useRest from '../useRest';
|
3 |
|
4 | jest.mock('../useRest', () => ({
|
5 | __esModule: true,
|
6 | default: jest.fn(),
|
7 | }));
|
8 |
|
9 | describe('useFilters custom hook', () => {
|
10 | it('should format search string', () => {
|
11 | useFilters({
|
12 | fields: ['foo', 'bar', 'quux'],
|
13 | coll: 'demo',
|
14 | });
|
15 |
|
16 | expect(useRest).toHaveBeenCalledWith(
|
17 | expect.objectContaining({
|
18 | url:
|
19 | '/search?collectionName=demo&fields[]=foo&fields[]=bar&fields[]=quux',
|
20 | }),
|
21 | );
|
22 | });
|
23 |
|
24 | it.skip('should append query string', () => {
|
25 | useFilters({
|
26 | query: '?search=hi',
|
27 | fields: ['foo'],
|
28 | coll: 'demo',
|
29 | });
|
30 |
|
31 | expect(useRest).toHaveBeenCalledWith(
|
32 | expect.objectContaining({
|
33 | url:
|
34 | '/search?collectionName=demo&fields[]=foo&search=hi',
|
35 | }),
|
36 | );
|
37 | });
|
38 |
|
39 | it('should create a drop-down options list', () => {
|
40 | useRest.mockReturnValue({
|
41 | fields: {
|
42 | example: ['foo', 'bar'],
|
43 | },
|
44 | });
|
45 |
|
46 | const filters = useFilters({
|
47 | fields: ['foo'],
|
48 | coll: 'demo',
|
49 | });
|
50 |
|
51 | expect(filters.getOptions('example')).toEqual([
|
52 | 'foo',
|
53 | 'bar',
|
54 | ]);
|
55 | });
|
56 | });
|