@globalpayments/vega 2.20.1 → 2.21.0
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/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/vega-breadcrumb.cjs.entry.js +2 -4
- package/dist/cjs/vega-calendar_3.cjs.entry.js +48 -12
- package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
- package/dist/cjs/vega-input-phone-number.cjs.entry.js +1 -0
- package/dist/cjs/vega-input.cjs.entry.js +17 -6
- package/dist/cjs/vega-table_8.cjs.entry.js +64 -32
- package/dist/cjs/vega.cjs.js +1 -1
- package/dist/collection/components/vega-breadcrumb/slimmers/controllers/vega-breadcrumb-click-controller.js +2 -4
- package/dist/collection/components/vega-calendar/vega-calendar-event/slimmers/controllers/vega-calendar-sub-state-controller.js +15 -1
- package/dist/collection/components/vega-calendar/vega-calendar-event/slimmers/renderers/vega-calendar-event-renderer.js +15 -10
- package/dist/collection/components/vega-calendar/vega-calendar-event/vega-calendar-event.js +3 -1
- package/dist/collection/components/vega-calendar/vega-calendar.js +37 -0
- package/dist/collection/components/vega-input/slimmers/controllers/vega-input-mask-config-controller.js +1 -1
- package/dist/collection/components/vega-input/vega-input.js +1 -1
- package/dist/collection/components/vega-input-phone-number/slimmers/renderers/phone-number-input-renderer.js +1 -0
- package/dist/collection/components/vega-table/slimmers/controllers/vega-table-data-source-controller.js +1 -3
- package/dist/collection/components/vega-table/slimmers/controllers/vega-table-sort-controller.js +30 -29
- package/dist/collection/components/vega-table/slimmers/controllers/vega-table-sorter.js +33 -0
- package/dist/collection/components/vega-table/test/vega-table-sorter.test.js +508 -0
- package/dist/collection/helpers/formatter/string-formatter/custom-formatter-strategy.js +16 -4
- package/dist/collection/helpers/formatter/test/string-formatter/custom-formatter-strategy.test.js +7 -2
- package/dist/collection/helpers/vega-telemetry-helper/test/vega-env-manager.test.js +1 -1
- package/dist/collection/helpers/vega-telemetry-helper/vega-env-manager.js +2 -2
- package/dist/collection/utils/e2e-utils.js +6 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/vega-breadcrumb.entry.js +2 -4
- package/dist/esm/vega-calendar_3.entry.js +48 -12
- package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
- package/dist/esm/vega-input-phone-number.entry.js +1 -0
- package/dist/esm/vega-input.entry.js +17 -6
- package/dist/esm/vega-table_8.entry.js +64 -32
- package/dist/esm/vega.js +1 -1
- package/dist/types/components/vega-calendar/vega-calendar-event/slimmers/controllers/vega-calendar-sub-state-controller.d.ts +1 -0
- package/dist/types/components/vega-calendar/vega-calendar-event/slimmers/renderers/vega-calendar-event-renderer.d.ts +2 -1
- package/dist/types/components/vega-calendar/vega-calendar-event/vega-calendar-event.d.ts +1 -0
- package/dist/types/components/vega-calendar/vega-calendar.d.ts +11 -0
- package/dist/types/components/vega-input/types.d.ts +1 -0
- package/dist/types/components/vega-table/slimmers/controllers/vega-table-sort-controller.d.ts +3 -3
- package/dist/types/components/vega-table/slimmers/controllers/vega-table-sorter.d.ts +27 -0
- package/dist/types/components/vega-table/test/vega-table-sorter.test.d.ts +1 -0
- package/dist/types/components/vega-table/vega-table.d.ts +3 -2
- package/dist/types/components.d.ts +8 -0
- package/dist/types/helpers/formatter/string-formatter/custom-formatter-strategy.d.ts +6 -3
- package/dist/types/utils/e2e-utils.d.ts +2 -0
- package/dist/vega/p-1f52fbdc.entry.js +1 -0
- package/dist/vega/p-5f136969.entry.js +1 -0
- package/dist/vega/p-5f377954.js +1 -1
- package/dist/vega/p-ae403881.entry.js +1 -0
- package/dist/vega/{p-a6454c72.entry.js → p-cf0c2937.entry.js} +1 -1
- package/dist/vega/{p-6cc1716b.entry.js → p-e66d54c5.entry.js} +1 -1
- package/dist/vega/vega.esm.js +1 -1
- package/package.json +1 -1
- package/dist/vega/p-8be4196f.entry.js +0 -1
- package/dist/vega/p-cfdf4a95.entry.js +0 -1
- package/dist/vega/p-e7da829b.entry.js +0 -1
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { VegaTableSortController } from '../slimmers/controllers/vega-table-sort-controller';
|
|
2
|
+
import { VegaTableSorter } from '../slimmers/controllers/vega-table-sorter';
|
|
3
|
+
describe('VegaTableSorter', () => {
|
|
4
|
+
const sortController = new VegaTableSortController();
|
|
5
|
+
function sortData(data, sorters) {
|
|
6
|
+
const updatedSorters = sorters.map((s) => {
|
|
7
|
+
return new VegaTableSorter(s.prop, s.order, s.sorter);
|
|
8
|
+
});
|
|
9
|
+
return sortController.sortData([...data], updatedSorters);
|
|
10
|
+
}
|
|
11
|
+
describe('should handle single sorting as expected', () => {
|
|
12
|
+
it('should sort by amount in desc', () => {
|
|
13
|
+
const data = [
|
|
14
|
+
{
|
|
15
|
+
amount: 100,
|
|
16
|
+
balance: 100,
|
|
17
|
+
date: '01/01/2022',
|
|
18
|
+
key: '1',
|
|
19
|
+
name: 'A',
|
|
20
|
+
status: 'In Progress',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
amount: 300,
|
|
24
|
+
balance: 200,
|
|
25
|
+
date: '01/02/2022',
|
|
26
|
+
key: '2',
|
|
27
|
+
name: 'D',
|
|
28
|
+
status: 'In Progress',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
amount: 400,
|
|
32
|
+
balance: 300,
|
|
33
|
+
date: '01/03/2022',
|
|
34
|
+
key: '3',
|
|
35
|
+
name: 'B',
|
|
36
|
+
status: 'Not Started',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
amount: 200,
|
|
40
|
+
balance: 400,
|
|
41
|
+
date: '01/04/2022',
|
|
42
|
+
key: '4',
|
|
43
|
+
name: 'C',
|
|
44
|
+
status: 'Pending',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
const sorters = [
|
|
48
|
+
{
|
|
49
|
+
prop: 'amount',
|
|
50
|
+
order: 'desc',
|
|
51
|
+
sorter: (a, b) => {
|
|
52
|
+
return a['amount'] - b['amount'];
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
expect(sortData(data, sorters)).toEqual([
|
|
57
|
+
{
|
|
58
|
+
amount: 400,
|
|
59
|
+
balance: 300,
|
|
60
|
+
date: '01/03/2022',
|
|
61
|
+
key: '3',
|
|
62
|
+
name: 'B',
|
|
63
|
+
status: 'Not Started',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
amount: 300,
|
|
67
|
+
balance: 200,
|
|
68
|
+
date: '01/02/2022',
|
|
69
|
+
key: '2',
|
|
70
|
+
name: 'D',
|
|
71
|
+
status: 'In Progress',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
amount: 200,
|
|
75
|
+
balance: 400,
|
|
76
|
+
date: '01/04/2022',
|
|
77
|
+
key: '4',
|
|
78
|
+
name: 'C',
|
|
79
|
+
status: 'Pending',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
amount: 100,
|
|
83
|
+
balance: 100,
|
|
84
|
+
date: '01/01/2022',
|
|
85
|
+
key: '1',
|
|
86
|
+
name: 'A',
|
|
87
|
+
status: 'In Progress',
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
it('should sort by balance in desc', () => {
|
|
92
|
+
const data = [
|
|
93
|
+
{
|
|
94
|
+
amount: 100,
|
|
95
|
+
balance: 100,
|
|
96
|
+
date: '01/01/2022',
|
|
97
|
+
key: '1',
|
|
98
|
+
name: 'A',
|
|
99
|
+
status: 'In Progress',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
amount: 300,
|
|
103
|
+
balance: 200,
|
|
104
|
+
date: '01/02/2022',
|
|
105
|
+
key: '2',
|
|
106
|
+
name: 'D',
|
|
107
|
+
status: 'In Progress',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
amount: 400,
|
|
111
|
+
balance: 300,
|
|
112
|
+
date: '01/03/2022',
|
|
113
|
+
key: '3',
|
|
114
|
+
name: 'B',
|
|
115
|
+
status: 'Not Started',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
amount: 200,
|
|
119
|
+
balance: 400,
|
|
120
|
+
date: '01/04/2022',
|
|
121
|
+
key: '4',
|
|
122
|
+
name: 'C',
|
|
123
|
+
status: 'Pending',
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
const sorters = [
|
|
127
|
+
{
|
|
128
|
+
prop: 'balance',
|
|
129
|
+
order: 'desc',
|
|
130
|
+
sorter: (a, b) => {
|
|
131
|
+
return a['balance'] - b['balance'];
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
expect(sortData(data, sorters)).toEqual([
|
|
136
|
+
{
|
|
137
|
+
amount: 200,
|
|
138
|
+
balance: 400,
|
|
139
|
+
date: '01/04/2022',
|
|
140
|
+
key: '4',
|
|
141
|
+
name: 'C',
|
|
142
|
+
status: 'Pending',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
amount: 400,
|
|
146
|
+
balance: 300,
|
|
147
|
+
date: '01/03/2022',
|
|
148
|
+
key: '3',
|
|
149
|
+
name: 'B',
|
|
150
|
+
status: 'Not Started',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
amount: 300,
|
|
154
|
+
balance: 200,
|
|
155
|
+
date: '01/02/2022',
|
|
156
|
+
key: '2',
|
|
157
|
+
name: 'D',
|
|
158
|
+
status: 'In Progress',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
amount: 100,
|
|
162
|
+
balance: 100,
|
|
163
|
+
date: '01/01/2022',
|
|
164
|
+
key: '1',
|
|
165
|
+
name: 'A',
|
|
166
|
+
status: 'In Progress',
|
|
167
|
+
},
|
|
168
|
+
]);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe('should handle multi-sorting sorting as expected', () => {
|
|
172
|
+
it('should sort by age, then by score and where age is the same, sort by score', () => {
|
|
173
|
+
const data = [
|
|
174
|
+
{ age: 25, score: 90 },
|
|
175
|
+
{ age: 20, score: 85 },
|
|
176
|
+
{ age: 25, score: 95 },
|
|
177
|
+
{ age: 30, score: 85 },
|
|
178
|
+
{ age: 20, score: 80 },
|
|
179
|
+
{ age: 20, score: 100 },
|
|
180
|
+
{ age: 25, score: 85 },
|
|
181
|
+
{ age: 25, score: 85 },
|
|
182
|
+
{ age: 30, score: 90 },
|
|
183
|
+
{ age: 30, score: 90 },
|
|
184
|
+
{ age: 30, score: 85 },
|
|
185
|
+
];
|
|
186
|
+
const sorters = [
|
|
187
|
+
{
|
|
188
|
+
prop: 'age',
|
|
189
|
+
order: 'asc',
|
|
190
|
+
sorter: (a, b) => {
|
|
191
|
+
return a['age'] - b['age'];
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
prop: 'score',
|
|
196
|
+
order: 'asc',
|
|
197
|
+
sorter: (a, b) => {
|
|
198
|
+
return a['score'] - b['score'];
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
expect(sortData(data, sorters)).toEqual([
|
|
203
|
+
{ age: 20, score: 80 },
|
|
204
|
+
{ age: 20, score: 85 },
|
|
205
|
+
{ age: 20, score: 100 },
|
|
206
|
+
{ age: 25, score: 85 },
|
|
207
|
+
{ age: 25, score: 85 },
|
|
208
|
+
{ age: 25, score: 90 },
|
|
209
|
+
{ age: 25, score: 95 },
|
|
210
|
+
{ age: 30, score: 85 },
|
|
211
|
+
{ age: 30, score: 85 },
|
|
212
|
+
{ age: 30, score: 90 },
|
|
213
|
+
{ age: 30, score: 90 },
|
|
214
|
+
]);
|
|
215
|
+
});
|
|
216
|
+
it('should sort by name, age and where name is the same, sort by age', () => {
|
|
217
|
+
const data = [
|
|
218
|
+
{ name: 'Alice', age: 25, score: 88 },
|
|
219
|
+
{ name: 'Bob', age: 22, score: 95 },
|
|
220
|
+
{ name: 'Charlie', age: 25, score: 82 },
|
|
221
|
+
{ name: 'Alice', age: 28, score: 78 },
|
|
222
|
+
{ name: 'Bob', age: 22, score: 90 },
|
|
223
|
+
];
|
|
224
|
+
const sorters = [
|
|
225
|
+
{
|
|
226
|
+
prop: 'name',
|
|
227
|
+
order: 'asc',
|
|
228
|
+
sorter: (a, b) => {
|
|
229
|
+
return a.name.localeCompare(b.name);
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
prop: 'age',
|
|
234
|
+
order: 'asc',
|
|
235
|
+
sorter: (a, b) => {
|
|
236
|
+
return a['age'] - b['age'];
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
expect(sortData(data, sorters)).toEqual([
|
|
241
|
+
{ name: 'Alice', age: 25, score: 88 },
|
|
242
|
+
{ name: 'Alice', age: 28, score: 78 },
|
|
243
|
+
{ name: 'Bob', age: 22, score: 95 },
|
|
244
|
+
{ name: 'Bob', age: 22, score: 90 },
|
|
245
|
+
{ name: 'Charlie', age: 25, score: 82 },
|
|
246
|
+
]);
|
|
247
|
+
});
|
|
248
|
+
it('should sort by age, score and where age is the same, sort by score', () => {
|
|
249
|
+
const data = [
|
|
250
|
+
{ age: 25, score: 88 },
|
|
251
|
+
{ age: 22, score: 95 },
|
|
252
|
+
{ age: 25, score: 82 },
|
|
253
|
+
{ age: 28, score: 78 },
|
|
254
|
+
{ age: 22, score: 90 },
|
|
255
|
+
];
|
|
256
|
+
const sorters = [
|
|
257
|
+
{
|
|
258
|
+
prop: 'age',
|
|
259
|
+
order: 'asc',
|
|
260
|
+
sorter: (a, b) => {
|
|
261
|
+
return a['age'] - b['age'];
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
prop: 'score',
|
|
266
|
+
order: 'asc',
|
|
267
|
+
sorter: (a, b) => {
|
|
268
|
+
return a['score'] - b['score'];
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
];
|
|
272
|
+
expect(sortData(data, sorters)).toEqual([
|
|
273
|
+
{ age: 22, score: 90 },
|
|
274
|
+
{ age: 22, score: 95 },
|
|
275
|
+
{ age: 25, score: 82 },
|
|
276
|
+
{ age: 25, score: 88 },
|
|
277
|
+
{ age: 28, score: 78 },
|
|
278
|
+
]);
|
|
279
|
+
});
|
|
280
|
+
it('should sort by name, age, score and where name is the same, sort by age, and where age is the same, sort by score', () => {
|
|
281
|
+
const data = [
|
|
282
|
+
{ name: 'Alice', age: 25, score: 88 },
|
|
283
|
+
{ name: 'Bob', age: 22, score: 95 },
|
|
284
|
+
{ name: 'Charlie', age: 25, score: 82 },
|
|
285
|
+
{ name: 'Alice', age: 28, score: 78 },
|
|
286
|
+
{ name: 'Bob', age: 22, score: 90 },
|
|
287
|
+
];
|
|
288
|
+
const sorters = [
|
|
289
|
+
{
|
|
290
|
+
prop: 'name',
|
|
291
|
+
order: 'asc',
|
|
292
|
+
sorter: (a, b) => {
|
|
293
|
+
return a.name.localeCompare(b.name);
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
prop: 'age',
|
|
298
|
+
order: 'asc',
|
|
299
|
+
sorter: (a, b) => {
|
|
300
|
+
return a['age'] - b['age'];
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
prop: 'score',
|
|
305
|
+
order: 'asc',
|
|
306
|
+
sorter: (a, b) => {
|
|
307
|
+
return a['score'] - b['score'];
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
expect(sortData(data, sorters)).toEqual([
|
|
312
|
+
{ name: 'Alice', age: 25, score: 88 },
|
|
313
|
+
{ name: 'Alice', age: 28, score: 78 },
|
|
314
|
+
{ name: 'Bob', age: 22, score: 90 },
|
|
315
|
+
{ name: 'Bob', age: 22, score: 95 },
|
|
316
|
+
{ name: 'Charlie', age: 25, score: 82 },
|
|
317
|
+
]);
|
|
318
|
+
});
|
|
319
|
+
it('should primarily sort by amount in desc order and if no tie in amount, secondary sorting of balance should not change sorted amount in desc', () => {
|
|
320
|
+
const data = [
|
|
321
|
+
{
|
|
322
|
+
amount: 100,
|
|
323
|
+
balance: 100,
|
|
324
|
+
date: '01/01/2022',
|
|
325
|
+
key: '1',
|
|
326
|
+
name: 'A',
|
|
327
|
+
status: 'In Progress',
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
amount: 300,
|
|
331
|
+
balance: 200,
|
|
332
|
+
date: '01/02/2022',
|
|
333
|
+
key: '2',
|
|
334
|
+
name: 'D',
|
|
335
|
+
status: 'In Progress',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
amount: 400,
|
|
339
|
+
balance: 300,
|
|
340
|
+
date: '01/03/2022',
|
|
341
|
+
key: '3',
|
|
342
|
+
name: 'B',
|
|
343
|
+
status: 'Not Started',
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
amount: 200,
|
|
347
|
+
balance: 400,
|
|
348
|
+
date: '01/04/2022',
|
|
349
|
+
key: '4',
|
|
350
|
+
name: 'C',
|
|
351
|
+
status: 'Pending',
|
|
352
|
+
},
|
|
353
|
+
];
|
|
354
|
+
const sorters = [
|
|
355
|
+
{
|
|
356
|
+
prop: 'amount',
|
|
357
|
+
order: 'desc',
|
|
358
|
+
sorter: (a, b) => {
|
|
359
|
+
return a['amount'] - b['amount'];
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
prop: 'balance',
|
|
364
|
+
order: 'desc',
|
|
365
|
+
sorter: (a, b) => {
|
|
366
|
+
return a['balance'] - b['balance'];
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
];
|
|
370
|
+
expect(sortData(data, sorters)).toEqual([
|
|
371
|
+
{
|
|
372
|
+
amount: 400,
|
|
373
|
+
balance: 300,
|
|
374
|
+
date: '01/03/2022',
|
|
375
|
+
key: '3',
|
|
376
|
+
name: 'B',
|
|
377
|
+
status: 'Not Started',
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
amount: 300,
|
|
381
|
+
balance: 200,
|
|
382
|
+
date: '01/02/2022',
|
|
383
|
+
key: '2',
|
|
384
|
+
name: 'D',
|
|
385
|
+
status: 'In Progress',
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
amount: 200,
|
|
389
|
+
balance: 400,
|
|
390
|
+
date: '01/04/2022',
|
|
391
|
+
key: '4',
|
|
392
|
+
name: 'C',
|
|
393
|
+
status: 'Pending',
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
amount: 100,
|
|
397
|
+
balance: 100,
|
|
398
|
+
date: '01/01/2022',
|
|
399
|
+
key: '1',
|
|
400
|
+
name: 'A',
|
|
401
|
+
status: 'In Progress',
|
|
402
|
+
},
|
|
403
|
+
]);
|
|
404
|
+
});
|
|
405
|
+
it('should sort by name A-Z then by amount from largest to smallest', () => {
|
|
406
|
+
const data = [
|
|
407
|
+
{
|
|
408
|
+
key: '1',
|
|
409
|
+
date: '01/03/2022',
|
|
410
|
+
name: 'C',
|
|
411
|
+
amount: 30,
|
|
412
|
+
amount2: 30,
|
|
413
|
+
balance: '$300',
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
key: '2',
|
|
417
|
+
date: '01/06/2022',
|
|
418
|
+
name: 'C',
|
|
419
|
+
amount: 20,
|
|
420
|
+
amount2: 20,
|
|
421
|
+
balance: '$400',
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
key: '3',
|
|
425
|
+
date: '01/05/2022',
|
|
426
|
+
name: 'C',
|
|
427
|
+
amount: 20,
|
|
428
|
+
amount2: 30,
|
|
429
|
+
balance: '$401',
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
key: '4',
|
|
433
|
+
date: '01/02/2022',
|
|
434
|
+
name: 'B',
|
|
435
|
+
amount: 20,
|
|
436
|
+
amount2: 125,
|
|
437
|
+
balance: '$200',
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
key: '5',
|
|
441
|
+
date: '01/04/2022',
|
|
442
|
+
name: 'D',
|
|
443
|
+
amount: 300,
|
|
444
|
+
amount2: 130,
|
|
445
|
+
balance: '$402',
|
|
446
|
+
},
|
|
447
|
+
];
|
|
448
|
+
const sorters = [
|
|
449
|
+
{
|
|
450
|
+
prop: 'name',
|
|
451
|
+
order: 'asc',
|
|
452
|
+
sorter: (a, b) => {
|
|
453
|
+
return a.name.localeCompare(b.name);
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
prop: 'amount',
|
|
458
|
+
order: 'desc',
|
|
459
|
+
sorter: (a, b) => {
|
|
460
|
+
return a['amount'] - b['amount'];
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
];
|
|
464
|
+
expect(sortData(data, sorters)).toEqual([
|
|
465
|
+
{
|
|
466
|
+
key: '4',
|
|
467
|
+
date: '01/02/2022',
|
|
468
|
+
name: 'B',
|
|
469
|
+
amount: 20,
|
|
470
|
+
amount2: 125,
|
|
471
|
+
balance: '$200',
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
key: '1',
|
|
475
|
+
date: '01/03/2022',
|
|
476
|
+
name: 'C',
|
|
477
|
+
amount: 30,
|
|
478
|
+
amount2: 30,
|
|
479
|
+
balance: '$300',
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
key: '2',
|
|
483
|
+
date: '01/06/2022',
|
|
484
|
+
name: 'C',
|
|
485
|
+
amount: 20,
|
|
486
|
+
amount2: 20,
|
|
487
|
+
balance: '$400',
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
key: '3',
|
|
491
|
+
date: '01/05/2022',
|
|
492
|
+
name: 'C',
|
|
493
|
+
amount: 20,
|
|
494
|
+
amount2: 30,
|
|
495
|
+
balance: '$401',
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
key: '5',
|
|
499
|
+
date: '01/04/2022',
|
|
500
|
+
name: 'D',
|
|
501
|
+
amount: 300,
|
|
502
|
+
amount2: 130,
|
|
503
|
+
balance: '$402',
|
|
504
|
+
},
|
|
505
|
+
]);
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNonNullable } from '../../../types/type-guard';
|
|
1
2
|
/**
|
|
2
3
|
* Used to format a string using a custom formatter.
|
|
3
4
|
*/
|
|
@@ -10,9 +11,12 @@ export class CustomFormatterStrategy {
|
|
|
10
11
|
* string formatter class that you are passing to the constructor of the class. This custom string
|
|
11
12
|
* formatter class likely contains methods or properties related to formatting strings in a specific
|
|
12
13
|
* way according to your requirements.
|
|
14
|
+
* @param {boolean} resetCaretPosition - The caret position should update to the last or keep the current position after format
|
|
13
15
|
*/
|
|
14
|
-
constructor(formatter) {
|
|
16
|
+
constructor(formatter, resetCaretPosition = false) {
|
|
17
|
+
this.resetCaretPositionFlag = false;
|
|
15
18
|
this.formatter = formatter;
|
|
19
|
+
this.resetCaretPositionFlag = resetCaretPosition;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* The format function in TypeScript takes a string input and returns the formatted output using a
|
|
@@ -31,16 +35,24 @@ export class CustomFormatterStrategy {
|
|
|
31
35
|
*
|
|
32
36
|
* @param {string} input - The `input` parameter in the `calculateCaretPosition` function is a string
|
|
33
37
|
* that represents the text input where you want to calculate the caret position.
|
|
38
|
+
* @param {number} caretPosition - The current position of caret
|
|
34
39
|
* @returns {Nullable<number>} The `calculateCaretPosition` function is returning the length of the formatted input
|
|
35
40
|
* string.
|
|
36
41
|
*/
|
|
37
|
-
calculateCaretPosition(input) {
|
|
38
|
-
|
|
42
|
+
calculateCaretPosition(input, caretPosition) {
|
|
43
|
+
if (this.resetCaretPositionFlag === true) {
|
|
44
|
+
return this.format(input).length;
|
|
45
|
+
}
|
|
46
|
+
else if (isNonNullable(caretPosition)) {
|
|
47
|
+
const startValue = input.substring(0, caretPosition);
|
|
48
|
+
const maskedStartValue = this.format(startValue);
|
|
49
|
+
return caretPosition + (maskedStartValue.length - startValue.length);
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
/**
|
|
41
53
|
* Trigger the formatter at init
|
|
42
54
|
*
|
|
43
|
-
* @returns {boolean} true
|
|
55
|
+
* @returns {boolean} true or false
|
|
44
56
|
*/
|
|
45
57
|
shouldTriggerAtInit() {
|
|
46
58
|
return true;
|
package/dist/collection/helpers/formatter/test/string-formatter/custom-formatter-strategy.test.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { CustomFormatterStrategy } from '../../string-formatter/custom-formatter-strategy';
|
|
2
2
|
test('custom formatter strategy is working as expected', () => {
|
|
3
|
-
const customFormatterStrategy = new CustomFormatterStrategy((value) => value.toUpperCase());
|
|
3
|
+
const customFormatterStrategy = new CustomFormatterStrategy((value) => value.toUpperCase(), true);
|
|
4
4
|
expect(customFormatterStrategy.format('test')).toBe('TEST');
|
|
5
|
-
expect(customFormatterStrategy.calculateCaretPosition('test')).toBe(4);
|
|
5
|
+
expect(customFormatterStrategy.calculateCaretPosition('test', null)).toBe(4);
|
|
6
6
|
expect(customFormatterStrategy.shouldTriggerAtInit()).toBe(true);
|
|
7
7
|
});
|
|
8
|
+
test('custom formatter strategy method calculateCaretPosition is working as expected', () => {
|
|
9
|
+
const customFormatterStrategy = new CustomFormatterStrategy((value) => value.toUpperCase());
|
|
10
|
+
expect(customFormatterStrategy.calculateCaretPosition('test', null)).toBe(undefined);
|
|
11
|
+
expect(customFormatterStrategy.calculateCaretPosition('test', 3)).toBe(3);
|
|
12
|
+
});
|
|
@@ -4,7 +4,7 @@ test('should return the correct vega environment parameters', () => {
|
|
|
4
4
|
const vegaEnv = VegaEnvManager.getVegaEnv();
|
|
5
5
|
expect(vegaEnv).toEqual({
|
|
6
6
|
framework: 'vanilla-js',
|
|
7
|
-
version: '2.
|
|
7
|
+
version: '2.21.0',
|
|
8
8
|
});
|
|
9
9
|
});
|
|
10
10
|
test('should return the correct vega framework', () => {
|
|
@@ -9,9 +9,9 @@ export var FrameworkEnum;
|
|
|
9
9
|
/** The VegaEnvManager class manages vega environment parameters. */
|
|
10
10
|
class VegaEnvManager {
|
|
11
11
|
constructor() {
|
|
12
|
-
// The `2.
|
|
12
|
+
// The `2.21.0` will be replaced to a version string when running publish script.
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
14
|
-
this.vegaVersion = '2.
|
|
14
|
+
this.vegaVersion = '2.21.0';
|
|
15
15
|
this.framework = FrameworkEnum.VanillaJs;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -235,6 +235,7 @@ export const getScreenshotDiffResults = async (page, desc, selector) => {
|
|
|
235
235
|
* @param {boolean} config.wrapped - set it to true when use visual test to catch the fixed area
|
|
236
236
|
* @param {EventSemanticsConfig} config.eventSemanticsConfig - sets the event semantics configuration for the EventManager
|
|
237
237
|
* @param {string} config.date --sets the date want to mock
|
|
238
|
+
* @param {number} config.timeout --sets the content timeout
|
|
238
239
|
*/
|
|
239
240
|
export const initVegaE2EPage = async (content, config) => {
|
|
240
241
|
const page = await newE2EPage();
|
|
@@ -245,9 +246,12 @@ export const initVegaE2EPage = async (content, config) => {
|
|
|
245
246
|
const injectTestIcons = `<script type='module'>
|
|
246
247
|
window.VegaIconManager.register(${JSON.stringify(TestIcons)});
|
|
247
248
|
</script>`;
|
|
248
|
-
|
|
249
|
+
const contentHtml = (config === null || config === void 0 ? void 0 : config.wrapped)
|
|
249
250
|
? `${injectTestIcons}${script}<div style="padding: 10px" id="visual-container">${content}</div>`
|
|
250
|
-
: injectTestIcons + script + content
|
|
251
|
+
: injectTestIcons + script + content;
|
|
252
|
+
(config === null || config === void 0 ? void 0 : config.timeout)
|
|
253
|
+
? await page.setContent(contentHtml, { timeout: config.timeout })
|
|
254
|
+
: await page.setContent(contentHtml);
|
|
251
255
|
await page.addStyleTag({ path: './src/test-assets/test-font-base64.css' });
|
|
252
256
|
await disableAnimationForPage(page);
|
|
253
257
|
await page.waitForChanges();
|