|
| 1 | +import '@testing-library/jest-dom'; |
| 2 | +import { renderHook, act } from '@testing-library/react'; |
| 3 | +import { useDataViewPagination } from './pagination'; |
| 4 | + |
| 5 | +describe('useDataViewPagination', () => { |
| 6 | + |
| 7 | + it('should get initial state correctly - no page', () => { |
| 8 | + const { result } = renderHook(() => useDataViewPagination({ perPage: 7 })) |
| 9 | + expect(result.current).toEqual({ |
| 10 | + onPerPageSelect: expect.any(Function), |
| 11 | + onSetPage: expect.any(Function), |
| 12 | + page: 1, |
| 13 | + perPage: 7 |
| 14 | + }) |
| 15 | + }); |
| 16 | + |
| 17 | + it('should get initial state correctly - page set', () => { |
| 18 | + const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 })) |
| 19 | + expect(result.current).toEqual({ |
| 20 | + onPerPageSelect: expect.any(Function), |
| 21 | + onSetPage: expect.any(Function), |
| 22 | + page: 3, |
| 23 | + perPage: 5 |
| 24 | + }) |
| 25 | + }); |
| 26 | + |
| 27 | + it('should set page correctly', () => { |
| 28 | + const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 })) |
| 29 | + |
| 30 | + act(() => { |
| 31 | + result.current.onSetPage(undefined, 8); |
| 32 | + }); |
| 33 | + |
| 34 | + expect(result.current).toEqual({ |
| 35 | + onPerPageSelect: expect.any(Function), |
| 36 | + onSetPage: expect.any(Function), |
| 37 | + page: 8, |
| 38 | + perPage: 5 |
| 39 | + }) |
| 40 | + }); |
| 41 | + |
| 42 | + it('should set perPage correctly', () => { |
| 43 | + const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 })) |
| 44 | + |
| 45 | + act(() => { |
| 46 | + result.current.onPerPageSelect(undefined, 50); |
| 47 | + }); |
| 48 | + |
| 49 | + expect(result.current).toEqual({ |
| 50 | + onPerPageSelect: expect.any(Function), |
| 51 | + onSetPage: expect.any(Function), |
| 52 | + page: 3, |
| 53 | + perPage: 50 |
| 54 | + }) |
| 55 | + }); |
| 56 | + |
| 57 | +}); |
0 commit comments