|
1 | 1 | import { renderHook, act, cleanup } from '@testing-library/react';
|
2 | 2 | import useTableRequestParams from '../useTableRequestParams';
|
| 3 | +import { PaginationProps } from 'antd'; |
3 | 4 |
|
4 | 5 | describe('lib/ActiontechTable-hooks-useTableRequestParams', () => {
|
5 | 6 | beforeEach(() => {
|
@@ -37,16 +38,66 @@ describe('lib/ActiontechTable-hooks-useTableRequestParams', () => {
|
37 | 38 |
|
38 | 39 | it('render use createSortParams', async () => {
|
39 | 40 | const { result } = renderHook(() => useTableRequestParams());
|
| 41 | + const params: { order_by?: string; is_asc?: boolean } = {}; |
| 42 | + result.current.createSortParams(params); |
| 43 | + expect(params).toEqual({}); |
| 44 | + |
40 | 45 | await act(async () => {
|
41 |
| - const sortInfo = result.current.sortInfo; |
42 |
| - expect(sortInfo).toEqual({}); |
| 46 | + result.current.tableChange( |
| 47 | + {} as PaginationProps, |
| 48 | + {} as Record<string, null>, |
| 49 | + { |
| 50 | + column: { |
| 51 | + dataIndex: 'query_time_max', |
| 52 | + title: '最长执行时间', |
| 53 | + sorter: true |
| 54 | + }, |
| 55 | + order: 'ascend', |
| 56 | + field: 'query_time_max' |
| 57 | + }, |
| 58 | + {} as any |
| 59 | + ); |
| 60 | + }); |
43 | 61 |
|
44 |
| - result.current.createSortParams({ |
45 |
| - order_by: 'aa', |
46 |
| - field: 'aa', |
47 |
| - is_asc: true |
48 |
| - }); |
49 |
| - expect(sortInfo).toEqual({}); |
| 62 | + expect(result.current.sortInfo).toEqual({ |
| 63 | + column: { |
| 64 | + dataIndex: 'query_time_max', |
| 65 | + title: '最长执行时间', |
| 66 | + sorter: true |
| 67 | + }, |
| 68 | + order: 'ascend', |
| 69 | + field: 'query_time_max' |
| 70 | + }); |
| 71 | + |
| 72 | + result.current.createSortParams(params); |
| 73 | + expect(params).toEqual({ |
| 74 | + is_asc: true, |
| 75 | + order_by: 'query_time_max' |
| 76 | + }); |
| 77 | + |
| 78 | + await act(async () => { |
| 79 | + result.current.tableChange( |
| 80 | + {} as PaginationProps, |
| 81 | + {} as Record<string, null>, |
| 82 | + [ |
| 83 | + { |
| 84 | + column: { |
| 85 | + dataIndex: 'last_receive_timestamp', |
| 86 | + title: '最后匹配时间', |
| 87 | + sorter: true |
| 88 | + }, |
| 89 | + order: 'descend', |
| 90 | + field: 'last_receive_timestamp' |
| 91 | + } |
| 92 | + ], |
| 93 | + {} as any |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + result.current.createSortParams(params); |
| 98 | + expect(params).toEqual({ |
| 99 | + is_asc: false, |
| 100 | + order_by: 'last_receive_timestamp' |
50 | 101 | });
|
51 | 102 | });
|
52 | 103 |
|
|
0 commit comments