@htlkg/components 0.0.4 → 0.0.11
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/package.json +10 -6
- package/src/data/Table.test.ts +76 -176
- package/src/data/Table.unit.test.ts +146 -337
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htlkg/components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -41,17 +41,21 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@hotelinking/ui": "^16.49.16",
|
|
45
44
|
"ajv": "^8.17.1",
|
|
46
45
|
"ajv-formats": "^3.0.1",
|
|
47
|
-
"
|
|
48
|
-
"@htlkg/core": "0.0.
|
|
49
|
-
|
|
46
|
+
"@htlkg/data": "0.0.11",
|
|
47
|
+
"@htlkg/core": "0.0.10"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@hotelinking/ui": "^16.0.0",
|
|
51
|
+
"vue": "^3.5.0"
|
|
50
52
|
},
|
|
51
53
|
"publishConfig": {
|
|
52
|
-
"access": "
|
|
54
|
+
"access": "public"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
57
|
+
"@hotelinking/ui": "^16.49.16",
|
|
58
|
+
"vue": "^3.5.22",
|
|
55
59
|
"@vitejs/plugin-vue": "^5.2.4",
|
|
56
60
|
"@vue/test-utils": "^2.4.6",
|
|
57
61
|
"typescript": "^5.9.2",
|
package/src/data/Table.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, vi
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { mount } from '@vue/test-utils';
|
|
3
3
|
import { nextTick } from 'vue';
|
|
4
4
|
import Table from './Table.vue';
|
|
@@ -8,55 +8,48 @@ import Table from './Table.vue';
|
|
|
8
8
|
* Tests user interactions, real-world scenarios, and component integration
|
|
9
9
|
*/
|
|
10
10
|
describe('Table integration tests', () => {
|
|
11
|
-
const
|
|
12
|
-
{ name: '
|
|
13
|
-
{ name: '
|
|
14
|
-
{ name: '
|
|
15
|
-
{ name: '
|
|
11
|
+
const mockHeader = [
|
|
12
|
+
{ name: 'id', label: 'ID', sortable: true },
|
|
13
|
+
{ name: 'name', label: 'Name', sortable: true },
|
|
14
|
+
{ name: 'email', label: 'Email', sortable: true },
|
|
15
|
+
{ name: 'status', label: 'Status', sortable: true }
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
const mockItems = [
|
|
19
|
-
{ id: 1,
|
|
20
|
-
{ id: 2,
|
|
21
|
-
{ id: 3,
|
|
22
|
-
{ id: 4,
|
|
23
|
-
{ id: 5,
|
|
19
|
+
{ id: 1, row: [1, 'John Doe', 'john@example.com', 'active'] },
|
|
20
|
+
{ id: 2, row: [2, 'Jane Smith', 'jane@example.com', 'inactive'] },
|
|
21
|
+
{ id: 3, row: [3, 'Bob Johnson', 'bob@example.com', 'active'] },
|
|
22
|
+
{ id: 4, row: [4, 'Alice Williams', 'alice@example.com', 'pending'] },
|
|
23
|
+
{ id: 5, row: [5, 'Charlie Brown', 'charlie@example.com', 'active'] }
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
const globalStubs = {
|
|
27
|
-
uiTable: true
|
|
28
|
-
uiPagination: true,
|
|
29
|
-
uiDropdown: true,
|
|
30
|
-
uiSmartFilterMultipleV2: true,
|
|
31
|
-
uiNoResults: true
|
|
27
|
+
uiTable: true
|
|
32
28
|
};
|
|
33
29
|
|
|
34
30
|
describe('User List Management', () => {
|
|
35
|
-
it('should
|
|
31
|
+
it('should accept items and header props', async () => {
|
|
36
32
|
const wrapper = mount(Table, {
|
|
37
33
|
props: {
|
|
38
34
|
items: mockItems,
|
|
39
|
-
|
|
35
|
+
header: mockHeader,
|
|
40
36
|
currentPage: 1,
|
|
41
37
|
totalPages: 2,
|
|
42
38
|
totalItems: 5,
|
|
43
|
-
|
|
44
|
-
showPagination: true
|
|
39
|
+
pageSize: 10
|
|
45
40
|
},
|
|
46
41
|
global: { stubs: globalStubs }
|
|
47
42
|
});
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
expect(
|
|
51
|
-
expect(vm.showTable).toBe(true);
|
|
52
|
-
expect(vm.showPagination).toBe(true);
|
|
44
|
+
expect(wrapper.props('items')).toHaveLength(5);
|
|
45
|
+
expect(wrapper.props('header')).toHaveLength(4);
|
|
53
46
|
});
|
|
54
47
|
|
|
55
|
-
it('should handle sorting
|
|
48
|
+
it('should handle sorting events', async () => {
|
|
56
49
|
const wrapper = mount(Table, {
|
|
57
50
|
props: {
|
|
58
51
|
items: mockItems,
|
|
59
|
-
|
|
52
|
+
header: mockHeader,
|
|
60
53
|
orderedBy: '',
|
|
61
54
|
orderDirection: 'asc'
|
|
62
55
|
},
|
|
@@ -69,14 +62,14 @@ describe('Table integration tests', () => {
|
|
|
69
62
|
|
|
70
63
|
expect(wrapper.emitted('update:orderedBy')?.[0]).toEqual(['name']);
|
|
71
64
|
expect(wrapper.emitted('update:orderDirection')?.[0]).toEqual(['desc']);
|
|
72
|
-
expect(wrapper.emitted('order-
|
|
65
|
+
expect(wrapper.emitted('order-by')?.[0]).toEqual([{ value: 'name', orderDirection: 'desc' }]);
|
|
73
66
|
});
|
|
74
67
|
|
|
75
68
|
it('should handle page navigation', async () => {
|
|
76
69
|
const wrapper = mount(Table, {
|
|
77
70
|
props: {
|
|
78
71
|
items: mockItems,
|
|
79
|
-
|
|
72
|
+
header: mockHeader,
|
|
80
73
|
currentPage: 1,
|
|
81
74
|
totalPages: 3
|
|
82
75
|
},
|
|
@@ -84,13 +77,13 @@ describe('Table integration tests', () => {
|
|
|
84
77
|
});
|
|
85
78
|
|
|
86
79
|
const vm = wrapper.vm as any;
|
|
87
|
-
|
|
80
|
+
|
|
88
81
|
// Navigate to page 2
|
|
89
82
|
vm.handleChangePage(2);
|
|
90
83
|
await nextTick();
|
|
91
84
|
|
|
92
85
|
expect(wrapper.emitted('update:currentPage')?.[0]).toEqual([2]);
|
|
93
|
-
expect(wrapper.emitted('page
|
|
86
|
+
expect(wrapper.emitted('change-page')?.[0]).toEqual([2]);
|
|
94
87
|
|
|
95
88
|
// Navigate to page 3
|
|
96
89
|
vm.handleChangePage(3);
|
|
@@ -103,20 +96,20 @@ describe('Table integration tests', () => {
|
|
|
103
96
|
const wrapper = mount(Table, {
|
|
104
97
|
props: {
|
|
105
98
|
items: mockItems,
|
|
106
|
-
|
|
99
|
+
header: mockHeader,
|
|
107
100
|
currentPage: 3,
|
|
108
|
-
|
|
101
|
+
pageSize: 10
|
|
109
102
|
},
|
|
110
103
|
global: { stubs: globalStubs }
|
|
111
104
|
});
|
|
112
105
|
|
|
113
106
|
const vm = wrapper.vm as any;
|
|
114
|
-
vm.handleChangePageSize(
|
|
107
|
+
vm.handleChangePageSize(25);
|
|
115
108
|
await nextTick();
|
|
116
109
|
|
|
117
|
-
expect(wrapper.emitted('update:
|
|
110
|
+
expect(wrapper.emitted('update:pageSize')?.[0]).toEqual([25]);
|
|
118
111
|
expect(wrapper.emitted('update:currentPage')?.[0]).toEqual([1]);
|
|
119
|
-
expect(wrapper.emitted('
|
|
112
|
+
expect(wrapper.emitted('change-page-size')?.[0]).toEqual([25]);
|
|
120
113
|
});
|
|
121
114
|
});
|
|
122
115
|
|
|
@@ -125,7 +118,7 @@ describe('Table integration tests', () => {
|
|
|
125
118
|
const wrapper = mount(Table, {
|
|
126
119
|
props: {
|
|
127
120
|
items: mockItems,
|
|
128
|
-
|
|
121
|
+
header: mockHeader
|
|
129
122
|
},
|
|
130
123
|
global: { stubs: globalStubs }
|
|
131
124
|
});
|
|
@@ -137,22 +130,19 @@ describe('Table integration tests', () => {
|
|
|
137
130
|
expect(vm.selectedItemIds.size).toBe(5);
|
|
138
131
|
expect(wrapper.emitted('select-all-items')).toBeDefined();
|
|
139
132
|
expect(wrapper.emitted('update:selected')).toBeDefined();
|
|
140
|
-
|
|
141
|
-
const selectedItems = wrapper.emitted('update:selected')?.[0]?.[0] as any[];
|
|
142
|
-
expect(selectedItems).toHaveLength(5);
|
|
143
133
|
});
|
|
144
134
|
|
|
145
135
|
it('should deselect all items', async () => {
|
|
146
136
|
const wrapper = mount(Table, {
|
|
147
137
|
props: {
|
|
148
138
|
items: mockItems,
|
|
149
|
-
|
|
139
|
+
header: mockHeader
|
|
150
140
|
},
|
|
151
141
|
global: { stubs: globalStubs }
|
|
152
142
|
});
|
|
153
143
|
|
|
154
144
|
const vm = wrapper.vm as any;
|
|
155
|
-
|
|
145
|
+
|
|
156
146
|
// First select all
|
|
157
147
|
vm.handleSelectAllItems();
|
|
158
148
|
await nextTick();
|
|
@@ -163,16 +153,13 @@ describe('Table integration tests', () => {
|
|
|
163
153
|
|
|
164
154
|
expect(vm.selectedItemIds.size).toBe(0);
|
|
165
155
|
expect(wrapper.emitted('deselect-all-items')).toBeDefined();
|
|
166
|
-
|
|
167
|
-
const selectedItems = wrapper.emitted('update:selected')?.slice(-1)[0]?.[0] as any[];
|
|
168
|
-
expect(selectedItems).toHaveLength(0);
|
|
169
156
|
});
|
|
170
157
|
|
|
171
158
|
it('should handle table action with selected items', async () => {
|
|
172
159
|
const wrapper = mount(Table, {
|
|
173
160
|
props: {
|
|
174
161
|
items: mockItems,
|
|
175
|
-
|
|
162
|
+
header: mockHeader,
|
|
176
163
|
actions: [
|
|
177
164
|
{ name: 'Delete', id: 'delete' },
|
|
178
165
|
{ name: 'Export', id: 'export' }
|
|
@@ -195,88 +182,57 @@ describe('Table integration tests', () => {
|
|
|
195
182
|
const wrapper = mount(Table, {
|
|
196
183
|
props: {
|
|
197
184
|
items: mockItems,
|
|
198
|
-
|
|
185
|
+
header: mockHeader
|
|
199
186
|
},
|
|
200
187
|
global: { stubs: globalStubs }
|
|
201
188
|
});
|
|
202
189
|
|
|
203
190
|
const vm = wrapper.vm as any;
|
|
204
|
-
|
|
191
|
+
|
|
205
192
|
// Select some items
|
|
206
193
|
vm.selectedItemIds = new Set([1, 2, 3]);
|
|
207
|
-
|
|
194
|
+
|
|
208
195
|
// Clear selection
|
|
209
196
|
vm.clearSelection();
|
|
210
197
|
await nextTick();
|
|
211
198
|
|
|
212
199
|
expect(vm.selectedItemIds.size).toBe(0);
|
|
213
|
-
expect(
|
|
200
|
+
expect(wrapper.emitted('update:resetSelected')?.[0]).toEqual([true]);
|
|
214
201
|
});
|
|
215
202
|
});
|
|
216
203
|
|
|
217
204
|
describe('Filtering and Search', () => {
|
|
218
205
|
it('should handle smart filter application', async () => {
|
|
219
|
-
const availableCategories = [
|
|
220
|
-
{
|
|
221
|
-
name: 'name',
|
|
222
|
-
label: 'Name',
|
|
223
|
-
componentType: 'uiInput' as const,
|
|
224
|
-
defaultProps: {}
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
name: 'status',
|
|
228
|
-
label: 'Status',
|
|
229
|
-
componentType: 'uiSelect' as const,
|
|
230
|
-
defaultProps: {}
|
|
231
|
-
}
|
|
232
|
-
];
|
|
233
|
-
|
|
234
206
|
const wrapper = mount(Table, {
|
|
235
207
|
props: {
|
|
236
208
|
items: mockItems,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
209
|
+
header: mockHeader,
|
|
210
|
+
smartFilterCategories: [
|
|
211
|
+
{
|
|
212
|
+
id: 'name',
|
|
213
|
+
name: 'Name',
|
|
214
|
+
componentType: 'uiInput' as const,
|
|
215
|
+
defaultProps: {}
|
|
216
|
+
}
|
|
217
|
+
]
|
|
240
218
|
},
|
|
241
219
|
global: { stubs: globalStubs }
|
|
242
220
|
});
|
|
243
221
|
|
|
244
222
|
const vm = wrapper.vm as any;
|
|
245
223
|
const filters = { name: 'John', status: 'active' };
|
|
246
|
-
|
|
224
|
+
|
|
247
225
|
vm.handleSmartFiltersSent(filters);
|
|
248
226
|
await nextTick();
|
|
249
227
|
|
|
250
|
-
expect(vm.hasUserSearched).toBe(true);
|
|
251
228
|
expect(wrapper.emitted('smart-filters-sent')?.[0]).toEqual([filters]);
|
|
252
|
-
expect(wrapper.emitted('multiple-filters-applied')?.[0]).toEqual([filters]);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('should show search no results after filtering', async () => {
|
|
256
|
-
const wrapper = mount(Table, {
|
|
257
|
-
props: {
|
|
258
|
-
items: [],
|
|
259
|
-
columns: mockColumns,
|
|
260
|
-
loading: false
|
|
261
|
-
},
|
|
262
|
-
global: { stubs: globalStubs }
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const vm = wrapper.vm as any;
|
|
266
|
-
|
|
267
|
-
// Simulate user search
|
|
268
|
-
vm.handleSmartFiltersSent({ name: 'NonExistent' });
|
|
269
|
-
await nextTick();
|
|
270
|
-
|
|
271
|
-
expect(vm.showSearchNoResults).toBe(true);
|
|
272
|
-
expect(vm.showInitialNoResults).toBe(false);
|
|
273
229
|
});
|
|
274
230
|
|
|
275
231
|
it('should clear filters', async () => {
|
|
276
232
|
const wrapper = mount(Table, {
|
|
277
233
|
props: {
|
|
278
234
|
items: mockItems,
|
|
279
|
-
|
|
235
|
+
header: mockHeader
|
|
280
236
|
},
|
|
281
237
|
global: { stubs: globalStubs }
|
|
282
238
|
});
|
|
@@ -292,7 +248,7 @@ describe('Table integration tests', () => {
|
|
|
292
248
|
const wrapper = mount(Table, {
|
|
293
249
|
props: {
|
|
294
250
|
items: mockItems,
|
|
295
|
-
|
|
251
|
+
header: mockHeader
|
|
296
252
|
},
|
|
297
253
|
global: { stubs: globalStubs }
|
|
298
254
|
});
|
|
@@ -310,91 +266,60 @@ describe('Table integration tests', () => {
|
|
|
310
266
|
const wrapper = mount(Table, {
|
|
311
267
|
props: {
|
|
312
268
|
items: mockItems,
|
|
313
|
-
|
|
269
|
+
header: mockHeader
|
|
314
270
|
},
|
|
315
271
|
global: { stubs: globalStubs }
|
|
316
272
|
});
|
|
317
273
|
|
|
318
274
|
const vm = wrapper.vm as any;
|
|
319
|
-
|
|
275
|
+
|
|
320
276
|
// Hide column 1
|
|
321
277
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: true });
|
|
322
278
|
await nextTick();
|
|
323
279
|
|
|
324
|
-
expect(vm.
|
|
280
|
+
expect(vm.internalHiddenColumns).toContain(1);
|
|
325
281
|
expect(vm.getHiddenColumns()).toContain(1);
|
|
326
282
|
|
|
327
283
|
// Show column 1 again
|
|
328
284
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: false });
|
|
329
285
|
await nextTick();
|
|
330
286
|
|
|
331
|
-
expect(vm.
|
|
287
|
+
expect(vm.internalHiddenColumns).not.toContain(1);
|
|
332
288
|
});
|
|
333
289
|
|
|
334
290
|
it('should handle multiple hidden columns', async () => {
|
|
335
291
|
const wrapper = mount(Table, {
|
|
336
292
|
props: {
|
|
337
293
|
items: mockItems,
|
|
338
|
-
|
|
294
|
+
header: mockHeader
|
|
339
295
|
},
|
|
340
296
|
global: { stubs: globalStubs }
|
|
341
297
|
});
|
|
342
298
|
|
|
343
299
|
const vm = wrapper.vm as any;
|
|
344
|
-
|
|
300
|
+
|
|
345
301
|
// Hide multiple columns
|
|
346
302
|
vm.handleColumnsVisibilityChanged({ index: 0, hidden: true });
|
|
347
303
|
vm.handleColumnsVisibilityChanged({ index: 2, hidden: true });
|
|
348
304
|
await nextTick();
|
|
349
305
|
|
|
350
|
-
expect(vm.
|
|
351
|
-
expect(vm.
|
|
352
|
-
expect(vm.
|
|
306
|
+
expect(vm.internalHiddenColumns).toHaveLength(2);
|
|
307
|
+
expect(vm.internalHiddenColumns).toContain(0);
|
|
308
|
+
expect(vm.internalHiddenColumns).toContain(2);
|
|
353
309
|
});
|
|
354
310
|
});
|
|
355
311
|
|
|
356
312
|
describe('Empty States', () => {
|
|
357
|
-
it('should show initial no results when no data', async () => {
|
|
358
|
-
const wrapper = mount(Table, {
|
|
359
|
-
props: {
|
|
360
|
-
items: [],
|
|
361
|
-
columns: mockColumns,
|
|
362
|
-
loading: false
|
|
363
|
-
},
|
|
364
|
-
global: { stubs: globalStubs }
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const vm = wrapper.vm as any;
|
|
368
|
-
expect(vm.showInitialNoResults).toBe(true);
|
|
369
|
-
expect(vm.showTable).toBe(false);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it('should show loading state', async () => {
|
|
373
|
-
const wrapper = mount(Table, {
|
|
374
|
-
props: {
|
|
375
|
-
items: [],
|
|
376
|
-
columns: mockColumns,
|
|
377
|
-
loading: true
|
|
378
|
-
},
|
|
379
|
-
global: { stubs: globalStubs }
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
const vm = wrapper.vm as any;
|
|
383
|
-
expect(vm.showTable).toBe(true);
|
|
384
|
-
expect(vm.showInitialNoResults).toBe(false);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
313
|
it('should handle no results action', async () => {
|
|
388
314
|
const wrapper = mount(Table, {
|
|
389
315
|
props: {
|
|
390
316
|
items: [],
|
|
391
|
-
|
|
317
|
+
header: mockHeader,
|
|
392
318
|
loading: false,
|
|
393
319
|
noResults: {
|
|
394
320
|
title: 'No users found',
|
|
395
321
|
message: 'Create your first user',
|
|
396
|
-
actions: [{ action: 'create', text: 'Create User' }]
|
|
397
|
-
select: { name: '', value: '' }
|
|
322
|
+
actions: [{ action: 'create', text: 'Create User' }]
|
|
398
323
|
}
|
|
399
324
|
},
|
|
400
325
|
global: { stubs: globalStubs }
|
|
@@ -408,29 +333,12 @@ describe('Table integration tests', () => {
|
|
|
408
333
|
});
|
|
409
334
|
});
|
|
410
335
|
|
|
411
|
-
describe('
|
|
412
|
-
it('should handle refresh action', async () => {
|
|
413
|
-
const wrapper = mount(Table, {
|
|
414
|
-
props: {
|
|
415
|
-
items: mockItems,
|
|
416
|
-
columns: mockColumns,
|
|
417
|
-
showRefresh: true
|
|
418
|
-
},
|
|
419
|
-
global: { stubs: globalStubs }
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
const vm = wrapper.vm as any;
|
|
423
|
-
vm.handleDropdownAction({ value: 'refreshData' });
|
|
424
|
-
await nextTick();
|
|
425
|
-
|
|
426
|
-
expect(wrapper.emitted('refresh:data')).toBeDefined();
|
|
427
|
-
});
|
|
428
|
-
|
|
336
|
+
describe('Actions', () => {
|
|
429
337
|
it('should handle table action button click', async () => {
|
|
430
338
|
const wrapper = mount(Table, {
|
|
431
339
|
props: {
|
|
432
340
|
items: mockItems,
|
|
433
|
-
|
|
341
|
+
header: mockHeader,
|
|
434
342
|
tableActionButtons: [
|
|
435
343
|
{ id: 'export', text: 'Export' },
|
|
436
344
|
{ id: 'import', text: 'Import' }
|
|
@@ -452,7 +360,7 @@ describe('Table integration tests', () => {
|
|
|
452
360
|
const wrapper = mount(Table, {
|
|
453
361
|
props: {
|
|
454
362
|
items: mockItems,
|
|
455
|
-
|
|
363
|
+
header: mockHeader
|
|
456
364
|
},
|
|
457
365
|
global: { stubs: globalStubs }
|
|
458
366
|
});
|
|
@@ -468,42 +376,37 @@ describe('Table integration tests', () => {
|
|
|
468
376
|
});
|
|
469
377
|
|
|
470
378
|
describe('State Management', () => {
|
|
471
|
-
it('should
|
|
379
|
+
it('should initialize with provided hiddenColumns prop', async () => {
|
|
472
380
|
const wrapper = mount(Table, {
|
|
473
381
|
props: {
|
|
474
382
|
items: mockItems,
|
|
475
|
-
|
|
383
|
+
header: mockHeader,
|
|
384
|
+
hiddenColumns: [1, 2]
|
|
476
385
|
},
|
|
477
386
|
global: { stubs: globalStubs }
|
|
478
387
|
});
|
|
479
388
|
|
|
480
389
|
const vm = wrapper.vm as any;
|
|
481
|
-
vm.
|
|
482
|
-
|
|
483
|
-
// Change items
|
|
484
|
-
await wrapper.setProps({ items: mockItems.slice(0, 3) });
|
|
485
|
-
await nextTick();
|
|
486
|
-
|
|
487
|
-
expect(vm.resetSelected).toBe(false);
|
|
390
|
+
expect(vm.internalHiddenColumns).toEqual([1, 2]);
|
|
488
391
|
});
|
|
489
392
|
|
|
490
393
|
it('should maintain hidden columns across updates', async () => {
|
|
491
394
|
const wrapper = mount(Table, {
|
|
492
395
|
props: {
|
|
493
396
|
items: mockItems,
|
|
494
|
-
|
|
397
|
+
header: mockHeader
|
|
495
398
|
},
|
|
496
399
|
global: { stubs: globalStubs }
|
|
497
400
|
});
|
|
498
401
|
|
|
499
402
|
const vm = wrapper.vm as any;
|
|
500
403
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: true });
|
|
501
|
-
|
|
404
|
+
|
|
502
405
|
// Update items
|
|
503
406
|
await wrapper.setProps({ items: mockItems.slice(0, 2) });
|
|
504
407
|
await nextTick();
|
|
505
408
|
|
|
506
|
-
expect(vm.
|
|
409
|
+
expect(vm.internalHiddenColumns).toContain(1);
|
|
507
410
|
});
|
|
508
411
|
});
|
|
509
412
|
|
|
@@ -512,16 +415,14 @@ describe('Table integration tests', () => {
|
|
|
512
415
|
const wrapper = mount(Table, {
|
|
513
416
|
props: {
|
|
514
417
|
items: mockItems,
|
|
515
|
-
|
|
418
|
+
header: mockHeader,
|
|
516
419
|
currentPage: 1,
|
|
517
420
|
totalPages: 2,
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
showFilters: true,
|
|
521
|
-
availableCategories: [
|
|
421
|
+
pageSize: 10,
|
|
422
|
+
smartFilterCategories: [
|
|
522
423
|
{
|
|
523
|
-
|
|
524
|
-
|
|
424
|
+
id: 'status',
|
|
425
|
+
name: 'Status',
|
|
525
426
|
componentType: 'uiSelect' as const,
|
|
526
427
|
defaultProps: {}
|
|
527
428
|
}
|
|
@@ -540,7 +441,7 @@ describe('Table integration tests', () => {
|
|
|
540
441
|
// 2. Sort by name
|
|
541
442
|
vm.handleOrderBy({ value: 'name', orderDirection: 'asc' });
|
|
542
443
|
await nextTick();
|
|
543
|
-
expect(wrapper.emitted('order-
|
|
444
|
+
expect(wrapper.emitted('order-by')).toBeDefined();
|
|
544
445
|
|
|
545
446
|
// 3. Select items
|
|
546
447
|
vm.handleSelectAllItems();
|
|
@@ -555,8 +456,7 @@ describe('Table integration tests', () => {
|
|
|
555
456
|
// 5. Change page
|
|
556
457
|
vm.handleChangePage(2);
|
|
557
458
|
await nextTick();
|
|
558
|
-
expect(wrapper.emitted('page
|
|
559
|
-
expect(vm.resetSelected).toBe(true);
|
|
459
|
+
expect(wrapper.emitted('change-page')).toBeDefined();
|
|
560
460
|
});
|
|
561
461
|
});
|
|
562
462
|
});
|
|
@@ -1,544 +1,353 @@
|
|
|
1
|
-
import { describe, it, expect,
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { mount } from '@vue/test-utils';
|
|
3
|
+
import { nextTick } from 'vue';
|
|
3
4
|
import Table from './Table.vue';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Unit tests for Table component
|
|
7
|
-
* Tests
|
|
8
|
+
* Tests the Table.vue wrapper component around uiTable
|
|
8
9
|
*/
|
|
9
10
|
describe('Table unit tests', () => {
|
|
10
|
-
const
|
|
11
|
-
{ name: '
|
|
12
|
-
{ name: '
|
|
13
|
-
{ name: '
|
|
11
|
+
const mockHeader = [
|
|
12
|
+
{ name: 'id', label: 'ID', sortable: true },
|
|
13
|
+
{ name: 'name', label: 'Name', sortable: true },
|
|
14
|
+
{ name: 'email', label: 'Email', sortable: true }
|
|
14
15
|
];
|
|
15
16
|
|
|
16
17
|
const mockItems = [
|
|
17
|
-
{ id: 1,
|
|
18
|
-
{ id: 2,
|
|
19
|
-
{ id: 3,
|
|
18
|
+
{ id: 1, row: [1, 'John Doe', 'john@example.com'] },
|
|
19
|
+
{ id: 2, row: [2, 'Jane Smith', 'jane@example.com'] },
|
|
20
|
+
{ id: 3, row: [3, 'Bob Johnson', 'bob@example.com'] }
|
|
20
21
|
];
|
|
21
22
|
|
|
22
23
|
const globalStubs = {
|
|
23
|
-
uiTable: true
|
|
24
|
-
uiPagination: true,
|
|
25
|
-
uiDropdown: true,
|
|
26
|
-
uiSmartFilterMultipleV2: true,
|
|
27
|
-
uiNoResults: true
|
|
24
|
+
uiTable: true
|
|
28
25
|
};
|
|
29
26
|
|
|
30
|
-
describe('
|
|
31
|
-
it('should
|
|
27
|
+
describe('pageSizeOptions computed', () => {
|
|
28
|
+
it('should return page size options with correct active state', () => {
|
|
32
29
|
const wrapper = mount(Table, {
|
|
33
|
-
props: { items: mockItems,
|
|
30
|
+
props: { items: mockItems, header: mockHeader, pageSize: 25 },
|
|
34
31
|
global: { stubs: globalStubs }
|
|
35
32
|
});
|
|
36
33
|
|
|
37
34
|
const vm = wrapper.vm as any;
|
|
38
|
-
expect(vm.
|
|
39
|
-
expect(vm.
|
|
40
|
-
expect(vm.
|
|
35
|
+
expect(vm.pageSizeOptions).toHaveLength(4);
|
|
36
|
+
expect(vm.pageSizeOptions[0].name).toBe('10');
|
|
37
|
+
expect(vm.pageSizeOptions[1].active).toBe(true); // 25 is active
|
|
41
38
|
});
|
|
42
39
|
|
|
43
|
-
it('should
|
|
44
|
-
const columnsWithTooltips = [
|
|
45
|
-
{ name: 'ID', value: 'id', tooltip: 'Unique identifier' },
|
|
46
|
-
{ name: 'Name', value: 'name', tooltip: 'User full name' }
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
const wrapper = mount(Table, {
|
|
50
|
-
props: { items: mockItems, columns: columnsWithTooltips },
|
|
51
|
-
global: { stubs: globalStubs }
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const vm = wrapper.vm as any;
|
|
55
|
-
expect(vm.tableHeader[0].tooltip).toBe('Unique identifier');
|
|
56
|
-
expect(vm.tableHeader[1].tooltip).toBe('User full name');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('tableItems computed', () => {
|
|
61
|
-
it('should convert items to uiTable format', () => {
|
|
62
|
-
const wrapper = mount(Table, {
|
|
63
|
-
props: { items: mockItems, columns: mockColumns },
|
|
64
|
-
global: { stubs: globalStubs }
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const vm = wrapper.vm as any;
|
|
68
|
-
expect(vm.tableItems).toHaveLength(3);
|
|
69
|
-
expect(vm.tableItems[0].id).toBe(1);
|
|
70
|
-
expect(vm.tableItems[0].row).toHaveLength(3);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should handle items without id by using index', () => {
|
|
74
|
-
const itemsWithoutId = [
|
|
75
|
-
{ name: 'John', email: 'john@test.com' },
|
|
76
|
-
{ name: 'Jane', email: 'jane@test.com' }
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
const wrapper = mount(Table, {
|
|
80
|
-
props: { items: itemsWithoutId, columns: mockColumns },
|
|
81
|
-
global: { stubs: globalStubs }
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const vm = wrapper.vm as any;
|
|
85
|
-
expect(vm.tableItems[0].id).toBe(0);
|
|
86
|
-
expect(vm.tableItems[1].id).toBe(1);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should handle disabled items', () => {
|
|
90
|
-
const itemsWithDisabled = [
|
|
91
|
-
{ id: 1, name: 'John', email: 'john@test.com', disabled: true },
|
|
92
|
-
{ id: 2, name: 'Jane', email: 'jane@test.com', disabled: false }
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
const wrapper = mount(Table, {
|
|
96
|
-
props: { items: itemsWithDisabled, columns: mockColumns },
|
|
97
|
-
global: { stubs: globalStubs }
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const vm = wrapper.vm as any;
|
|
101
|
-
expect(vm.tableItems[0].disabled).toBe(true);
|
|
102
|
-
expect(vm.tableItems[1].disabled).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should handle null and undefined values', () => {
|
|
106
|
-
const itemsWithNulls = [
|
|
107
|
-
{ id: 1, name: null, email: undefined }
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
const wrapper = mount(Table, {
|
|
111
|
-
props: { items: itemsWithNulls, columns: mockColumns },
|
|
112
|
-
global: { stubs: globalStubs }
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const vm = wrapper.vm as any;
|
|
116
|
-
expect(vm.tableItems[0].row[1]).toBe('');
|
|
117
|
-
expect(vm.tableItems[0].row[2]).toBe('');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('pageItemsOptions computed', () => {
|
|
122
|
-
it('should return page size options', () => {
|
|
123
|
-
const wrapper = mount(Table, {
|
|
124
|
-
props: { items: mockItems, columns: mockColumns, itemsPerPage: 25 },
|
|
125
|
-
global: { stubs: globalStubs }
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const vm = wrapper.vm as any;
|
|
129
|
-
expect(vm.pageItemsOptions).toHaveLength(4);
|
|
130
|
-
expect(vm.pageItemsOptions[0].name).toBe('10');
|
|
131
|
-
expect(vm.pageItemsOptions[1].active).toBe(true); // 25 is active
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should mark correct option as active', () => {
|
|
40
|
+
it('should mark correct option as active for page size 50', () => {
|
|
135
41
|
const wrapper = mount(Table, {
|
|
136
|
-
props: { items: mockItems,
|
|
42
|
+
props: { items: mockItems, header: mockHeader, pageSize: 50 },
|
|
137
43
|
global: { stubs: globalStubs }
|
|
138
44
|
});
|
|
139
45
|
|
|
140
46
|
const vm = wrapper.vm as any;
|
|
141
|
-
const activeOption = vm.
|
|
47
|
+
const activeOption = vm.pageSizeOptions.find((opt: any) => opt.active);
|
|
142
48
|
expect(activeOption.value).toBe('50');
|
|
143
49
|
});
|
|
144
50
|
});
|
|
145
51
|
|
|
146
|
-
describe('showInitialNoResults computed', () => {
|
|
147
|
-
it('should return true when no items and not loading', () => {
|
|
148
|
-
const wrapper = mount(Table, {
|
|
149
|
-
props: { items: [], columns: mockColumns, loading: false },
|
|
150
|
-
global: { stubs: globalStubs }
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const vm = wrapper.vm as any;
|
|
154
|
-
expect(vm.showInitialNoResults).toBe(true);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should return false when loading', () => {
|
|
158
|
-
const wrapper = mount(Table, {
|
|
159
|
-
props: { items: [], columns: mockColumns, loading: true },
|
|
160
|
-
global: { stubs: globalStubs }
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const vm = wrapper.vm as any;
|
|
164
|
-
expect(vm.showInitialNoResults).toBe(false);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should return false when items exist', () => {
|
|
168
|
-
const wrapper = mount(Table, {
|
|
169
|
-
props: { items: mockItems, columns: mockColumns, loading: false },
|
|
170
|
-
global: { stubs: globalStubs }
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const vm = wrapper.vm as any;
|
|
174
|
-
expect(vm.showInitialNoResults).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('should return false when user has searched', () => {
|
|
178
|
-
const wrapper = mount(Table, {
|
|
179
|
-
props: { items: [], columns: mockColumns, loading: false },
|
|
180
|
-
global: { stubs: globalStubs }
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const vm = wrapper.vm as any;
|
|
184
|
-
vm.hasUserSearched = true;
|
|
185
|
-
expect(vm.showInitialNoResults).toBe(false);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe('showSearchNoResults computed', () => {
|
|
190
|
-
it('should return true when no items after search', () => {
|
|
191
|
-
const wrapper = mount(Table, {
|
|
192
|
-
props: { items: [], columns: mockColumns, loading: false },
|
|
193
|
-
global: { stubs: globalStubs }
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const vm = wrapper.vm as any;
|
|
197
|
-
vm.hasUserSearched = true;
|
|
198
|
-
expect(vm.showSearchNoResults).toBe(true);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should return false when not searched', () => {
|
|
202
|
-
const wrapper = mount(Table, {
|
|
203
|
-
props: { items: [], columns: mockColumns, loading: false },
|
|
204
|
-
global: { stubs: globalStubs }
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const vm = wrapper.vm as any;
|
|
208
|
-
expect(vm.showSearchNoResults).toBe(false);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('showTable computed', () => {
|
|
213
|
-
it('should return true when loading', () => {
|
|
214
|
-
const wrapper = mount(Table, {
|
|
215
|
-
props: { items: [], columns: mockColumns, loading: true },
|
|
216
|
-
global: { stubs: globalStubs }
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const vm = wrapper.vm as any;
|
|
220
|
-
expect(vm.showTable).toBe(true);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should return true when items exist', () => {
|
|
224
|
-
const wrapper = mount(Table, {
|
|
225
|
-
props: { items: mockItems, columns: mockColumns, loading: false },
|
|
226
|
-
global: { stubs: globalStubs }
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const vm = wrapper.vm as any;
|
|
230
|
-
expect(vm.showTable).toBe(true);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should return false when no items and not loading', () => {
|
|
234
|
-
const wrapper = mount(Table, {
|
|
235
|
-
props: { items: [], columns: mockColumns, loading: false },
|
|
236
|
-
global: { stubs: globalStubs }
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const vm = wrapper.vm as any;
|
|
240
|
-
expect(vm.showTable).toBe(false);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
52
|
describe('handleOrderBy()', () => {
|
|
245
|
-
it('should emit order events', () => {
|
|
53
|
+
it('should emit order events', async () => {
|
|
246
54
|
const wrapper = mount(Table, {
|
|
247
|
-
props: { items: mockItems,
|
|
55
|
+
props: { items: mockItems, header: mockHeader },
|
|
248
56
|
global: { stubs: globalStubs }
|
|
249
57
|
});
|
|
250
58
|
|
|
251
59
|
const vm = wrapper.vm as any;
|
|
252
60
|
vm.handleOrderBy({ value: 'name', orderDirection: 'desc' });
|
|
61
|
+
await nextTick();
|
|
253
62
|
|
|
254
63
|
expect(wrapper.emitted('update:orderedBy')).toBeDefined();
|
|
255
64
|
expect(wrapper.emitted('update:orderedBy')?.[0]).toEqual(['name']);
|
|
256
65
|
expect(wrapper.emitted('update:orderDirection')).toBeDefined();
|
|
257
66
|
expect(wrapper.emitted('update:orderDirection')?.[0]).toEqual(['desc']);
|
|
258
|
-
expect(wrapper.emitted('order-
|
|
259
|
-
expect(wrapper.emitted('order-
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('should reset selected items', () => {
|
|
263
|
-
const wrapper = mount(Table, {
|
|
264
|
-
props: { items: mockItems, columns: mockColumns },
|
|
265
|
-
global: { stubs: globalStubs }
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const vm = wrapper.vm as any;
|
|
269
|
-
vm.resetSelected = false;
|
|
270
|
-
vm.handleOrderBy({ value: 'name', orderDirection: 'asc' });
|
|
271
|
-
|
|
272
|
-
expect(vm.resetSelected).toBe(true);
|
|
67
|
+
expect(wrapper.emitted('order-by')).toBeDefined();
|
|
68
|
+
expect(wrapper.emitted('order-by')?.[0]).toEqual([{ value: 'name', orderDirection: 'desc' }]);
|
|
273
69
|
});
|
|
274
70
|
});
|
|
275
71
|
|
|
276
72
|
describe('handleChangePage()', () => {
|
|
277
|
-
it('should emit page change events', () => {
|
|
73
|
+
it('should emit page change events', async () => {
|
|
278
74
|
const wrapper = mount(Table, {
|
|
279
|
-
props: { items: mockItems,
|
|
75
|
+
props: { items: mockItems, header: mockHeader, currentPage: 1 },
|
|
280
76
|
global: { stubs: globalStubs }
|
|
281
77
|
});
|
|
282
78
|
|
|
283
79
|
const vm = wrapper.vm as any;
|
|
284
80
|
vm.handleChangePage(2);
|
|
81
|
+
await nextTick();
|
|
285
82
|
|
|
286
83
|
expect(wrapper.emitted('update:currentPage')).toBeDefined();
|
|
287
84
|
expect(wrapper.emitted('update:currentPage')?.[0]).toEqual([2]);
|
|
288
|
-
expect(wrapper.emitted('page
|
|
289
|
-
expect(wrapper.emitted('page
|
|
85
|
+
expect(wrapper.emitted('change-page')).toBeDefined();
|
|
86
|
+
expect(wrapper.emitted('change-page')?.[0]).toEqual([2]);
|
|
290
87
|
});
|
|
88
|
+
});
|
|
291
89
|
|
|
292
|
-
|
|
90
|
+
describe('handleChangePageSize()', () => {
|
|
91
|
+
it('should emit page size change events', async () => {
|
|
293
92
|
const wrapper = mount(Table, {
|
|
294
|
-
props: { items: mockItems,
|
|
93
|
+
props: { items: mockItems, header: mockHeader, pageSize: 10 },
|
|
295
94
|
global: { stubs: globalStubs }
|
|
296
95
|
});
|
|
297
96
|
|
|
298
97
|
const vm = wrapper.vm as any;
|
|
299
|
-
vm.
|
|
300
|
-
|
|
98
|
+
vm.handleChangePageSize(25);
|
|
99
|
+
await nextTick();
|
|
301
100
|
|
|
302
|
-
expect(
|
|
101
|
+
expect(wrapper.emitted('update:pageSize')).toBeDefined();
|
|
102
|
+
expect(wrapper.emitted('update:pageSize')?.[0]).toEqual([25]);
|
|
103
|
+
expect(wrapper.emitted('change-page-size')).toBeDefined();
|
|
104
|
+
expect(wrapper.emitted('change-page-size')?.[0]).toEqual([25]);
|
|
303
105
|
});
|
|
304
|
-
});
|
|
305
106
|
|
|
306
|
-
|
|
307
|
-
it('should emit page size change events', () => {
|
|
107
|
+
it('should reset to page 1 when page size changes', async () => {
|
|
308
108
|
const wrapper = mount(Table, {
|
|
309
|
-
props: { items: mockItems,
|
|
109
|
+
props: { items: mockItems, header: mockHeader, currentPage: 3 },
|
|
310
110
|
global: { stubs: globalStubs }
|
|
311
111
|
});
|
|
312
112
|
|
|
313
113
|
const vm = wrapper.vm as any;
|
|
314
|
-
vm.handleChangePageSize(
|
|
114
|
+
vm.handleChangePageSize(50);
|
|
115
|
+
await nextTick();
|
|
315
116
|
|
|
316
|
-
expect(wrapper.emitted('update:
|
|
317
|
-
expect(wrapper.emitted('update:
|
|
318
|
-
expect(wrapper.emitted('items-per-page-changed')).toBeDefined();
|
|
319
|
-
expect(wrapper.emitted('items-per-page-changed')?.[0]).toEqual([25]);
|
|
117
|
+
expect(wrapper.emitted('update:currentPage')).toBeDefined();
|
|
118
|
+
expect(wrapper.emitted('update:currentPage')?.[0]).toEqual([1]);
|
|
320
119
|
});
|
|
321
120
|
|
|
322
|
-
it('should
|
|
121
|
+
it('should handle string page size value', async () => {
|
|
323
122
|
const wrapper = mount(Table, {
|
|
324
|
-
props: { items: mockItems,
|
|
123
|
+
props: { items: mockItems, header: mockHeader, pageSize: 10 },
|
|
325
124
|
global: { stubs: globalStubs }
|
|
326
125
|
});
|
|
327
126
|
|
|
328
127
|
const vm = wrapper.vm as any;
|
|
329
|
-
vm.handleChangePageSize(
|
|
128
|
+
vm.handleChangePageSize('25');
|
|
129
|
+
await nextTick();
|
|
330
130
|
|
|
331
|
-
expect(wrapper.emitted('update:
|
|
332
|
-
expect(wrapper.emitted('update:currentPage')?.[0]).toEqual([1]);
|
|
131
|
+
expect(wrapper.emitted('update:pageSize')?.[0]).toEqual([25]);
|
|
333
132
|
});
|
|
334
133
|
});
|
|
335
134
|
|
|
336
135
|
describe('handleColumnsVisibilityChanged()', () => {
|
|
337
|
-
it('should add column to hidden list', () => {
|
|
136
|
+
it('should add column to hidden list', async () => {
|
|
338
137
|
const wrapper = mount(Table, {
|
|
339
|
-
props: { items: mockItems,
|
|
138
|
+
props: { items: mockItems, header: mockHeader },
|
|
340
139
|
global: { stubs: globalStubs }
|
|
341
140
|
});
|
|
342
141
|
|
|
343
142
|
const vm = wrapper.vm as any;
|
|
344
143
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: true });
|
|
144
|
+
await nextTick();
|
|
345
145
|
|
|
346
|
-
expect(vm.
|
|
146
|
+
expect(vm.internalHiddenColumns).toContain(1);
|
|
147
|
+
expect(wrapper.emitted('columns-visibility-changed')).toBeDefined();
|
|
347
148
|
});
|
|
348
149
|
|
|
349
|
-
it('should remove column from hidden list', () => {
|
|
150
|
+
it('should remove column from hidden list', async () => {
|
|
350
151
|
const wrapper = mount(Table, {
|
|
351
|
-
props: { items: mockItems,
|
|
152
|
+
props: { items: mockItems, header: mockHeader, hiddenColumns: [1, 2] },
|
|
352
153
|
global: { stubs: globalStubs }
|
|
353
154
|
});
|
|
354
155
|
|
|
355
156
|
const vm = wrapper.vm as any;
|
|
356
|
-
vm.hiddenColumns = [1, 2];
|
|
357
157
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: false });
|
|
158
|
+
await nextTick();
|
|
358
159
|
|
|
359
|
-
expect(vm.
|
|
360
|
-
expect(vm.
|
|
160
|
+
expect(vm.internalHiddenColumns).not.toContain(1);
|
|
161
|
+
expect(vm.internalHiddenColumns).toContain(2);
|
|
361
162
|
});
|
|
362
163
|
|
|
363
|
-
it('should not duplicate hidden columns', () => {
|
|
164
|
+
it('should not duplicate hidden columns', async () => {
|
|
364
165
|
const wrapper = mount(Table, {
|
|
365
|
-
props: { items: mockItems,
|
|
166
|
+
props: { items: mockItems, header: mockHeader },
|
|
366
167
|
global: { stubs: globalStubs }
|
|
367
168
|
});
|
|
368
169
|
|
|
369
170
|
const vm = wrapper.vm as any;
|
|
370
171
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: true });
|
|
371
172
|
vm.handleColumnsVisibilityChanged({ index: 1, hidden: true });
|
|
173
|
+
await nextTick();
|
|
372
174
|
|
|
373
|
-
expect(vm.
|
|
175
|
+
expect(vm.internalHiddenColumns.filter((i: number) => i === 1)).toHaveLength(1);
|
|
374
176
|
});
|
|
375
177
|
});
|
|
376
178
|
|
|
377
|
-
describe('
|
|
378
|
-
it('should clear
|
|
179
|
+
describe('exposed methods', () => {
|
|
180
|
+
it('clearSelection should clear selectedItemIds and emit events', async () => {
|
|
379
181
|
const wrapper = mount(Table, {
|
|
380
|
-
props: { items: mockItems,
|
|
182
|
+
props: { items: mockItems, header: mockHeader },
|
|
381
183
|
global: { stubs: globalStubs }
|
|
382
184
|
});
|
|
383
185
|
|
|
384
186
|
const vm = wrapper.vm as any;
|
|
385
187
|
vm.selectedItemIds = new Set([1, 2, 3]);
|
|
386
188
|
vm.clearSelection();
|
|
189
|
+
await nextTick();
|
|
387
190
|
|
|
388
191
|
expect(vm.selectedItemIds.size).toBe(0);
|
|
389
|
-
expect(
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it('should emit update:selected with empty array', () => {
|
|
393
|
-
const wrapper = mount(Table, {
|
|
394
|
-
props: { items: mockItems, columns: mockColumns },
|
|
395
|
-
global: { stubs: globalStubs }
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
const vm = wrapper.vm as any;
|
|
399
|
-
vm.selectedItemIds = new Set([1, 2]);
|
|
400
|
-
vm.clearSelection();
|
|
401
|
-
|
|
402
|
-
expect(wrapper.emitted('update:selected')).toBeDefined();
|
|
403
|
-
const lastEmit = wrapper.emitted('update:selected')?.slice(-1)[0];
|
|
404
|
-
expect(lastEmit?.[0]).toEqual([]);
|
|
192
|
+
expect(wrapper.emitted('update:resetSelected')).toBeDefined();
|
|
405
193
|
});
|
|
406
|
-
});
|
|
407
194
|
|
|
408
|
-
|
|
409
|
-
it('should return hidden columns array', () => {
|
|
195
|
+
it('getHiddenColumns should return internal hidden columns', async () => {
|
|
410
196
|
const wrapper = mount(Table, {
|
|
411
|
-
props: { items: mockItems,
|
|
197
|
+
props: { items: mockItems, header: mockHeader, hiddenColumns: [0, 2] },
|
|
412
198
|
global: { stubs: globalStubs }
|
|
413
199
|
});
|
|
414
200
|
|
|
415
201
|
const vm = wrapper.vm as any;
|
|
416
|
-
vm.hiddenColumns = [0, 2];
|
|
417
|
-
|
|
418
202
|
expect(vm.getHiddenColumns()).toEqual([0, 2]);
|
|
419
203
|
});
|
|
420
204
|
|
|
421
|
-
it('should return
|
|
205
|
+
it('getSelectedItems should return selected item IDs as array', async () => {
|
|
422
206
|
const wrapper = mount(Table, {
|
|
423
|
-
props: { items: mockItems,
|
|
207
|
+
props: { items: mockItems, header: mockHeader },
|
|
424
208
|
global: { stubs: globalStubs }
|
|
425
209
|
});
|
|
426
210
|
|
|
427
211
|
const vm = wrapper.vm as any;
|
|
428
|
-
|
|
212
|
+
vm.selectedItemIds = new Set([1, 3]);
|
|
213
|
+
|
|
214
|
+
const selected = vm.getSelectedItems();
|
|
215
|
+
expect(selected).toContain(1);
|
|
216
|
+
expect(selected).toContain(3);
|
|
217
|
+
expect(selected).toHaveLength(2);
|
|
429
218
|
});
|
|
430
219
|
});
|
|
431
220
|
|
|
432
|
-
describe('
|
|
433
|
-
it('should
|
|
221
|
+
describe('handleSmartFiltersSent()', () => {
|
|
222
|
+
it('should emit smart-filters-sent event', async () => {
|
|
434
223
|
const wrapper = mount(Table, {
|
|
435
|
-
props: { items: mockItems,
|
|
224
|
+
props: { items: mockItems, header: mockHeader },
|
|
436
225
|
global: { stubs: globalStubs }
|
|
437
226
|
});
|
|
438
227
|
|
|
439
228
|
const vm = wrapper.vm as any;
|
|
440
|
-
|
|
229
|
+
const filters = { name: 'John' };
|
|
230
|
+
vm.handleSmartFiltersSent(filters);
|
|
231
|
+
await nextTick();
|
|
441
232
|
|
|
442
|
-
|
|
443
|
-
expect(
|
|
444
|
-
expect(selected).toContain(3);
|
|
445
|
-
expect(selected).toHaveLength(2);
|
|
233
|
+
expect(wrapper.emitted('smart-filters-sent')).toBeDefined();
|
|
234
|
+
expect(wrapper.emitted('smart-filters-sent')?.[0]).toEqual([filters]);
|
|
446
235
|
});
|
|
236
|
+
});
|
|
447
237
|
|
|
448
|
-
|
|
238
|
+
describe('handleSelectAllItems()', () => {
|
|
239
|
+
it('should select all items and emit event', async () => {
|
|
449
240
|
const wrapper = mount(Table, {
|
|
450
|
-
props: { items: mockItems,
|
|
241
|
+
props: { items: mockItems, header: mockHeader },
|
|
451
242
|
global: { stubs: globalStubs }
|
|
452
243
|
});
|
|
453
244
|
|
|
454
245
|
const vm = wrapper.vm as any;
|
|
455
|
-
|
|
246
|
+
vm.handleSelectAllItems();
|
|
247
|
+
await nextTick();
|
|
248
|
+
|
|
249
|
+
expect(vm.selectedItemIds.size).toBe(3);
|
|
250
|
+
expect(vm.selectedItemIds.has(1)).toBe(true);
|
|
251
|
+
expect(vm.selectedItemIds.has(2)).toBe(true);
|
|
252
|
+
expect(vm.selectedItemIds.has(3)).toBe(true);
|
|
253
|
+
expect(wrapper.emitted('select-all-items')).toBeDefined();
|
|
456
254
|
});
|
|
457
255
|
});
|
|
458
256
|
|
|
459
|
-
describe('
|
|
460
|
-
it('should
|
|
257
|
+
describe('handleDeselectAllItems()', () => {
|
|
258
|
+
it('should deselect all items and emit event', async () => {
|
|
461
259
|
const wrapper = mount(Table, {
|
|
462
|
-
props: { items: mockItems,
|
|
260
|
+
props: { items: mockItems, header: mockHeader },
|
|
463
261
|
global: { stubs: globalStubs }
|
|
464
262
|
});
|
|
465
263
|
|
|
466
264
|
const vm = wrapper.vm as any;
|
|
467
|
-
vm.
|
|
265
|
+
vm.selectedItemIds = new Set([1, 2, 3]);
|
|
266
|
+
vm.handleDeselectAllItems();
|
|
267
|
+
await nextTick();
|
|
468
268
|
|
|
469
|
-
expect(vm.
|
|
269
|
+
expect(vm.selectedItemIds.size).toBe(0);
|
|
270
|
+
expect(wrapper.emitted('deselect-all-items')).toBeDefined();
|
|
470
271
|
});
|
|
272
|
+
});
|
|
471
273
|
|
|
472
|
-
|
|
274
|
+
describe('handleTableAction()', () => {
|
|
275
|
+
it('should update selectedItemIds and emit table-action event', async () => {
|
|
473
276
|
const wrapper = mount(Table, {
|
|
474
|
-
props: { items: mockItems,
|
|
277
|
+
props: { items: mockItems, header: mockHeader },
|
|
475
278
|
global: { stubs: globalStubs }
|
|
476
279
|
});
|
|
477
280
|
|
|
478
281
|
const vm = wrapper.vm as any;
|
|
479
|
-
|
|
480
|
-
|
|
282
|
+
vm.handleTableAction({ action: 'delete', items: [1, 3] });
|
|
283
|
+
await nextTick();
|
|
481
284
|
|
|
482
|
-
expect(
|
|
483
|
-
expect(wrapper.emitted('
|
|
484
|
-
expect(wrapper.emitted('
|
|
485
|
-
expect(wrapper.emitted('multiple-filters-applied')?.[0]).toEqual([filters]);
|
|
285
|
+
expect(vm.selectedItemIds.size).toBe(2);
|
|
286
|
+
expect(wrapper.emitted('table-action')).toBeDefined();
|
|
287
|
+
expect(wrapper.emitted('table-action')?.[0]).toEqual([{ action: 'delete', items: [1, 3] }]);
|
|
486
288
|
});
|
|
487
289
|
});
|
|
488
290
|
|
|
489
|
-
describe('
|
|
490
|
-
it('should
|
|
291
|
+
describe('handleSmartFiltersCleared()', () => {
|
|
292
|
+
it('should emit smart-filters-cleared event', async () => {
|
|
491
293
|
const wrapper = mount(Table, {
|
|
492
|
-
props: { items: mockItems,
|
|
294
|
+
props: { items: mockItems, header: mockHeader },
|
|
493
295
|
global: { stubs: globalStubs }
|
|
494
296
|
});
|
|
495
297
|
|
|
496
298
|
const vm = wrapper.vm as any;
|
|
497
|
-
vm.
|
|
299
|
+
vm.handleSmartFiltersCleared();
|
|
300
|
+
await nextTick();
|
|
498
301
|
|
|
499
|
-
expect(
|
|
500
|
-
expect(vm.selectedItemIds.has(1)).toBe(true);
|
|
501
|
-
expect(vm.selectedItemIds.has(2)).toBe(true);
|
|
502
|
-
expect(vm.selectedItemIds.has(3)).toBe(true);
|
|
302
|
+
expect(wrapper.emitted('smart-filters-cleared')).toBeDefined();
|
|
503
303
|
});
|
|
304
|
+
});
|
|
504
305
|
|
|
505
|
-
|
|
306
|
+
describe('handleSmartFilterDeleted()', () => {
|
|
307
|
+
it('should emit smart-filter-deleted event with index', async () => {
|
|
506
308
|
const wrapper = mount(Table, {
|
|
507
|
-
props: { items: mockItems,
|
|
309
|
+
props: { items: mockItems, header: mockHeader },
|
|
508
310
|
global: { stubs: globalStubs }
|
|
509
311
|
});
|
|
510
312
|
|
|
511
313
|
const vm = wrapper.vm as any;
|
|
512
|
-
vm.
|
|
314
|
+
vm.handleSmartFilterDeleted(0);
|
|
315
|
+
await nextTick();
|
|
513
316
|
|
|
514
|
-
expect(wrapper.emitted('
|
|
317
|
+
expect(wrapper.emitted('smart-filter-deleted')).toBeDefined();
|
|
318
|
+
expect(wrapper.emitted('smart-filter-deleted')?.[0]).toEqual([0]);
|
|
515
319
|
});
|
|
516
320
|
});
|
|
517
321
|
|
|
518
|
-
describe('
|
|
519
|
-
it('should
|
|
322
|
+
describe('handleNoResultsAction()', () => {
|
|
323
|
+
it('should emit no-results-action event', async () => {
|
|
520
324
|
const wrapper = mount(Table, {
|
|
521
|
-
props: { items:
|
|
325
|
+
props: { items: [], header: mockHeader },
|
|
522
326
|
global: { stubs: globalStubs }
|
|
523
327
|
});
|
|
524
328
|
|
|
525
329
|
const vm = wrapper.vm as any;
|
|
526
|
-
vm.
|
|
527
|
-
|
|
330
|
+
vm.handleNoResultsAction('create');
|
|
331
|
+
await nextTick();
|
|
528
332
|
|
|
529
|
-
expect(
|
|
333
|
+
expect(wrapper.emitted('no-results-action')).toBeDefined();
|
|
334
|
+
expect(wrapper.emitted('no-results-action')?.[0]).toEqual(['create']);
|
|
530
335
|
});
|
|
336
|
+
});
|
|
531
337
|
|
|
532
|
-
|
|
338
|
+
describe('handleModalAction()', () => {
|
|
339
|
+
it('should emit modal-action event', async () => {
|
|
533
340
|
const wrapper = mount(Table, {
|
|
534
|
-
props: { items: mockItems,
|
|
341
|
+
props: { items: mockItems, header: mockHeader },
|
|
535
342
|
global: { stubs: globalStubs }
|
|
536
343
|
});
|
|
537
344
|
|
|
538
345
|
const vm = wrapper.vm as any;
|
|
539
|
-
vm.
|
|
346
|
+
vm.handleModalAction({ modal: 'confirm-delete', action: 'confirm' });
|
|
347
|
+
await nextTick();
|
|
540
348
|
|
|
541
|
-
expect(wrapper.emitted('
|
|
349
|
+
expect(wrapper.emitted('modal-action')).toBeDefined();
|
|
350
|
+
expect(wrapper.emitted('modal-action')?.[0]).toEqual([{ modal: 'confirm-delete', action: 'confirm' }]);
|
|
542
351
|
});
|
|
543
352
|
});
|
|
544
353
|
});
|