@kdcloudjs/table 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +34 -33
- package/dist/@kdcloudjs/table.css +1 -1
- package/dist/@kdcloudjs/table.css.map +1 -1
- package/dist/@kdcloudjs/table.js +6555 -3388
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +32 -24
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/_utils/hooks.js +1 -2
- package/es/_utils/numberUtil.js +3 -4
- package/es/locale/locale.js +1 -2
- package/es/table/base/calculations.js +3 -4
- package/es/table/base/empty.js +2 -2
- package/es/table/base/header.d.ts +6 -2
- package/es/table/base/header.js +41 -22
- package/es/table/base/helpers/SpanManager.js +1 -1
- package/es/table/base/helpers/TableDOMUtils.d.ts +3 -0
- package/es/table/base/helpers/TableDOMUtils.js +23 -5
- package/es/table/base/helpers/getRichVisibleRectsStream.d.ts +23 -0
- package/es/table/base/helpers/getRichVisibleRectsStream.js +216 -0
- package/es/table/base/html-table.d.ts +3 -1
- package/es/table/base/html-table.js +43 -26
- package/es/table/base/interfaces.d.ts +1 -0
- package/es/table/base/renderTemplates.d.ts +1 -0
- package/es/table/base/renderTemplates.js +344 -0
- package/es/table/base/styles.d.ts +24 -0
- package/es/table/base/styles.js +31 -9
- package/es/table/base/table.d.ts +12 -4
- package/es/table/base/table.js +183 -136
- package/es/table/base/utils.d.ts +6 -3
- package/es/table/base/utils.js +27 -6
- package/es/table/common-views.js +3 -3
- package/es/table/pipeline/features/autoFill.js +7 -1
- package/es/table/pipeline/features/columnDrag.js +168 -59
- package/es/table/pipeline/features/columnFilter.js +7 -9
- package/es/table/pipeline/features/columnResizeWidth.d.ts +3 -0
- package/es/table/pipeline/features/columnResizeWidth.js +11 -4
- package/es/table/pipeline/features/contextMenu.js +78 -31
- package/es/table/pipeline/features/filter/Filter.js +74 -37
- package/es/table/pipeline/features/index.d.ts +1 -0
- package/es/table/pipeline/features/index.js +2 -1
- package/es/table/pipeline/features/multiSelect.js +85 -79
- package/es/table/pipeline/features/rangeSelection.d.ts +10 -0
- package/es/table/pipeline/features/rangeSelection.js +231 -0
- package/es/table/pipeline/features/rowDetail.js +39 -16
- package/es/table/pipeline/features/rowGrouping.js +2 -1
- package/es/table/pipeline/features/singleSelect.js +4 -1
- package/es/table/pipeline/features/sort.js +2 -3
- package/es/table/pipeline/features/treeMode.js +4 -4
- package/es/table/pipeline/pipeline.d.ts +8 -0
- package/es/table/pipeline/pipeline.js +49 -5
- package/es/table/pivot/cross-table/buildCrossTable.js +1 -2
- package/es/table/pivot/cross-tree-table/buildCrossTreeTable.js +1 -2
- package/es/table/pivot/pivot-utils/builders.js +1 -2
- package/es/table/pivot/pivot-utils/convert-utils.js +5 -4
- package/es/table/transforms/autoWidth.js +1 -2
- package/es/table/transforms/sort.js +1 -2
- package/es/table/transforms/treeMode.js +1 -2
- package/es/table/utils/applyTransforms.js +1 -3
- package/es/table/utils/browserType.d.ts +6 -0
- package/es/table/utils/browserType.js +6 -0
- package/es/table/utils/buildTree.js +4 -5
- package/es/table/utils/collectNodes.js +1 -2
- package/es/table/utils/exportTableAsExcel.js +1 -2
- package/es/table/utils/getTreeDepth.js +1 -2
- package/es/table/utils/groupBy.js +1 -2
- package/es/table/utils/index.d.ts +1 -0
- package/es/table/utils/index.js +2 -1
- package/es/table/utils/layeredSort.js +5 -2
- package/es/table/utils/makeRecursiveMapper.js +4 -5
- package/es/table/utils/others.d.ts +1 -1
- package/es/table/utils/others.js +20 -14
- package/es/table/utils/traverseColumn.js +1 -2
- package/es/table/utils/tree-data-helpers/StrictTreeDataHelper.js +4 -5
- package/es/table/utils/tree-data-helpers/TreeDataHelper.js +4 -5
- package/lib/_utils/formatUtil.js +1 -1
- package/lib/_utils/hooks.js +2 -4
- package/lib/_utils/numberUtil.js +7 -9
- package/lib/_utils/usePopper.js +9 -1
- package/lib/config-provider/configProvider.js +9 -1
- package/lib/config-provider/index.js +5 -5
- package/lib/locale/index.js +14 -6
- package/lib/locale/locale.js +2 -4
- package/lib/table/base/calculations.js +4 -6
- package/lib/table/base/empty.js +11 -3
- package/lib/table/base/header.d.ts +6 -2
- package/lib/table/base/header.js +39 -19
- package/lib/table/base/helpers/SpanManager.js +1 -1
- package/lib/table/base/helpers/TableDOMUtils.d.ts +3 -0
- package/lib/table/base/helpers/TableDOMUtils.js +21 -5
- package/lib/table/base/helpers/getRichVisibleRectsStream.d.ts +23 -0
- package/lib/table/base/helpers/getRichVisibleRectsStream.js +246 -0
- package/lib/table/base/html-table.d.ts +3 -1
- package/lib/table/base/html-table.js +44 -26
- package/lib/table/base/index.js +4 -4
- package/lib/table/base/interfaces.d.ts +1 -0
- package/lib/table/base/renderTemplates.d.ts +1 -0
- package/lib/table/base/renderTemplates.js +370 -0
- package/lib/table/base/styles.d.ts +24 -0
- package/lib/table/base/styles.js +42 -13
- package/lib/table/base/table.d.ts +12 -4
- package/lib/table/base/table.js +191 -137
- package/lib/table/base/utils.d.ts +6 -3
- package/lib/table/base/utils.js +47 -10
- package/lib/table/common-views.js +3 -3
- package/lib/table/pipeline/features/autoFill.js +9 -2
- package/lib/table/pipeline/features/columnDrag.js +168 -59
- package/lib/table/pipeline/features/columnFilter.js +6 -9
- package/lib/table/pipeline/features/columnResizeWidth.d.ts +3 -0
- package/lib/table/pipeline/features/columnResizeWidth.js +21 -5
- package/lib/table/pipeline/features/contextMenu.js +89 -32
- package/lib/table/pipeline/features/filter/DefaultFilterContent.js +10 -2
- package/lib/table/pipeline/features/filter/Filter.js +88 -37
- package/lib/table/pipeline/features/filter/FilterPanel.js +10 -2
- package/lib/table/pipeline/features/filter/index.js +4 -4
- package/lib/table/pipeline/features/index.d.ts +1 -0
- package/lib/table/pipeline/features/index.js +37 -27
- package/lib/table/pipeline/features/multiSelect.js +81 -75
- package/lib/table/pipeline/features/rangeSelection.d.ts +10 -0
- package/lib/table/pipeline/features/rangeSelection.js +256 -0
- package/lib/table/pipeline/features/rowDetail.js +42 -16
- package/lib/table/pipeline/features/rowGrouping.js +3 -1
- package/lib/table/pipeline/features/singleSelect.js +4 -1
- package/lib/table/pipeline/features/sort.js +2 -4
- package/lib/table/pipeline/features/treeMode.js +6 -6
- package/lib/table/pipeline/index.js +11 -3
- package/lib/table/pipeline/pipeline.d.ts +8 -0
- package/lib/table/pipeline/pipeline.js +50 -7
- package/lib/table/pivot/cross-table/buildCrossTable.js +1 -3
- package/lib/table/pivot/cross-table/index.js +4 -4
- package/lib/table/pivot/cross-tree-table/buildCrossTreeTable.js +1 -3
- package/lib/table/pivot/pivot-utils/builders.js +2 -4
- package/lib/table/pivot/pivot-utils/convert-utils.js +7 -5
- package/lib/table/pivot/pivot-utils/index.js +4 -4
- package/lib/table/transforms/autoWidth.js +10 -4
- package/lib/table/transforms/columnResize.js +10 -2
- package/lib/table/transforms/index.js +32 -32
- package/lib/table/transforms/sort.js +10 -4
- package/lib/table/transforms/treeMode.js +9 -3
- package/lib/table/utils/applyTransforms.js +1 -5
- package/lib/table/utils/browserType.d.ts +6 -0
- package/lib/table/utils/browserType.js +13 -0
- package/lib/table/utils/buildTree.js +1 -3
- package/lib/table/utils/collectNodes.js +1 -3
- package/lib/table/utils/copyToClipboard.js +1 -1
- package/lib/table/utils/element.js +3 -3
- package/lib/table/utils/exportTableAsExcel.js +1 -3
- package/lib/table/utils/getTreeDepth.js +1 -3
- package/lib/table/utils/groupBy.js +1 -3
- package/lib/table/utils/index.d.ts +1 -0
- package/lib/table/utils/index.js +57 -49
- package/lib/table/utils/layeredSort.js +6 -2
- package/lib/table/utils/makeRecursiveMapper.js +1 -3
- package/lib/table/utils/others.d.ts +1 -1
- package/lib/table/utils/others.js +23 -18
- package/lib/table/utils/traverseColumn.js +1 -3
- package/lib/table/utils/tree-data-helpers/StrictTreeDataHelper.js +5 -7
- package/lib/table/utils/tree-data-helpers/TreeDataHelper.js +5 -7
- package/package.json +6 -2
- package/dist/kd-table.css +0 -422
- package/dist/kd-table.css.map +0 -1
- package/dist/kd-table.js +0 -38578
- package/dist/kd-table.js.map +0 -1
- package/dist/kd-table.min.css +0 -9
- package/dist/kd-table.min.js +0 -208
- package/dist/kd-table.min.js.map +0 -1
- package/es/table/base/helpers/__test__/visible-part.test.d.ts +0 -1
- package/es/table/base/helpers/__test__/visible-part.test.js +0 -28
- package/es/table/base/helpers/visible-part.d.ts +0 -23
- package/es/table/base/helpers/visible-part.js +0 -58
- package/es/table/pipeline/features/__test__/multiSelect.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/multiSelect.test.js +0 -152
- package/es/table/pipeline/features/__test__/rowDetail.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/rowDetail.test.js +0 -223
- package/es/table/pipeline/features/__test__/rowGrouping.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/rowGrouping.test.js +0 -120
- package/es/table/pipeline/features/__test__/singleSelect.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/singleSelect.test.js +0 -191
- package/es/table/pipeline/features/__test__/sort.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/sort.test.js +0 -213
- package/es/table/pipeline/features/__test__/tips.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/tips.test.js +0 -123
- package/es/table/pipeline/features/__test__/treeMode.test.d.ts +0 -1
- package/es/table/pipeline/features/__test__/treeMode.test.js +0 -202
- package/es/table/pipeline/features/filter/__test__/Filter.test.d.ts +0 -1
- package/es/table/pipeline/features/filter/__test__/Filter.test.js +0 -29
- package/lib/table/base/helpers/__test__/visible-part.test.d.ts +0 -1
- package/lib/table/base/helpers/__test__/visible-part.test.js +0 -31
- package/lib/table/base/helpers/visible-part.d.ts +0 -23
- package/lib/table/base/helpers/visible-part.js +0 -72
- package/lib/table/pipeline/features/__test__/multiSelect.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/multiSelect.test.js +0 -163
- package/lib/table/pipeline/features/__test__/rowDetail.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/rowDetail.test.js +0 -230
- package/lib/table/pipeline/features/__test__/rowGrouping.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/rowGrouping.test.js +0 -129
- package/lib/table/pipeline/features/__test__/singleSelect.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/singleSelect.test.js +0 -201
- package/lib/table/pipeline/features/__test__/sort.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/sort.test.js +0 -218
- package/lib/table/pipeline/features/__test__/tips.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/tips.test.js +0 -133
- package/lib/table/pipeline/features/__test__/treeMode.test.d.ts +0 -1
- package/lib/table/pipeline/features/__test__/treeMode.test.js +0 -206
- package/lib/table/pipeline/features/filter/__test__/Filter.test.d.ts +0 -1
- package/lib/table/pipeline/features/filter/__test__/Filter.test.js +0 -36
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
3
|
-
import { singleSelect } from '../singleSelect';
|
|
4
|
-
import { useTablePipeline } from '../../pipeline';
|
|
5
|
-
import { mount } from 'enzyme';
|
|
6
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
var dataSource = [{
|
|
9
|
-
id: '1',
|
|
10
|
-
name: '阿里巴巴网络技术有限公司',
|
|
11
|
-
amount: '600,000.00(CNY)',
|
|
12
|
-
dept: '招商银行丨杭州分行',
|
|
13
|
-
applier: 'James Collier'
|
|
14
|
-
}, {
|
|
15
|
-
id: '2',
|
|
16
|
-
name: '阿里巴巴网络技术有限公司',
|
|
17
|
-
amount: '600,000.00(CNY)',
|
|
18
|
-
dept: '建设银行丨未来科技城',
|
|
19
|
-
applier: 'Philip Burke'
|
|
20
|
-
}, {
|
|
21
|
-
id: '3',
|
|
22
|
-
name: '阿里巴巴网络技术有限公司',
|
|
23
|
-
amount: '600,000.00(CNY)',
|
|
24
|
-
dept: '交通银行丨浙大路支行',
|
|
25
|
-
applier: 'Wesley Cruz'
|
|
26
|
-
}, {
|
|
27
|
-
id: '4',
|
|
28
|
-
name: '阿里巴巴网络技术有限公司',
|
|
29
|
-
amount: '600,000.00(CNY)',
|
|
30
|
-
dept: '招商银行丨庆春路支行',
|
|
31
|
-
applier: 'Billy Horton'
|
|
32
|
-
}, {
|
|
33
|
-
id: '5',
|
|
34
|
-
name: '阿里巴巴网络技术有限公司',
|
|
35
|
-
amount: '600,000.00(CNY)',
|
|
36
|
-
dept: '招商银行丨文一路分行',
|
|
37
|
-
applier: 'Paul Tran'
|
|
38
|
-
}, {
|
|
39
|
-
id: '6',
|
|
40
|
-
name: '阿里巴巴网络技术有限公司',
|
|
41
|
-
amount: '600,000.00(CNY)',
|
|
42
|
-
dept: '农业银行丨杭州分行',
|
|
43
|
-
applier: 'Anna Poole'
|
|
44
|
-
}];
|
|
45
|
-
var columns = [{
|
|
46
|
-
code: 'name',
|
|
47
|
-
width: 220,
|
|
48
|
-
name: '公司名称'
|
|
49
|
-
}, {
|
|
50
|
-
code: 'amount',
|
|
51
|
-
width: 160,
|
|
52
|
-
align: 'right',
|
|
53
|
-
name: '金额'
|
|
54
|
-
}, {
|
|
55
|
-
code: 'dept',
|
|
56
|
-
width: 160,
|
|
57
|
-
name: '金融机构'
|
|
58
|
-
}, {
|
|
59
|
-
code: 'applier',
|
|
60
|
-
width: 120,
|
|
61
|
-
name: '申请人'
|
|
62
|
-
}];
|
|
63
|
-
|
|
64
|
-
function Radio(_ref) {
|
|
65
|
-
var checked = _ref.checked,
|
|
66
|
-
disabled = _ref.disabled,
|
|
67
|
-
onChange = _ref.onChange;
|
|
68
|
-
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("input", {
|
|
69
|
-
type: 'radio',
|
|
70
|
-
disabled: disabled,
|
|
71
|
-
checked: checked,
|
|
72
|
-
onChange: onChange
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
describe('singleSelect 单元测试', function () {
|
|
77
|
-
var opts = {
|
|
78
|
-
value: '1',
|
|
79
|
-
clickArea: 'cell',
|
|
80
|
-
highlightRowWhenSelected: true,
|
|
81
|
-
isDisabled: function isDisabled(row, rowIndex) {
|
|
82
|
-
var _context;
|
|
83
|
-
|
|
84
|
-
return _includesInstanceProperty(_context = ['4', '5', '6']).call(_context, row.id);
|
|
85
|
-
},
|
|
86
|
-
onChange: jest.fn()
|
|
87
|
-
};
|
|
88
|
-
var newPipeline = null;
|
|
89
|
-
beforeEach(function () {
|
|
90
|
-
var _renderHook = renderHook(function () {
|
|
91
|
-
return useTablePipeline({
|
|
92
|
-
primaryKey: 'id',
|
|
93
|
-
components: {
|
|
94
|
-
Radio: Radio
|
|
95
|
-
}
|
|
96
|
-
}).input({
|
|
97
|
-
dataSource: dataSource,
|
|
98
|
-
columns: columns
|
|
99
|
-
});
|
|
100
|
-
}),
|
|
101
|
-
result = _renderHook.result;
|
|
102
|
-
|
|
103
|
-
var tablePipeline = result.current;
|
|
104
|
-
newPipeline = singleSelect(opts)(tablePipeline);
|
|
105
|
-
});
|
|
106
|
-
afterEach(function () {
|
|
107
|
-
newPipeline = null;
|
|
108
|
-
opts.onChange.mockClear();
|
|
109
|
-
});
|
|
110
|
-
it('初始渲染', function () {
|
|
111
|
-
var col = newPipeline.getColumns(); // 表格会在最后补一个空白列,加上单选列所以有6列
|
|
112
|
-
|
|
113
|
-
expect(col.length).toBe(6);
|
|
114
|
-
expect(col[0].code).toBe('__SELECT');
|
|
115
|
-
});
|
|
116
|
-
it('getCellProps', function () {
|
|
117
|
-
var col = newPipeline.getColumns();
|
|
118
|
-
var cellProps = col[0].getCellProps('', newPipeline.getDataSource()[0], 0);
|
|
119
|
-
expect(cellProps.style).toEqual({
|
|
120
|
-
cursor: 'pointer'
|
|
121
|
-
});
|
|
122
|
-
expect(opts.onChange).not.toHaveBeenCalled();
|
|
123
|
-
cellProps.onClick();
|
|
124
|
-
expect(opts.onChange).toHaveBeenCalled();
|
|
125
|
-
});
|
|
126
|
-
it('单元格渲染', function () {
|
|
127
|
-
var col = newPipeline.getColumns();
|
|
128
|
-
var wrapper = mount(col[0].render('', newPipeline.getDataSource()[0], 0));
|
|
129
|
-
expect(_findInstanceProperty(wrapper).call(wrapper, 'Radio').length).toBe(1);
|
|
130
|
-
});
|
|
131
|
-
it('触发区域为radio', function () {
|
|
132
|
-
var _renderHook2 = renderHook(function () {
|
|
133
|
-
return useTablePipeline({
|
|
134
|
-
primaryKey: 'id',
|
|
135
|
-
components: {
|
|
136
|
-
Radio: Radio
|
|
137
|
-
}
|
|
138
|
-
}).input({
|
|
139
|
-
dataSource: dataSource,
|
|
140
|
-
columns: columns
|
|
141
|
-
});
|
|
142
|
-
}),
|
|
143
|
-
result = _renderHook2.result;
|
|
144
|
-
|
|
145
|
-
var tablePipeline = result.current;
|
|
146
|
-
opts.clickArea = 'radio';
|
|
147
|
-
var newPipeline = singleSelect(opts)(tablePipeline);
|
|
148
|
-
var col = newPipeline.getColumns();
|
|
149
|
-
var wrapper = mount(col[0].render('', newPipeline.getDataSource()[0], 0)); // Radio 触发onChange
|
|
150
|
-
|
|
151
|
-
var input = _findInstanceProperty(wrapper).call(wrapper, 'input');
|
|
152
|
-
|
|
153
|
-
input.simulate('change');
|
|
154
|
-
expect(opts.onChange).toHaveBeenCalled();
|
|
155
|
-
opts.clickArea = 'cell';
|
|
156
|
-
});
|
|
157
|
-
it('appendRowPropsGetter', function () {
|
|
158
|
-
var props = newPipeline.getProps();
|
|
159
|
-
var rowProps = props.getRowProps(newPipeline.getDataSource()[0], 0);
|
|
160
|
-
expect(rowProps.className).toBe('highlight');
|
|
161
|
-
expect(rowProps.style).toEqual({});
|
|
162
|
-
});
|
|
163
|
-
it('触发区域为row', function () {
|
|
164
|
-
var _renderHook3 = renderHook(function () {
|
|
165
|
-
return useTablePipeline({
|
|
166
|
-
primaryKey: 'id',
|
|
167
|
-
components: {
|
|
168
|
-
Radio: Radio
|
|
169
|
-
}
|
|
170
|
-
}).input({
|
|
171
|
-
dataSource: dataSource,
|
|
172
|
-
columns: columns
|
|
173
|
-
});
|
|
174
|
-
}),
|
|
175
|
-
result = _renderHook3.result;
|
|
176
|
-
|
|
177
|
-
var tablePipeline = result.current;
|
|
178
|
-
opts.clickArea = 'row';
|
|
179
|
-
var newPipeline = singleSelect(opts)(tablePipeline);
|
|
180
|
-
var props = newPipeline.getProps();
|
|
181
|
-
var rowProps = props.getRowProps(newPipeline.getDataSource()[0], 0);
|
|
182
|
-
expect(rowProps.style).toEqual({
|
|
183
|
-
cursor: 'pointer'
|
|
184
|
-
});
|
|
185
|
-
rowProps.onClick();
|
|
186
|
-
expect(opts.onChange).toHaveBeenCalled(); // disable的行没有样式
|
|
187
|
-
|
|
188
|
-
var rowProps1 = props.getRowProps(newPipeline.getDataSource()[4], 4);
|
|
189
|
-
expect(rowProps1.style).toEqual({});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
2
|
-
import { sort } from '../sort';
|
|
3
|
-
import { useTablePipeline } from '../../pipeline';
|
|
4
|
-
import { mount } from 'enzyme';
|
|
5
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
6
|
-
var dataSource = [{
|
|
7
|
-
id: '1',
|
|
8
|
-
prov: '湖北省',
|
|
9
|
-
confirm: 54406,
|
|
10
|
-
cure: 4793,
|
|
11
|
-
dead: 1457,
|
|
12
|
-
t: '2020-02-15 19:52:02'
|
|
13
|
-
}, {
|
|
14
|
-
id: '2',
|
|
15
|
-
prov: '广东省',
|
|
16
|
-
confirm: 1294,
|
|
17
|
-
cure: 409,
|
|
18
|
-
dead: 2,
|
|
19
|
-
t: '2020-02-15 19:52:02'
|
|
20
|
-
}, {
|
|
21
|
-
id: '3',
|
|
22
|
-
prov: '河南省',
|
|
23
|
-
confirm: 1212,
|
|
24
|
-
cure: 390,
|
|
25
|
-
dead: 13,
|
|
26
|
-
t: '2020-02-15 19:52:02'
|
|
27
|
-
}, {
|
|
28
|
-
id: '4',
|
|
29
|
-
prov: '浙江省',
|
|
30
|
-
confirm: 1000,
|
|
31
|
-
cure: 428,
|
|
32
|
-
dead: 0,
|
|
33
|
-
t: '2020-02-15 19:52:02'
|
|
34
|
-
}, {
|
|
35
|
-
id: '5',
|
|
36
|
-
prov: '湖南省',
|
|
37
|
-
confirm: 1000,
|
|
38
|
-
cure: 417,
|
|
39
|
-
dead: 2,
|
|
40
|
-
t: '2020-02-15 19:52:02'
|
|
41
|
-
}];
|
|
42
|
-
var columns = [{
|
|
43
|
-
code: 'prov',
|
|
44
|
-
name: '省份',
|
|
45
|
-
width: 150,
|
|
46
|
-
features: {
|
|
47
|
-
sortable: true
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
code: 'confirm',
|
|
51
|
-
name: '确诊',
|
|
52
|
-
width: 100,
|
|
53
|
-
align: 'right',
|
|
54
|
-
features: {
|
|
55
|
-
sortable: true
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
code: 'cure',
|
|
59
|
-
name: '治愈',
|
|
60
|
-
width: 100,
|
|
61
|
-
align: 'right',
|
|
62
|
-
features: {
|
|
63
|
-
sortable: true
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
code: 'dead',
|
|
67
|
-
name: '死亡',
|
|
68
|
-
width: 100,
|
|
69
|
-
align: 'right',
|
|
70
|
-
features: {
|
|
71
|
-
sortable: true
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
code: 't',
|
|
75
|
-
name: '更新时间',
|
|
76
|
-
width: 180,
|
|
77
|
-
features: {
|
|
78
|
-
sortable: true
|
|
79
|
-
}
|
|
80
|
-
}];
|
|
81
|
-
describe('sort 单元测试', function () {
|
|
82
|
-
var opts = {
|
|
83
|
-
defaultSorts: [{
|
|
84
|
-
code: 'cure',
|
|
85
|
-
order: 'asc'
|
|
86
|
-
}],
|
|
87
|
-
highlightColumnWhenActive: true,
|
|
88
|
-
mode: 'single',
|
|
89
|
-
keepDataSource: false,
|
|
90
|
-
onChangeSorts: jest.fn()
|
|
91
|
-
};
|
|
92
|
-
var newPipeline = null;
|
|
93
|
-
beforeEach(function () {
|
|
94
|
-
var _renderHook = renderHook(function () {
|
|
95
|
-
return useTablePipeline({
|
|
96
|
-
primaryKey: 'id'
|
|
97
|
-
}).input({
|
|
98
|
-
dataSource: dataSource,
|
|
99
|
-
columns: columns
|
|
100
|
-
});
|
|
101
|
-
}),
|
|
102
|
-
result = _renderHook.result;
|
|
103
|
-
|
|
104
|
-
var tablePipeline = result.current;
|
|
105
|
-
newPipeline = sort(opts)(tablePipeline);
|
|
106
|
-
});
|
|
107
|
-
afterEach(function () {
|
|
108
|
-
newPipeline = null;
|
|
109
|
-
opts.onChangeSorts.mockClear();
|
|
110
|
-
});
|
|
111
|
-
it('初始化数据', function () {
|
|
112
|
-
// 默认cure列升序排序
|
|
113
|
-
expect(newPipeline.getDataSource()[0]).toEqual({
|
|
114
|
-
id: '3',
|
|
115
|
-
prov: '河南省',
|
|
116
|
-
confirm: 1212,
|
|
117
|
-
cure: 390,
|
|
118
|
-
dead: 13,
|
|
119
|
-
t: '2020-02-15 19:52:02'
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
it('列头单元格渲染', function () {
|
|
123
|
-
var col = newPipeline.getColumns();
|
|
124
|
-
var wrapper = mount(col[0].title);
|
|
125
|
-
expect(_findInstanceProperty(wrapper).call(wrapper, 'SortIcon').length).toBe(1); // 列头单元格
|
|
126
|
-
|
|
127
|
-
var div = _findInstanceProperty(wrapper).call(wrapper, 'div').at(0);
|
|
128
|
-
|
|
129
|
-
div.simulate('click');
|
|
130
|
-
expect(opts.onChangeSorts).toBeCalledWith([{
|
|
131
|
-
code: 'prov',
|
|
132
|
-
order: 'desc'
|
|
133
|
-
}], {
|
|
134
|
-
code: 'prov',
|
|
135
|
-
order: 'desc'
|
|
136
|
-
});
|
|
137
|
-
expect(1).toBe(1);
|
|
138
|
-
});
|
|
139
|
-
it('getCellProps', function () {
|
|
140
|
-
var col = newPipeline.getColumns();
|
|
141
|
-
var cellProps = col[2].getCellProps(4793, newPipeline.getDataSource()[0], 0);
|
|
142
|
-
expect(cellProps.style).toEqual({
|
|
143
|
-
background: 'var(--highlight-bgcolor)'
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
it('keepDataSource为true,数据不变', function () {
|
|
147
|
-
var _renderHook2 = renderHook(function () {
|
|
148
|
-
return useTablePipeline({
|
|
149
|
-
primaryKey: 'id'
|
|
150
|
-
}).input({
|
|
151
|
-
dataSource: dataSource,
|
|
152
|
-
columns: columns
|
|
153
|
-
});
|
|
154
|
-
}),
|
|
155
|
-
result = _renderHook2.result;
|
|
156
|
-
|
|
157
|
-
var tablePipeline = result.current;
|
|
158
|
-
opts.keepDataSource = true;
|
|
159
|
-
var newPipeline = sort(opts)(tablePipeline);
|
|
160
|
-
expect(newPipeline.getDataSource()[0].id).toBe('1');
|
|
161
|
-
opts.keepDataSource = false;
|
|
162
|
-
});
|
|
163
|
-
it('多列排序', function () {
|
|
164
|
-
var _renderHook3 = renderHook(function () {
|
|
165
|
-
return useTablePipeline({
|
|
166
|
-
primaryKey: 'id'
|
|
167
|
-
}).input({
|
|
168
|
-
dataSource: dataSource,
|
|
169
|
-
columns: columns
|
|
170
|
-
});
|
|
171
|
-
}),
|
|
172
|
-
result = _renderHook3.result;
|
|
173
|
-
|
|
174
|
-
var tablePipeline = result.current;
|
|
175
|
-
opts.defaultSorts = [{
|
|
176
|
-
code: 'confirm',
|
|
177
|
-
order: 'desc'
|
|
178
|
-
}, {
|
|
179
|
-
code: 'cure',
|
|
180
|
-
order: 'asc'
|
|
181
|
-
}];
|
|
182
|
-
opts.mode = 'multiple';
|
|
183
|
-
var newPipeline = sort(opts)(tablePipeline); // confirm 降序,cure升序
|
|
184
|
-
|
|
185
|
-
expect(newPipeline.getDataSource()[3].confirm).toBe(1000);
|
|
186
|
-
expect(newPipeline.getDataSource()[3].cure).toBe(417);
|
|
187
|
-
expect(newPipeline.getDataSource()[4].confirm).toBe(1000);
|
|
188
|
-
expect(newPipeline.getDataSource()[4].cure).toBe(428);
|
|
189
|
-
var col = newPipeline.getColumns();
|
|
190
|
-
var confirmWrapper = mount(col[1].title); // 列头单元格
|
|
191
|
-
|
|
192
|
-
var div = _findInstanceProperty(confirmWrapper).call(confirmWrapper, 'div').at(0);
|
|
193
|
-
|
|
194
|
-
div.simulate('click'); // confirm 列初始是降序,点击后是升序
|
|
195
|
-
// calls[0][1]表示第1次调用的第二个参数
|
|
196
|
-
|
|
197
|
-
expect(opts.onChangeSorts.mock.calls[0][1]).toEqual({
|
|
198
|
-
code: 'confirm',
|
|
199
|
-
order: 'asc'
|
|
200
|
-
});
|
|
201
|
-
opts.onChangeSorts.mockClear();
|
|
202
|
-
var cureWrapper = mount(col[2].title);
|
|
203
|
-
|
|
204
|
-
var div1 = _findInstanceProperty(cureWrapper).call(cureWrapper, 'div').at(0);
|
|
205
|
-
|
|
206
|
-
div1.simulate('click'); // confirm 列初始是升序,点击后没有排序
|
|
207
|
-
|
|
208
|
-
expect(opts.onChangeSorts.mock.calls[0][1]).toEqual({
|
|
209
|
-
code: 'cure',
|
|
210
|
-
order: 'none'
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
2
|
-
import { tips } from '../tips';
|
|
3
|
-
import { useTablePipeline } from '../../pipeline';
|
|
4
|
-
import { mount } from 'enzyme';
|
|
5
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
var dataSource = [{
|
|
8
|
-
id: '1',
|
|
9
|
-
prov: '湖北省',
|
|
10
|
-
confirm: 54406,
|
|
11
|
-
cure: 4793,
|
|
12
|
-
dead: 1457,
|
|
13
|
-
t: '2020-02-15 19:52:02'
|
|
14
|
-
}, {
|
|
15
|
-
id: '2',
|
|
16
|
-
prov: '广东省',
|
|
17
|
-
confirm: 1294,
|
|
18
|
-
cure: 409,
|
|
19
|
-
dead: 2,
|
|
20
|
-
t: '2020-02-15 19:52:02'
|
|
21
|
-
}, {
|
|
22
|
-
id: '3',
|
|
23
|
-
prov: '河南省',
|
|
24
|
-
confirm: 1212,
|
|
25
|
-
cure: 390,
|
|
26
|
-
dead: 13,
|
|
27
|
-
t: '2020-02-15 19:52:02'
|
|
28
|
-
}, {
|
|
29
|
-
id: '4',
|
|
30
|
-
prov: '浙江省',
|
|
31
|
-
confirm: 1000,
|
|
32
|
-
cure: 428,
|
|
33
|
-
dead: 0,
|
|
34
|
-
t: '2020-02-15 19:52:02'
|
|
35
|
-
}, {
|
|
36
|
-
id: '5',
|
|
37
|
-
prov: '湖南省',
|
|
38
|
-
confirm: 1000,
|
|
39
|
-
cure: 417,
|
|
40
|
-
dead: 2,
|
|
41
|
-
t: '2020-02-15 19:52:02'
|
|
42
|
-
}];
|
|
43
|
-
var columns = [{
|
|
44
|
-
code: 'prov',
|
|
45
|
-
name: '省份',
|
|
46
|
-
width: 150,
|
|
47
|
-
features: {
|
|
48
|
-
tips: '省份信息'
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
code: 'confirm',
|
|
52
|
-
name: '确诊',
|
|
53
|
-
width: 100,
|
|
54
|
-
align: 'right',
|
|
55
|
-
features: {
|
|
56
|
-
tips: '确诊数量'
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
code: 'cure',
|
|
60
|
-
name: '治愈',
|
|
61
|
-
width: 100,
|
|
62
|
-
align: 'right'
|
|
63
|
-
}, {
|
|
64
|
-
code: 'dead',
|
|
65
|
-
name: '死亡',
|
|
66
|
-
width: 100,
|
|
67
|
-
align: 'right'
|
|
68
|
-
}, {
|
|
69
|
-
code: 't',
|
|
70
|
-
name: '更新时间',
|
|
71
|
-
width: 180
|
|
72
|
-
}];
|
|
73
|
-
|
|
74
|
-
function Tooltip(_ref) {
|
|
75
|
-
var title = _ref.title,
|
|
76
|
-
children = _ref.children;
|
|
77
|
-
return /*#__PURE__*/React.createElement("div", null, title);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
describe('tips 单元测试', function () {
|
|
81
|
-
var newPipeline = null;
|
|
82
|
-
beforeEach(function () {
|
|
83
|
-
var _renderHook = renderHook(function () {
|
|
84
|
-
return useTablePipeline({
|
|
85
|
-
primaryKey: 'id',
|
|
86
|
-
components: {
|
|
87
|
-
Tooltip: Tooltip
|
|
88
|
-
}
|
|
89
|
-
}).input({
|
|
90
|
-
dataSource: dataSource,
|
|
91
|
-
columns: columns
|
|
92
|
-
});
|
|
93
|
-
}),
|
|
94
|
-
result = _renderHook.result;
|
|
95
|
-
|
|
96
|
-
var tablePipeline = result.current;
|
|
97
|
-
newPipeline = tips()(tablePipeline);
|
|
98
|
-
});
|
|
99
|
-
afterEach(function () {
|
|
100
|
-
newPipeline = null;
|
|
101
|
-
});
|
|
102
|
-
it('初始化时存在Tooltip组件', function () {
|
|
103
|
-
var col = newPipeline.getColumns();
|
|
104
|
-
var wrapper = mount(col[0].title);
|
|
105
|
-
expect(_findInstanceProperty(wrapper).call(wrapper, 'Tooltip').length).toBe(1);
|
|
106
|
-
});
|
|
107
|
-
it('不传Tooltip', function () {
|
|
108
|
-
var _renderHook2 = renderHook(function () {
|
|
109
|
-
return useTablePipeline({
|
|
110
|
-
primaryKey: 'id'
|
|
111
|
-
}).input({
|
|
112
|
-
dataSource: dataSource,
|
|
113
|
-
columns: columns
|
|
114
|
-
});
|
|
115
|
-
}),
|
|
116
|
-
result = _renderHook2.result;
|
|
117
|
-
|
|
118
|
-
var tablePipeline = result.current;
|
|
119
|
-
expect(function () {
|
|
120
|
-
return tips()(tablePipeline);
|
|
121
|
-
}).toThrow(Error);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|