Skip to content

Commit f678ab1

Browse files
authored
Merge pull request #378 from actiontech/test/add-unit-tests
Test/add unit tests
2 parents a5ba16a + 74e3c44 commit f678ab1

File tree

17 files changed

+7448
-142
lines changed

17 files changed

+7448
-142
lines changed

packages/shared/lib/components/ActiontechTable/hooks/test/useTableRequestParams.test.tsx

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { renderHook, act, cleanup } from '@testing-library/react';
22
import useTableRequestParams from '../useTableRequestParams';
3+
import { PaginationProps } from 'antd';
34

45
describe('lib/ActiontechTable-hooks-useTableRequestParams', () => {
56
beforeEach(() => {
@@ -37,16 +38,66 @@ describe('lib/ActiontechTable-hooks-useTableRequestParams', () => {
3738

3839
it('render use createSortParams', async () => {
3940
const { result } = renderHook(() => useTableRequestParams());
41+
const params: { order_by?: string; is_asc?: boolean } = {};
42+
result.current.createSortParams(params);
43+
expect(params).toEqual({});
44+
4045
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+
});
4361

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'
50101
});
51102
});
52103

0 commit comments

Comments
 (0)