@zeedhi/teknisa-components-common 1.130.0 → 1.132.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/coverage/clover.xml +1224 -1109
- package/coverage/coverage-final.json +48 -46
- package/coverage/lcov-report/index.html +22 -22
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +3 -3
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +11 -11
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +4 -4
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +3 -3
- package/coverage/lcov.info +2230 -1993
- package/dist/tek-components-common.esm.js +393 -195
- package/dist/tek-components-common.umd.js +393 -194
- package/package.json +2 -2
- package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +123 -2
- package/tests/unit/components/tek-grid/grid-export-button.spec.ts +403 -0
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +147 -4
- package/tests/unit/components/tek-grid/grid.spec.ts +182 -9
- package/tests/unit/components/tek-grid/layout_options.spec.ts +680 -25
- package/tests/unit/utils/object-comparison.spec.ts +89 -0
- package/types/components/index.d.ts +1 -0
- package/types/components/tek-grid/grid-columns-button.d.ts +2 -1
- package/types/components/tek-grid/grid-export-button.d.ts +19 -0
- package/types/components/tek-grid/grid-filter-button.d.ts +1 -0
- package/types/components/tek-grid/grid.d.ts +4 -0
- package/types/components/tek-grid/interfaces.d.ts +8 -0
- package/types/components/tek-grid/layout-options.d.ts +15 -0
- package/types/components/tek-tree-grid/tree-grid.d.ts +2 -0
- package/types/utils/grid-base/export-options/button-option.d.ts +3 -1
- package/types/utils/grid-base/export-options/multi-option.d.ts +3 -1
- package/types/utils/grid-base/grid-base.d.ts +1 -3
- package/types/utils/index.d.ts +1 -0
- package/types/utils/object-comparison.d.ts +3 -0
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ITekGridLayoutInfo,
|
|
9
9
|
TekGrid,
|
|
10
10
|
TekGridLayoutOptions,
|
|
11
|
+
TekRestDatasource,
|
|
11
12
|
} from '../../../../src';
|
|
12
13
|
import { setClick } from '../../../__helpers__';
|
|
13
14
|
|
|
@@ -51,9 +52,321 @@ describe('LayoutOptions', () => {
|
|
|
51
52
|
expect(instance.layoutNames).toEqual([]);
|
|
52
53
|
expect(instance.originalColumnProps).toEqual([]);
|
|
53
54
|
});
|
|
55
|
+
|
|
56
|
+
it('should create layout options object with gridName', () => {
|
|
57
|
+
const instance = new TekGridLayoutOptions({
|
|
58
|
+
name: 'layout_with_grid_name',
|
|
59
|
+
component: 'TekGridLayoutOptions',
|
|
60
|
+
gridName: 'layout_grid_name',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(instance.gridName).toBe('layout_grid_name');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('loadGrid()', () => {
|
|
68
|
+
it('should load grid by gridName', () => {
|
|
69
|
+
const grid = new TekGrid({
|
|
70
|
+
name: 'layout_options_load_grid',
|
|
71
|
+
component: 'TekGrid',
|
|
72
|
+
});
|
|
73
|
+
grid.onCreated();
|
|
74
|
+
|
|
75
|
+
const instance = new TekGridLayoutOptions({
|
|
76
|
+
name: 'layout_load_grid',
|
|
77
|
+
component: 'TekGridLayoutOptions',
|
|
78
|
+
gridName: 'layout_options_load_grid',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
instance.loadGrid();
|
|
82
|
+
|
|
83
|
+
expect(instance.grid).toBe(grid);
|
|
84
|
+
expect(instance.gridName).toBe(grid.name);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should load grid by gridName after layout options is created', () => {
|
|
88
|
+
const instance = new TekGridLayoutOptions({
|
|
89
|
+
name: 'layout_load_grid_late',
|
|
90
|
+
component: 'TekGridLayoutOptions',
|
|
91
|
+
gridName: 'layout_options_late_grid',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(instance.grid).toBeUndefined();
|
|
95
|
+
|
|
96
|
+
const grid = new TekGrid({
|
|
97
|
+
name: 'layout_options_late_grid',
|
|
98
|
+
component: 'TekGrid',
|
|
99
|
+
});
|
|
100
|
+
grid.onCreated();
|
|
101
|
+
|
|
102
|
+
instance.loadGrid();
|
|
103
|
+
|
|
104
|
+
expect(instance.grid).toBe(grid);
|
|
105
|
+
expect(instance.gridName).toBe(grid.name);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should load grid by gridName argument', () => {
|
|
109
|
+
const grid = new TekGrid({
|
|
110
|
+
name: 'layout_options_argument_grid',
|
|
111
|
+
component: 'TekGrid',
|
|
112
|
+
});
|
|
113
|
+
grid.onCreated();
|
|
114
|
+
|
|
115
|
+
const instance = new TekGridLayoutOptions({
|
|
116
|
+
name: 'layout_load_grid_argument',
|
|
117
|
+
component: 'TekGridLayoutOptions',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
instance.loadGrid('layout_options_argument_grid');
|
|
121
|
+
|
|
122
|
+
expect(instance.grid).toBe(grid);
|
|
123
|
+
expect(instance.gridName).toBe(grid.name);
|
|
124
|
+
});
|
|
54
125
|
});
|
|
55
126
|
|
|
56
127
|
describe('mounted()', () => {
|
|
128
|
+
it('should store original props from gridName when mounted outside the grid', async () => {
|
|
129
|
+
const parentGrid = new Grid({
|
|
130
|
+
name: 'layout_options_parent_grid',
|
|
131
|
+
component: 'Grid',
|
|
132
|
+
columns: [{ name: 'parent_id' }],
|
|
133
|
+
});
|
|
134
|
+
const grid = new TekGrid({
|
|
135
|
+
name: 'layout_options_named_grid',
|
|
136
|
+
component: 'TekGrid',
|
|
137
|
+
columns: [
|
|
138
|
+
{ name: 'id' },
|
|
139
|
+
{ name: 'name' },
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
grid.onCreated();
|
|
143
|
+
|
|
144
|
+
const instance = new TekGridLayoutOptions({
|
|
145
|
+
name: 'layout_named_grid',
|
|
146
|
+
component: 'TekGridLayoutOptions',
|
|
147
|
+
gridName: 'layout_options_named_grid',
|
|
148
|
+
});
|
|
149
|
+
instance.parent = parentGrid;
|
|
150
|
+
|
|
151
|
+
await instance.onMounted({} as HTMLElement);
|
|
152
|
+
|
|
153
|
+
expect(instance.grid).toBe(grid);
|
|
154
|
+
expect(instance.originalColumnProps.map((column) => column.name)).toEqual(['id', 'name']);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should not mark layout as edited when named grid layout change does not change layout state', async () => {
|
|
158
|
+
const grid = new TekGrid({
|
|
159
|
+
name: 'layout_options_change_layout_grid',
|
|
160
|
+
component: 'TekGrid',
|
|
161
|
+
columns: [{ name: 'id' }],
|
|
162
|
+
});
|
|
163
|
+
grid.onCreated();
|
|
164
|
+
|
|
165
|
+
const instance = new TekGridLayoutOptions({
|
|
166
|
+
name: 'external_layout_options',
|
|
167
|
+
component: 'TekGridLayoutOptions',
|
|
168
|
+
gridName: 'layout_options_change_layout_grid',
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
await instance.onMounted({} as HTMLElement);
|
|
172
|
+
expect(instance.layoutEdited).toBe(false);
|
|
173
|
+
|
|
174
|
+
grid.changeLayout();
|
|
175
|
+
|
|
176
|
+
expect(instance.layoutEdited).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should mark layout as edited only when column width changes explicitly', async () => {
|
|
180
|
+
const grid = new TekGrid({
|
|
181
|
+
name: 'layout_options_column_width_grid',
|
|
182
|
+
component: 'TekGrid',
|
|
183
|
+
columns: [{ name: 'id' }],
|
|
184
|
+
});
|
|
185
|
+
grid.onCreated();
|
|
186
|
+
|
|
187
|
+
const instance = new TekGridLayoutOptions({
|
|
188
|
+
name: 'layout_options_column_width',
|
|
189
|
+
component: 'TekGridLayoutOptions',
|
|
190
|
+
gridName: 'layout_options_column_width_grid',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await instance.onMounted({} as HTMLElement);
|
|
194
|
+
expect(instance.layoutEdited).toBe(false);
|
|
195
|
+
|
|
196
|
+
grid.changeLayout();
|
|
197
|
+
|
|
198
|
+
expect(instance.layoutEdited).toBe(false);
|
|
199
|
+
|
|
200
|
+
grid.columns[0].width = '120px';
|
|
201
|
+
grid.changeLayout();
|
|
202
|
+
|
|
203
|
+
expect(instance.layoutEdited).toBe(true);
|
|
204
|
+
|
|
205
|
+
grid.columns[0].width = undefined;
|
|
206
|
+
grid.changeLayout();
|
|
207
|
+
|
|
208
|
+
expect(instance.layoutEdited).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should compare current grid layout with selected named layout', async () => {
|
|
212
|
+
const grid = new TekGrid({
|
|
213
|
+
name: 'layout_options_named_baseline_grid',
|
|
214
|
+
component: 'TekGrid',
|
|
215
|
+
columns: [{ name: 'id' }],
|
|
216
|
+
});
|
|
217
|
+
grid.onCreated();
|
|
218
|
+
|
|
219
|
+
const instance = new TekGridLayoutOptions({
|
|
220
|
+
name: 'layout_options_named_baseline',
|
|
221
|
+
component: 'TekGridLayoutOptions',
|
|
222
|
+
gridName: 'layout_options_named_baseline_grid',
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await instance.onMounted({} as HTMLElement);
|
|
226
|
+
|
|
227
|
+
const selectedLayout = instance.getCurrentLayout();
|
|
228
|
+
selectedLayout.name = 'Name first';
|
|
229
|
+
instance.layouts = {
|
|
230
|
+
'Name first': selectedLayout,
|
|
231
|
+
};
|
|
232
|
+
instance.currentLayoutName = 'Name first';
|
|
233
|
+
|
|
234
|
+
expect(instance.hasLayoutChanges()).toBe(false);
|
|
235
|
+
|
|
236
|
+
grid.columns[0].width = '120px';
|
|
237
|
+
|
|
238
|
+
expect(instance.hasLayoutChanges()).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('should not detect layout changes when there is no baseline layout', async () => {
|
|
242
|
+
const grid = new TekGrid({
|
|
243
|
+
name: 'layout_options_without_baseline_grid',
|
|
244
|
+
component: 'TekGrid',
|
|
245
|
+
columns: [{ name: 'id' }],
|
|
246
|
+
});
|
|
247
|
+
grid.onCreated();
|
|
248
|
+
|
|
249
|
+
const instance = new TekGridLayoutOptions({
|
|
250
|
+
name: 'layout_options_without_baseline',
|
|
251
|
+
component: 'TekGridLayoutOptions',
|
|
252
|
+
gridName: 'layout_options_without_baseline_grid',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
await instance.onMounted({} as HTMLElement);
|
|
256
|
+
instance.currentLayoutName = 'Missing layout';
|
|
257
|
+
|
|
258
|
+
expect(instance.hasLayoutChanges()).toBe(false);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('should mark layout as edited when filter changes and clear when filter is restored', async () => {
|
|
262
|
+
const grid = new TekGrid({
|
|
263
|
+
name: 'layout_options_filter_undo_grid',
|
|
264
|
+
component: 'TekGrid',
|
|
265
|
+
columns: [{ name: 'id' }],
|
|
266
|
+
});
|
|
267
|
+
grid.onCreated();
|
|
268
|
+
|
|
269
|
+
const instance = new TekGridLayoutOptions({
|
|
270
|
+
name: 'layout_options_filter_undo',
|
|
271
|
+
component: 'TekGridLayoutOptions',
|
|
272
|
+
gridName: 'layout_options_filter_undo_grid',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
await instance.onMounted({} as HTMLElement);
|
|
276
|
+
expect(instance.layoutEdited).toBe(false);
|
|
277
|
+
|
|
278
|
+
grid.datasource.filter = { id: '10' };
|
|
279
|
+
grid.changeLayout();
|
|
280
|
+
|
|
281
|
+
expect(instance.layoutEdited).toBe(true);
|
|
282
|
+
|
|
283
|
+
grid.datasource.filter = {};
|
|
284
|
+
grid.changeLayout();
|
|
285
|
+
|
|
286
|
+
expect(instance.layoutEdited).toBe(false);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should mark layout as edited when dynamic filter changes and clear when dynamic filter is restored', async () => {
|
|
290
|
+
const grid = new TekGrid({
|
|
291
|
+
name: 'layout_options_dynamic_filter_undo_grid',
|
|
292
|
+
component: 'TekGrid',
|
|
293
|
+
datasource: {
|
|
294
|
+
type: 'tek-rest',
|
|
295
|
+
lazyLoad: true,
|
|
296
|
+
dynamicFilter: {
|
|
297
|
+
id: [{ relation: 'AND', operation: 'EQUALS', value: '10' }],
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
columns: [{ name: 'id' }],
|
|
301
|
+
});
|
|
302
|
+
grid.onCreated();
|
|
303
|
+
|
|
304
|
+
const instance = new TekGridLayoutOptions({
|
|
305
|
+
name: 'layout_options_dynamic_filter_undo',
|
|
306
|
+
component: 'TekGridLayoutOptions',
|
|
307
|
+
gridName: 'layout_options_dynamic_filter_undo_grid',
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
await instance.onMounted({} as HTMLElement);
|
|
311
|
+
expect(instance.layoutEdited).toBe(false);
|
|
312
|
+
|
|
313
|
+
(grid.datasource as TekRestDatasource).dynamicFilter.id[0].value = '20';
|
|
314
|
+
grid.changeLayout();
|
|
315
|
+
|
|
316
|
+
expect(instance.layoutEdited).toBe(true);
|
|
317
|
+
|
|
318
|
+
(grid.datasource as TekRestDatasource).dynamicFilter.id[0].value = '10';
|
|
319
|
+
grid.changeLayout();
|
|
320
|
+
|
|
321
|
+
expect(instance.layoutEdited).toBe(false);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should preserve existing changeLayout event handlers', async () => {
|
|
325
|
+
let changeLayoutCalled = false;
|
|
326
|
+
const grid = new TekGrid({
|
|
327
|
+
name: 'layout_options_existing_change_layout_grid',
|
|
328
|
+
component: 'TekGrid',
|
|
329
|
+
columns: [{ name: 'id' }],
|
|
330
|
+
events: {
|
|
331
|
+
changeLayout: () => {
|
|
332
|
+
changeLayoutCalled = true;
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
grid.onCreated();
|
|
337
|
+
|
|
338
|
+
const instance = new TekGridLayoutOptions({
|
|
339
|
+
name: 'external_existing_layout_options',
|
|
340
|
+
component: 'TekGridLayoutOptions',
|
|
341
|
+
gridName: 'layout_options_existing_change_layout_grid',
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
await instance.onMounted({} as HTMLElement);
|
|
345
|
+
grid.changeLayout();
|
|
346
|
+
|
|
347
|
+
expect(changeLayoutCalled).toBe(true);
|
|
348
|
+
expect(instance.layoutEdited).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should mark layout as edited when parent grid layout changes', async () => {
|
|
352
|
+
const grid = new Grid({
|
|
353
|
+
name: 'layout_options_parent_change_layout_grid',
|
|
354
|
+
component: 'Grid',
|
|
355
|
+
columns: [{ name: 'id' }],
|
|
356
|
+
});
|
|
357
|
+
const instance = new TekGridLayoutOptions({
|
|
358
|
+
name: 'parent_layout_options',
|
|
359
|
+
component: 'TekGridLayoutOptions',
|
|
360
|
+
});
|
|
361
|
+
instance.parent = grid;
|
|
362
|
+
|
|
363
|
+
await instance.onMounted({} as HTMLElement);
|
|
364
|
+
grid.datasource.filter = { id: '10' };
|
|
365
|
+
grid.changeLayout();
|
|
366
|
+
|
|
367
|
+
expect(instance.layoutEdited).toBe(true);
|
|
368
|
+
});
|
|
369
|
+
|
|
57
370
|
it('should store the original column props of a TekGrid', () => {
|
|
58
371
|
const tag = new Tag({
|
|
59
372
|
name: 'toolbar',
|
|
@@ -103,11 +416,11 @@ describe('LayoutOptions', () => {
|
|
|
103
416
|
isVisible: true,
|
|
104
417
|
fixed: false,
|
|
105
418
|
grouped: false,
|
|
106
|
-
minWidth:
|
|
107
|
-
maxWidth:
|
|
419
|
+
minWidth: '',
|
|
420
|
+
maxWidth: '',
|
|
108
421
|
aggregation: undefined,
|
|
109
422
|
align: 'left',
|
|
110
|
-
groupOpened:
|
|
423
|
+
groupOpened: false,
|
|
111
424
|
label: '',
|
|
112
425
|
filterHelperValue: [],
|
|
113
426
|
},
|
|
@@ -116,11 +429,11 @@ describe('LayoutOptions', () => {
|
|
|
116
429
|
isVisible: true,
|
|
117
430
|
fixed: false,
|
|
118
431
|
grouped: false,
|
|
119
|
-
minWidth:
|
|
120
|
-
maxWidth:
|
|
432
|
+
minWidth: '',
|
|
433
|
+
maxWidth: '',
|
|
121
434
|
aggregation: undefined,
|
|
122
435
|
align: 'left',
|
|
123
|
-
groupOpened:
|
|
436
|
+
groupOpened: false,
|
|
124
437
|
label: '',
|
|
125
438
|
filterHelperValue: [],
|
|
126
439
|
},
|
|
@@ -129,11 +442,11 @@ describe('LayoutOptions', () => {
|
|
|
129
442
|
isVisible: true,
|
|
130
443
|
fixed: false,
|
|
131
444
|
grouped: false,
|
|
132
|
-
minWidth:
|
|
133
|
-
maxWidth:
|
|
445
|
+
minWidth: '',
|
|
446
|
+
maxWidth: '',
|
|
134
447
|
aggregation: undefined,
|
|
135
448
|
align: 'left',
|
|
136
|
-
groupOpened:
|
|
449
|
+
groupOpened: false,
|
|
137
450
|
label: '',
|
|
138
451
|
filterHelperValue: [],
|
|
139
452
|
},
|
|
@@ -142,11 +455,11 @@ describe('LayoutOptions', () => {
|
|
|
142
455
|
isVisible: true,
|
|
143
456
|
fixed: false,
|
|
144
457
|
grouped: false,
|
|
145
|
-
minWidth:
|
|
146
|
-
maxWidth:
|
|
458
|
+
minWidth: '',
|
|
459
|
+
maxWidth: '',
|
|
147
460
|
aggregation: undefined,
|
|
148
461
|
align: 'left',
|
|
149
|
-
groupOpened:
|
|
462
|
+
groupOpened: false,
|
|
150
463
|
label: '',
|
|
151
464
|
filterHelperValue: 'TODAY',
|
|
152
465
|
},
|
|
@@ -155,11 +468,11 @@ describe('LayoutOptions', () => {
|
|
|
155
468
|
isVisible: true,
|
|
156
469
|
fixed: false,
|
|
157
470
|
grouped: false,
|
|
158
|
-
minWidth:
|
|
159
|
-
maxWidth:
|
|
471
|
+
minWidth: '',
|
|
472
|
+
maxWidth: '',
|
|
160
473
|
aggregation: undefined,
|
|
161
474
|
align: 'left',
|
|
162
|
-
groupOpened:
|
|
475
|
+
groupOpened: false,
|
|
163
476
|
label: '',
|
|
164
477
|
filterHelperValue: ['TODAY', 'TOMORROW'],
|
|
165
478
|
},
|
|
@@ -189,37 +502,37 @@ describe('LayoutOptions', () => {
|
|
|
189
502
|
minWidth: '100px',
|
|
190
503
|
aggregation: undefined,
|
|
191
504
|
align: 'left',
|
|
192
|
-
groupOpened:
|
|
505
|
+
groupOpened: false,
|
|
193
506
|
label: '',
|
|
194
507
|
filterHelperValue: '',
|
|
195
508
|
fixed: false,
|
|
196
|
-
grouped:
|
|
509
|
+
grouped: false,
|
|
197
510
|
},
|
|
198
511
|
{
|
|
199
512
|
name: 'name',
|
|
200
513
|
isVisible: true,
|
|
201
|
-
minWidth:
|
|
202
|
-
maxWidth:
|
|
514
|
+
minWidth: '',
|
|
515
|
+
maxWidth: '',
|
|
203
516
|
aggregation: undefined,
|
|
204
517
|
align: 'left',
|
|
205
|
-
groupOpened:
|
|
518
|
+
groupOpened: false,
|
|
206
519
|
label: '',
|
|
207
520
|
filterHelperValue: '',
|
|
208
521
|
fixed: false,
|
|
209
|
-
grouped:
|
|
522
|
+
grouped: false,
|
|
210
523
|
},
|
|
211
524
|
{
|
|
212
525
|
name: 'salary',
|
|
213
526
|
isVisible: true,
|
|
214
|
-
minWidth:
|
|
215
|
-
maxWidth:
|
|
527
|
+
minWidth: '',
|
|
528
|
+
maxWidth: '',
|
|
216
529
|
aggregation: undefined,
|
|
217
530
|
align: 'left',
|
|
218
|
-
groupOpened:
|
|
531
|
+
groupOpened: false,
|
|
219
532
|
label: '',
|
|
220
533
|
filterHelperValue: '',
|
|
221
534
|
fixed: false,
|
|
222
|
-
grouped:
|
|
535
|
+
grouped: false,
|
|
223
536
|
},
|
|
224
537
|
]);
|
|
225
538
|
});
|
|
@@ -603,6 +916,41 @@ describe('LayoutOptions', () => {
|
|
|
603
916
|
expect(instance.currentLayoutName).toBe('Name first');
|
|
604
917
|
expect(instance.layouts['Name last'].gridWidth).toBe('740px');
|
|
605
918
|
});
|
|
919
|
+
|
|
920
|
+
it('should call beforeApplyLayout with default layout', async () => {
|
|
921
|
+
let appliedLayout: ITekGridApplyLayoutEventParams['layout'];
|
|
922
|
+
const tag = new Tag({
|
|
923
|
+
name: 'toolbar',
|
|
924
|
+
component: 'ZdTag',
|
|
925
|
+
tag: 'span',
|
|
926
|
+
});
|
|
927
|
+
const grid = new TekGrid({
|
|
928
|
+
name: 'grid_apply_default_layout',
|
|
929
|
+
component: 'TekGrid',
|
|
930
|
+
columns: [
|
|
931
|
+
{ name: 'id' },
|
|
932
|
+
{ name: 'name' },
|
|
933
|
+
{ name: 'salary' },
|
|
934
|
+
],
|
|
935
|
+
events: {
|
|
936
|
+
beforeApplyLayout: ({ layout }: ITekGridApplyLayoutEventParams) => {
|
|
937
|
+
appliedLayout = layout;
|
|
938
|
+
return true;
|
|
939
|
+
},
|
|
940
|
+
},
|
|
941
|
+
});
|
|
942
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_apply_default', component: 'TekGridLayoutOptions' });
|
|
943
|
+
instance.parent = tag;
|
|
944
|
+
tag.parent = grid;
|
|
945
|
+
|
|
946
|
+
await instance.onMounted({} as HTMLElement);
|
|
947
|
+
|
|
948
|
+
instance.applyLayout('');
|
|
949
|
+
|
|
950
|
+
expect(appliedLayout).toEqual(instance.getLayout(''));
|
|
951
|
+
expect(appliedLayout!.name).toBe('');
|
|
952
|
+
expect(instance.currentLayoutName).toBe('');
|
|
953
|
+
});
|
|
606
954
|
});
|
|
607
955
|
|
|
608
956
|
describe('deleteLayout()', () => {
|
|
@@ -664,6 +1012,209 @@ describe('LayoutOptions', () => {
|
|
|
664
1012
|
});
|
|
665
1013
|
});
|
|
666
1014
|
|
|
1015
|
+
describe('getCurrentLayout()', () => {
|
|
1016
|
+
it('should return layout from view bridge when available', () => {
|
|
1017
|
+
const instance = new TekGridLayoutOptions({
|
|
1018
|
+
name: 'layout_current_from_view',
|
|
1019
|
+
component: 'TekGridLayoutOptions',
|
|
1020
|
+
});
|
|
1021
|
+
const layout = {
|
|
1022
|
+
name: '',
|
|
1023
|
+
gridWidth: 'auto',
|
|
1024
|
+
order: [],
|
|
1025
|
+
filter: {},
|
|
1026
|
+
dynamicFilter: {},
|
|
1027
|
+
columns: [],
|
|
1028
|
+
};
|
|
1029
|
+
instance.viewGetCurrentLayout = jest.fn(() => layout);
|
|
1030
|
+
|
|
1031
|
+
expect(instance.getCurrentLayout()).toBe(layout);
|
|
1032
|
+
expect(instance.viewGetCurrentLayout).toBeCalledWith('');
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
it('should return current grid layout', async () => {
|
|
1036
|
+
const tag = new Tag({
|
|
1037
|
+
name: 'toolbar',
|
|
1038
|
+
component: 'ZdTag',
|
|
1039
|
+
tag: 'span',
|
|
1040
|
+
});
|
|
1041
|
+
const grid = new TekGrid({
|
|
1042
|
+
name: 'grid_current_layout',
|
|
1043
|
+
component: 'TekGrid',
|
|
1044
|
+
columns: [
|
|
1045
|
+
{ name: 'id' },
|
|
1046
|
+
{ name: 'name' },
|
|
1047
|
+
{ name: 'salary' },
|
|
1048
|
+
],
|
|
1049
|
+
});
|
|
1050
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_current', component: 'TekGridLayoutOptions' });
|
|
1051
|
+
instance.parent = tag;
|
|
1052
|
+
tag.parent = grid;
|
|
1053
|
+
|
|
1054
|
+
await instance.onMounted({} as HTMLElement);
|
|
1055
|
+
|
|
1056
|
+
grid.datasource.order = ['name.asc'];
|
|
1057
|
+
grid.datasource.filter = { name: 'a' };
|
|
1058
|
+
(grid.datasource as any).dynamicFilter = {
|
|
1059
|
+
name: [
|
|
1060
|
+
{
|
|
1061
|
+
operation: 'CONTAINS',
|
|
1062
|
+
relation: 'AND',
|
|
1063
|
+
value: 'a',
|
|
1064
|
+
},
|
|
1065
|
+
],
|
|
1066
|
+
};
|
|
1067
|
+
grid.columns[1].isVisible = false;
|
|
1068
|
+
grid.columns[1].width = '120px';
|
|
1069
|
+
|
|
1070
|
+
expect(instance.getCurrentLayout()).toEqual({
|
|
1071
|
+
name: '',
|
|
1072
|
+
gridWidth: 'auto',
|
|
1073
|
+
order: ['name.asc'],
|
|
1074
|
+
filter: { name: 'a' },
|
|
1075
|
+
dynamicFilter: {
|
|
1076
|
+
name: [
|
|
1077
|
+
{
|
|
1078
|
+
operation: 'CONTAINS',
|
|
1079
|
+
relation: 'AND',
|
|
1080
|
+
value: 'a',
|
|
1081
|
+
},
|
|
1082
|
+
],
|
|
1083
|
+
},
|
|
1084
|
+
columns: [
|
|
1085
|
+
{
|
|
1086
|
+
name: 'id',
|
|
1087
|
+
label: '',
|
|
1088
|
+
align: 'left',
|
|
1089
|
+
isVisible: true,
|
|
1090
|
+
minWidth: '',
|
|
1091
|
+
maxWidth: '',
|
|
1092
|
+
width: undefined,
|
|
1093
|
+
fixed: false,
|
|
1094
|
+
grouped: false,
|
|
1095
|
+
groupOpened: false,
|
|
1096
|
+
aggregation: undefined,
|
|
1097
|
+
filterHelperValue: [],
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
name: 'name',
|
|
1101
|
+
label: '',
|
|
1102
|
+
align: 'left',
|
|
1103
|
+
isVisible: false,
|
|
1104
|
+
minWidth: '',
|
|
1105
|
+
maxWidth: '',
|
|
1106
|
+
width: '120px',
|
|
1107
|
+
fixed: false,
|
|
1108
|
+
grouped: false,
|
|
1109
|
+
groupOpened: false,
|
|
1110
|
+
aggregation: undefined,
|
|
1111
|
+
filterHelperValue: [],
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
name: 'salary',
|
|
1115
|
+
label: '',
|
|
1116
|
+
align: 'left',
|
|
1117
|
+
isVisible: true,
|
|
1118
|
+
minWidth: '',
|
|
1119
|
+
maxWidth: '',
|
|
1120
|
+
width: undefined,
|
|
1121
|
+
fixed: false,
|
|
1122
|
+
grouped: false,
|
|
1123
|
+
groupOpened: false,
|
|
1124
|
+
aggregation: undefined,
|
|
1125
|
+
filterHelperValue: [],
|
|
1126
|
+
},
|
|
1127
|
+
],
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
describe('getLayout()', () => {
|
|
1133
|
+
it('should return undefined when named layout does not exist', () => {
|
|
1134
|
+
const instance = new TekGridLayoutOptions({
|
|
1135
|
+
name: 'layout_get_missing',
|
|
1136
|
+
component: 'TekGridLayoutOptions',
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
expect(instance.getLayout('Missing layout')).toBeUndefined();
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
it('should return current layout when called without parameters', () => {
|
|
1143
|
+
const instance = new TekGridLayoutOptions({
|
|
1144
|
+
name: 'layout_get_without_parameters',
|
|
1145
|
+
component: 'TekGridLayoutOptions',
|
|
1146
|
+
});
|
|
1147
|
+
instance.layouts = testLayouts.layouts!;
|
|
1148
|
+
instance.currentLayoutName = 'Name first';
|
|
1149
|
+
|
|
1150
|
+
const layout = instance.getLayout();
|
|
1151
|
+
|
|
1152
|
+
expect(layout).toEqual(testLayouts.layouts!['Name first']);
|
|
1153
|
+
|
|
1154
|
+
layout!.gridWidth = '999px';
|
|
1155
|
+
expect(instance.layouts['Name first'].gridWidth).toBe('544px');
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
it('should return a named layout clone', async () => {
|
|
1159
|
+
const tag = new Tag({
|
|
1160
|
+
name: 'toolbar',
|
|
1161
|
+
component: 'ZdTag',
|
|
1162
|
+
tag: 'span',
|
|
1163
|
+
});
|
|
1164
|
+
const grid = new TekGrid({
|
|
1165
|
+
name: 'grid_get_layout',
|
|
1166
|
+
component: 'TekGrid',
|
|
1167
|
+
columns: [
|
|
1168
|
+
{ name: 'id' },
|
|
1169
|
+
{ name: 'name' },
|
|
1170
|
+
{ name: 'salary' },
|
|
1171
|
+
],
|
|
1172
|
+
});
|
|
1173
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_get', component: 'TekGridLayoutOptions' });
|
|
1174
|
+
instance.parent = tag;
|
|
1175
|
+
tag.parent = grid;
|
|
1176
|
+
|
|
1177
|
+
await instance.onMounted({} as HTMLElement);
|
|
1178
|
+
|
|
1179
|
+
const layout = instance.getLayout('Name first');
|
|
1180
|
+
expect(layout).toEqual(instance.layouts['Name first']);
|
|
1181
|
+
|
|
1182
|
+
layout!.gridWidth = '999px';
|
|
1183
|
+
expect(instance.layouts['Name first'].gridWidth).toBe('544px');
|
|
1184
|
+
});
|
|
1185
|
+
|
|
1186
|
+
it('should return default layout when name is empty', async () => {
|
|
1187
|
+
const tag = new Tag({
|
|
1188
|
+
name: 'toolbar',
|
|
1189
|
+
component: 'ZdTag',
|
|
1190
|
+
tag: 'span',
|
|
1191
|
+
});
|
|
1192
|
+
const grid = new TekGrid({
|
|
1193
|
+
name: 'grid_get_default_layout',
|
|
1194
|
+
component: 'TekGrid',
|
|
1195
|
+
columns: [
|
|
1196
|
+
{ name: 'id' },
|
|
1197
|
+
{ name: 'name' },
|
|
1198
|
+
{ name: 'salary' },
|
|
1199
|
+
],
|
|
1200
|
+
});
|
|
1201
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_get_default', component: 'TekGridLayoutOptions' });
|
|
1202
|
+
instance.parent = tag;
|
|
1203
|
+
tag.parent = grid;
|
|
1204
|
+
|
|
1205
|
+
await instance.onMounted({} as HTMLElement);
|
|
1206
|
+
|
|
1207
|
+
expect(instance.getLayout('')).toEqual({
|
|
1208
|
+
name: '',
|
|
1209
|
+
gridWidth: 'auto',
|
|
1210
|
+
order: [],
|
|
1211
|
+
filter: {},
|
|
1212
|
+
dynamicFilter: {},
|
|
1213
|
+
columns: instance.originalColumnProps,
|
|
1214
|
+
});
|
|
1215
|
+
});
|
|
1216
|
+
});
|
|
1217
|
+
|
|
667
1218
|
describe('updateLayout()', () => {
|
|
668
1219
|
it('should update layout and save', async () => {
|
|
669
1220
|
const tag = new Tag({
|
|
@@ -725,6 +1276,110 @@ describe('LayoutOptions', () => {
|
|
|
725
1276
|
},
|
|
726
1277
|
});
|
|
727
1278
|
});
|
|
1279
|
+
|
|
1280
|
+
it('should update named layout using current grid configuration', async () => {
|
|
1281
|
+
let eventSavedLayouts: ITekGridLayoutInfo = {};
|
|
1282
|
+
const tag = new Tag({
|
|
1283
|
+
name: 'toolbar',
|
|
1284
|
+
component: 'ZdTag',
|
|
1285
|
+
tag: 'span',
|
|
1286
|
+
});
|
|
1287
|
+
const grid = new TekGrid({
|
|
1288
|
+
name: 'grid_update_current_layout',
|
|
1289
|
+
component: 'TekGrid',
|
|
1290
|
+
columns: [
|
|
1291
|
+
{ name: 'id' },
|
|
1292
|
+
{ name: 'name' },
|
|
1293
|
+
{ name: 'salary' },
|
|
1294
|
+
],
|
|
1295
|
+
events: {
|
|
1296
|
+
saveLayouts: ({ layouts }) => { eventSavedLayouts = layouts; },
|
|
1297
|
+
},
|
|
1298
|
+
});
|
|
1299
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_update_current', component: 'TekGridLayoutOptions' });
|
|
1300
|
+
instance.parent = tag;
|
|
1301
|
+
tag.parent = grid;
|
|
1302
|
+
|
|
1303
|
+
await instance.onMounted({} as HTMLElement);
|
|
1304
|
+
|
|
1305
|
+
grid.datasource.order = ['salary.desc'];
|
|
1306
|
+
grid.datasource.filter = { salary: 100 };
|
|
1307
|
+
grid.columns[2].width = '160px';
|
|
1308
|
+
|
|
1309
|
+
instance.updateLayout('Custom layout');
|
|
1310
|
+
|
|
1311
|
+
expect(instance.currentLayoutName).toBe('Custom layout');
|
|
1312
|
+
expect(instance.layouts['Custom layout'].name).toBe('Custom layout');
|
|
1313
|
+
expect(instance.layouts['Custom layout'].gridWidth).toBe('auto');
|
|
1314
|
+
expect(instance.layouts['Custom layout'].order).toEqual(['salary.desc']);
|
|
1315
|
+
expect(instance.layouts['Custom layout'].filter).toEqual({ salary: 100 });
|
|
1316
|
+
expect(instance.layouts['Custom layout'].columns![2].width).toBe('160px');
|
|
1317
|
+
expect(eventSavedLayouts.currentLayoutName).toBe('Custom layout');
|
|
1318
|
+
expect(eventSavedLayouts.layouts!['Custom layout'].filter).toEqual({ salary: 100 });
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
it('should update current selected layout when name is unset', async () => {
|
|
1322
|
+
const tag = new Tag({
|
|
1323
|
+
name: 'toolbar',
|
|
1324
|
+
component: 'ZdTag',
|
|
1325
|
+
tag: 'span',
|
|
1326
|
+
});
|
|
1327
|
+
const grid = new TekGrid({
|
|
1328
|
+
name: 'grid_update_selected_layout',
|
|
1329
|
+
component: 'TekGrid',
|
|
1330
|
+
columns: [
|
|
1331
|
+
{ name: 'id' },
|
|
1332
|
+
{ name: 'name' },
|
|
1333
|
+
{ name: 'salary' },
|
|
1334
|
+
],
|
|
1335
|
+
});
|
|
1336
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_update_selected', component: 'TekGridLayoutOptions' });
|
|
1337
|
+
instance.parent = tag;
|
|
1338
|
+
tag.parent = grid;
|
|
1339
|
+
|
|
1340
|
+
await instance.onMounted({} as HTMLElement);
|
|
1341
|
+
|
|
1342
|
+
instance.currentLayoutName = 'Name first';
|
|
1343
|
+
grid.datasource.filter = { name: 'selected' };
|
|
1344
|
+
|
|
1345
|
+
instance.updateLayout();
|
|
1346
|
+
|
|
1347
|
+
expect(instance.currentLayoutName).toBe('Name first');
|
|
1348
|
+
expect(instance.layouts['Name first'].filter).toEqual({ name: 'selected' });
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
it('should update default layout when name is empty', async () => {
|
|
1352
|
+
const tag = new Tag({
|
|
1353
|
+
name: 'toolbar',
|
|
1354
|
+
component: 'ZdTag',
|
|
1355
|
+
tag: 'span',
|
|
1356
|
+
});
|
|
1357
|
+
const grid = new TekGrid({
|
|
1358
|
+
name: 'grid_update_default_layout',
|
|
1359
|
+
component: 'TekGrid',
|
|
1360
|
+
columns: [
|
|
1361
|
+
{ name: 'id' },
|
|
1362
|
+
{ name: 'name' },
|
|
1363
|
+
{ name: 'salary' },
|
|
1364
|
+
],
|
|
1365
|
+
});
|
|
1366
|
+
const instance = new TekGridLayoutOptions({ name: 'layout_update_default', component: 'TekGridLayoutOptions' });
|
|
1367
|
+
instance.parent = tag;
|
|
1368
|
+
tag.parent = grid;
|
|
1369
|
+
|
|
1370
|
+
await instance.onMounted({} as HTMLElement);
|
|
1371
|
+
|
|
1372
|
+
grid.datasource.order = ['id.desc'];
|
|
1373
|
+
grid.datasource.filter = { id: 1 };
|
|
1374
|
+
instance.layoutEdited = true;
|
|
1375
|
+
|
|
1376
|
+
instance.updateLayout('');
|
|
1377
|
+
|
|
1378
|
+
expect(instance.layouts['']).toBeUndefined();
|
|
1379
|
+
expect(instance.originalDatasourceOrder).toEqual(['id.desc']);
|
|
1380
|
+
expect(instance.originalDatasourceFilter).toEqual({ id: 1 });
|
|
1381
|
+
expect(instance.layoutEdited).toBeFalsy();
|
|
1382
|
+
});
|
|
728
1383
|
});
|
|
729
1384
|
|
|
730
1385
|
describe('discardChanges()', () => {
|