@zeedhi/teknisa-components-common 3.0.4 → 3.2.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.
Files changed (134) hide show
  1. package/dist/teknisa-components-common.es.js +3536 -0
  2. package/dist/types/components/index.d.ts +2 -0
  3. package/dist/types/components/tek-breadcrumb-header/breadcrumb-header.d.ts +2 -2
  4. package/dist/types/components/tek-breadcrumb-header/interfaces.d.ts +1 -1
  5. package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +1 -21
  6. package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +6 -30
  7. package/dist/types/components/tek-grid/filter-helper.d.ts +2 -2
  8. package/dist/types/components/tek-grid/grid-filter-button.d.ts +1 -0
  9. package/dist/types/components/tek-grid/grouped-data-manager.d.ts +8 -1
  10. package/dist/types/components/tek-grid/grouped-data-navigator.d.ts +12 -0
  11. package/dist/types/components/tek-grid/index.d.ts +1 -1
  12. package/dist/types/components/tek-grid/interfaces.d.ts +8 -1
  13. package/dist/types/components/tek-grid/tek-grid-controller.d.ts +19 -17
  14. package/dist/types/components/tek-grid/tek-grid-data-editor.d.ts +11 -0
  15. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +1 -1
  16. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +8 -1
  17. package/dist/types/components/tek-grid/tek-grid.d.ts +24 -6
  18. package/dist/types/components/tek-loading/interfaces.d.ts +6 -0
  19. package/dist/types/components/tek-loading/loading.d.ts +16 -0
  20. package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +4 -4
  21. package/dist/types/utils/extract-properties/extract-properties.d.ts +1 -0
  22. package/dist/types/utils/index.d.ts +2 -0
  23. package/dist/types/utils/report-filter/report-filter.d.ts +12 -0
  24. package/package.json +32 -12
  25. package/coverage/clover.xml +0 -6
  26. package/coverage/coverage-final.json +0 -1
  27. package/coverage/lcov-report/base.css +0 -224
  28. package/coverage/lcov-report/block-navigation.js +0 -87
  29. package/coverage/lcov-report/favicon.png +0 -0
  30. package/coverage/lcov-report/index.html +0 -101
  31. package/coverage/lcov-report/prettify.css +0 -1
  32. package/coverage/lcov-report/prettify.js +0 -2
  33. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  34. package/coverage/lcov-report/sorter.js +0 -210
  35. package/coverage/lcov.info +0 -0
  36. package/dist/teknisa-components-common.js +0 -3802
  37. package/dist/teknisa-components-common.min.js +0 -3802
  38. package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +0 -14
  39. package/dist/types/error/delete-rows-error.d.ts +0 -6
  40. package/environments.json +0 -14
  41. package/jest.config.js +0 -1
  42. package/src/components/index.ts +0 -101
  43. package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +0 -29
  44. package/src/components/tek-breadcrumb-header/interfaces.ts +0 -7
  45. package/src/components/tek-datasource/index.ts +0 -3
  46. package/src/components/tek-datasource/interfaces.ts +0 -36
  47. package/src/components/tek-datasource/tek-memory-datasource.ts +0 -314
  48. package/src/components/tek-datasource/tek-rest-datasource.ts +0 -224
  49. package/src/components/tek-grid/columns-searcher.ts +0 -22
  50. package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +0 -20
  51. package/src/components/tek-grid/filter-helper.ts +0 -20
  52. package/src/components/tek-grid/grid-filter-button.ts +0 -419
  53. package/src/components/tek-grid/grouped-data-manager.ts +0 -448
  54. package/src/components/tek-grid/grouped-data-selector.ts +0 -40
  55. package/src/components/tek-grid/grouped-view-navigator.ts +0 -84
  56. package/src/components/tek-grid/index.ts +0 -18
  57. package/src/components/tek-grid/interfaces.ts +0 -329
  58. package/src/components/tek-grid/keymap-grouped.ts +0 -20
  59. package/src/components/tek-grid/layout-options.ts +0 -248
  60. package/src/components/tek-grid/tek-grid-column.ts +0 -193
  61. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +0 -28
  62. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +0 -38
  63. package/src/components/tek-grid/tek-grid-controller.ts +0 -140
  64. package/src/components/tek-grid/tek-grid-events.ts +0 -105
  65. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +0 -26
  66. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +0 -3
  67. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +0 -6
  68. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +0 -85
  69. package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +0 -2
  70. package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +0 -365
  71. package/src/components/tek-grid/tek-grid.ts +0 -1118
  72. package/src/components/tek-user-info/TekUserInfoController.ts +0 -87
  73. package/src/components/tek-user-info/interfaces.ts +0 -21
  74. package/src/components/tek-user-info/tek-user-info-list.ts +0 -64
  75. package/src/components/tek-user-info/tek-user-info.ts +0 -337
  76. package/src/error/tek-grid-delete-rows-error.ts +0 -15
  77. package/src/error/teknisa-common-error.ts +0 -8
  78. package/src/utils/config/config.ts +0 -8
  79. package/src/utils/index.ts +0 -3
  80. package/src/utils/is-filled-object/is-filled-object.ts +0 -5
  81. package/src/utils/is-nil.ts +0 -3
  82. package/tests/__helpers__/component-event-helper.ts +0 -5
  83. package/tests/__helpers__/flush-promises-helper.ts +0 -3
  84. package/tests/__helpers__/get-child-helper.ts +0 -27
  85. package/tests/__helpers__/index.ts +0 -3
  86. package/tests/__helpers__/mock-created-helper.ts +0 -12
  87. package/tests/__mocks__/@zeedhi/core/i18n.js +0 -75
  88. package/tests/__mocks__/@zeedhi/core.js +0 -5
  89. package/tests/unit/components/crud/crud-add-button.spec.ts +0 -56
  90. package/tests/unit/components/crud/crud-button.spec.ts +0 -94
  91. package/tests/unit/components/crud/crud-cancel-button.spec.ts +0 -91
  92. package/tests/unit/components/crud/crud-delete-button.spec.ts +0 -122
  93. package/tests/unit/components/crud/crud-form.spec.ts +0 -165
  94. package/tests/unit/components/crud/crud-save-button.spec.ts +0 -118
  95. package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +0 -42
  96. package/tests/unit/components/tek-card-title/CardTitle.spec.ts +0 -34
  97. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +0 -460
  98. package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +0 -362
  99. package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +0 -112
  100. package/tests/unit/components/tek-grid/button-option.spec.ts +0 -49
  101. package/tests/unit/components/tek-grid/columns-searcher.spec.ts +0 -112
  102. package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +0 -90
  103. package/tests/unit/components/tek-grid/filter-helper.spec.ts +0 -52
  104. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +0 -842
  105. package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +0 -593
  106. package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +0 -136
  107. package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +0 -244
  108. package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +0 -20
  109. package/tests/unit/components/tek-grid/layout-options.spec.ts +0 -1020
  110. package/tests/unit/components/tek-grid/multi-option.spec.ts +0 -139
  111. package/tests/unit/components/tek-grid/tek-grid-column.spec.ts +0 -312
  112. package/tests/unit/components/tek-grid/tek-grid-columns-button.spec.ts +0 -228
  113. package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +0 -253
  114. package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +0 -186
  115. package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +0 -34
  116. package/tests/unit/components/tek-grid/tek-grid.spec.ts +0 -895
  117. package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +0 -482
  118. package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +0 -422
  119. package/tests/unit/components/tek-image/Image.spec.ts +0 -67
  120. package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +0 -37
  121. package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +0 -200
  122. package/tests/unit/components/tek-loading/Loading.spec.ts +0 -30
  123. package/tests/unit/components/tek-notifications/notifications.spec.ts +0 -201
  124. package/tests/unit/components/tek-product-card/product-card.spec.ts +0 -61
  125. package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +0 -220
  126. package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +0 -86
  127. package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +0 -430
  128. package/tests/unit/components/tree-grid/tree-grid.spec.ts +0 -776
  129. package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +0 -44
  130. package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +0 -135
  131. package/tests/unit/utils/grid-base/grid-controller.spec.ts +0 -174
  132. package/tests/unit/utils/report-filter/report-filter.spec.ts +0 -66
  133. package/tsconfig.build.json +0 -7
  134. package/tsconfig.eslint.json +0 -9
@@ -1,1020 +0,0 @@
1
- import { Grid, Tag } from '@zeedhi/common';
2
- import { Config, Http, Loader, SimpleControllerBuilder } from '@zeedhi/core';
3
- import {
4
- ITekConfig,
5
- ITekGridLayoutInfo,
6
- TekGrid,
7
- TekGridLayoutOptions,
8
- ITekGridProps,
9
- } from '../../../../src';
10
- import { flushPromises } from '../../__helpers__';
11
-
12
- let savedLayouts: string = '';
13
- const testLayouts: ITekGridLayoutInfo = {
14
- layouts: {
15
- 'Name first': {
16
- name: 'Name first',
17
- gridWidth: '544px',
18
- columns: [
19
- {
20
- name: 'id',
21
- width: '34px',
22
- isVisible: true,
23
- grouped: false,
24
- },
25
- {
26
- name: 'name',
27
- width: '107px',
28
- isVisible: true,
29
- grouped: false,
30
- },
31
- {
32
- name: 'salary',
33
- width: '114px',
34
- isVisible: true,
35
- grouped: false,
36
- },
37
- ],
38
- },
39
- },
40
- };
41
-
42
- const setupInstance = (props: Partial<ITekGridProps> = {}) => {
43
- const instance = new TekGrid({
44
- name: 'Grid',
45
- component: 'TekGrid',
46
- columns: [
47
- { name: 'first' },
48
- { name: 'second' },
49
- { name: 'third' },
50
- ],
51
- datasource: {
52
- limit: 2,
53
- page: 1,
54
- data: [
55
- { id: 1 },
56
- { id: 2 },
57
- { id: 3 },
58
- { id: 4 },
59
- { id: 5 },
60
- { id: 6 },
61
- { id: 7 },
62
- ],
63
- },
64
- ...props,
65
- });
66
- const elem = document.createElement('DIV');
67
- instance.onCreated();
68
- instance.onMounted(elem);
69
-
70
- return instance;
71
- };
72
-
73
- describe('LayoutOptions', () => {
74
- beforeAll(() => {
75
- Loader.setBuilder(new SimpleControllerBuilder());
76
- });
77
-
78
- describe('constructor()', () => {
79
- it('should create layout options object', () => {
80
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
81
-
82
- expect(instance.currentLayoutName).toBe('');
83
- expect(instance.layouts).toEqual({});
84
- expect(instance.layoutNames).toEqual([]);
85
- expect(instance.originalColumnProps).toEqual([]);
86
- });
87
- });
88
-
89
- describe('mounted()', () => {
90
- it('should store the original column props of a TekGrid', () => {
91
- const tag = new Tag({
92
- name: 'toolbar',
93
- component: 'ZdTag',
94
- tag: 'span',
95
- });
96
- const grid = setupInstance({
97
- name: 'grid',
98
- component: 'TekGrid',
99
- columns: [
100
- { name: 'id' },
101
- { name: 'name' },
102
- { name: 'salary' },
103
- {
104
- name: 'date1',
105
- filterProps: {
106
- name: 'date1-filter',
107
- helperValue: 'TODAY',
108
- },
109
- },
110
- {
111
- name: 'date2',
112
- filterProps: [
113
- {
114
- name: 'date2-filter1',
115
- helperValue: 'TODAY',
116
- },
117
- {
118
- name: 'date2-filter2',
119
- helperValue: 'TOMORROW',
120
- },
121
- ],
122
- },
123
- ],
124
- });
125
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
126
- instance.parent = tag;
127
- tag.parent = grid;
128
-
129
- instance.onMounted({} as HTMLElement);
130
-
131
- expect(instance.originalDatasourceDynamicFilter).toEqual({});
132
- expect(instance.originalDatasourceFilter).toEqual({});
133
- expect(instance.originalColumnProps).toEqual([
134
- {
135
- name: 'id',
136
- isVisible: true,
137
- fixed: false,
138
- grouped: false,
139
- minWidth: undefined,
140
- maxWidth: undefined,
141
- aggregation: undefined,
142
- align: 'left',
143
- groupOpened: false,
144
- label: '',
145
- filterHelperValue: [],
146
- width: undefined,
147
- },
148
- {
149
- name: 'name',
150
- isVisible: true,
151
- fixed: false,
152
- grouped: false,
153
- minWidth: undefined,
154
- maxWidth: undefined,
155
- aggregation: undefined,
156
- align: 'left',
157
- groupOpened: false,
158
- label: '',
159
- filterHelperValue: [],
160
- width: undefined,
161
- },
162
- {
163
- name: 'salary',
164
- isVisible: true,
165
- fixed: false,
166
- grouped: false,
167
- minWidth: undefined,
168
- maxWidth: undefined,
169
- aggregation: undefined,
170
- align: 'left',
171
- groupOpened: false,
172
- label: '',
173
- filterHelperValue: [],
174
- width: undefined,
175
- },
176
- {
177
- name: 'date1',
178
- isVisible: true,
179
- fixed: false,
180
- grouped: false,
181
- minWidth: undefined,
182
- maxWidth: undefined,
183
- aggregation: undefined,
184
- align: 'left',
185
- groupOpened: false,
186
- label: '',
187
- filterHelperValue: 'TODAY',
188
- width: undefined
189
- },
190
- {
191
- name: 'date2',
192
- isVisible: true,
193
- fixed: false,
194
- grouped: false,
195
- minWidth: undefined,
196
- maxWidth: undefined,
197
- aggregation: undefined,
198
- align: 'left',
199
- groupOpened: false,
200
- label: '',
201
- filterHelperValue: ['TODAY', 'TOMORROW'],
202
- width: undefined,
203
- },
204
- ]);
205
- });
206
-
207
- it('should store the original column props of a normal Grid', () => {
208
- const grid = new Grid({
209
- name: 'grid',
210
- component: 'Grid',
211
- columns: [
212
- { name: 'id', maxWidth: '200px', minWidth: '100px' },
213
- { name: 'name' },
214
- { name: 'salary' },
215
- ],
216
- });
217
- grid.onCreated();
218
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
219
- instance.parent = grid;
220
-
221
- instance.onMounted({} as HTMLElement);
222
-
223
- expect(instance.originalColumnProps).toEqual([
224
- {
225
- name: 'id',
226
- isVisible: true,
227
- maxWidth: '200px',
228
- minWidth: '100px',
229
- aggregation: undefined,
230
- align: 'left',
231
- groupOpened: undefined,
232
- label: '',
233
- filterHelperValue: '',
234
- fixed: false,
235
- grouped: undefined,
236
- },
237
- {
238
- name: 'name',
239
- isVisible: true,
240
- minWidth: undefined,
241
- maxWidth: undefined,
242
- aggregation: undefined,
243
- align: 'left',
244
- groupOpened: undefined,
245
- label: '',
246
- filterHelperValue: '',
247
- fixed: false,
248
- grouped: undefined,
249
- },
250
- {
251
- name: 'salary',
252
- isVisible: true,
253
- minWidth: undefined,
254
- maxWidth: undefined,
255
- aggregation: undefined,
256
- align: 'left',
257
- groupOpened: undefined,
258
- label: '',
259
- filterHelperValue: '',
260
- fixed: false,
261
- grouped: undefined,
262
- },
263
- ]);
264
- });
265
- });
266
-
267
- describe('loadLayouts()', () => {
268
- it('should load using event', async () => {
269
- const layouts: ITekGridLayoutInfo = {
270
- currentLayoutName: 'Name first',
271
- layouts: {
272
- 'Name first': {
273
- name: 'Name first',
274
- gridWidth: '544px',
275
- columns: [
276
- {
277
- name: 'id',
278
- width: '34px',
279
- isVisible: true,
280
- grouped: false,
281
- },
282
- {
283
- name: 'name',
284
- width: '107px',
285
- isVisible: true,
286
- grouped: false,
287
- },
288
- {
289
- name: 'salary',
290
- width: '114px',
291
- isVisible: true,
292
- grouped: false,
293
- },
294
- ],
295
- },
296
- },
297
- };
298
-
299
- const tag = new Tag({
300
- name: 'toolbar',
301
- component: 'ZdTag',
302
- tag: 'span',
303
- });
304
- const grid = setupInstance({
305
- name: 'grid',
306
- component: 'TekGrid',
307
- columns: [
308
- { name: 'id' },
309
- { name: 'name' },
310
- { name: 'salary' },
311
- ],
312
- events: {
313
- loadLayouts: async () => layouts,
314
- },
315
- });
316
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
317
- instance.parent = tag;
318
- tag.parent = grid;
319
-
320
- await instance.onMounted({} as HTMLElement);
321
-
322
- expect(instance.currentLayoutName).toBe('Name first');
323
- expect(instance.layoutNames).toEqual(['Name first']);
324
- expect(instance.layouts).toEqual(layouts.layouts);
325
- });
326
-
327
- it('should load using localStorage', async () => {
328
- const tag = new Tag({
329
- name: 'toolbar',
330
- component: 'ZdTag',
331
- tag: 'span',
332
- });
333
- const grid = setupInstance({
334
- name: 'grid',
335
- component: 'TekGrid',
336
- columns: [
337
- { name: 'id' },
338
- { name: 'name' },
339
- { name: 'salary' },
340
- ],
341
- });
342
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
343
- instance.parent = tag;
344
- tag.parent = grid;
345
-
346
- const localStorageMock = (function () { // eslint-disable-line func-names
347
- return {
348
- getItem(): string {
349
- return JSON.stringify(testLayouts);
350
- },
351
- setItem(_name: string, value: string) {
352
- savedLayouts = value;
353
- },
354
- };
355
- }());
356
-
357
- Object.defineProperty(window, 'localStorage', {
358
- value: localStorageMock,
359
- });
360
-
361
- await instance.onMounted({} as HTMLElement);
362
-
363
- expect(instance.currentLayoutName).toBe('');
364
- expect(instance.layoutNames).toEqual(['Name first']);
365
- expect(instance.layouts).toEqual(testLayouts.layouts);
366
- });
367
- });
368
-
369
- describe('newLayout()', () => {
370
- it('should add new layout', () => {
371
- const newLayout = {
372
- name: 'Name first',
373
- gridWidth: '544px',
374
- columns: [
375
- {
376
- name: 'id',
377
- width: '34px',
378
- isVisible: true,
379
- grouped: false,
380
- },
381
- {
382
- name: 'name',
383
- width: '107px',
384
- isVisible: true,
385
- grouped: false,
386
- },
387
- {
388
- name: 'salary',
389
- width: '114px',
390
- isVisible: true,
391
- grouped: false,
392
- },
393
- ],
394
- };
395
- const tag = new Tag({
396
- name: 'toolbar',
397
- component: 'ZdTag',
398
- tag: 'span',
399
- });
400
- const grid = setupInstance({
401
- name: 'grid',
402
- component: 'TekGrid',
403
- columns: [
404
- { name: 'id' },
405
- { name: 'name' },
406
- { name: 'salary' },
407
- ],
408
- });
409
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
410
- instance.parent = tag;
411
- tag.parent = grid;
412
-
413
- instance.onMounted({} as HTMLElement);
414
-
415
- instance.newLayout(newLayout);
416
-
417
- expect(instance.currentLayoutName).toBe('Name first');
418
- expect(instance.layoutNames).toEqual(['Name first']);
419
- expect(instance.layouts).toEqual({ 'Name first': newLayout });
420
- expect(savedLayouts).toBe(JSON.stringify({
421
- currentLayoutName: 'Name first',
422
- layouts: { 'Name first': newLayout },
423
- }));
424
- });
425
- });
426
-
427
- describe('addLayout()', () => {
428
- it('should add new layout and not change current layout', () => {
429
- const newLayout = {
430
- name: 'Name first',
431
- gridWidth: '544px',
432
- columns: [
433
- {
434
- name: 'id',
435
- width: '34px',
436
- isVisible: true,
437
- grouped: false,
438
- },
439
- {
440
- name: 'name',
441
- width: '107px',
442
- isVisible: true,
443
- grouped: false,
444
- },
445
- {
446
- name: 'salary',
447
- width: '114px',
448
- isVisible: true,
449
- grouped: false,
450
- },
451
- ],
452
- };
453
- const tag = new Tag({
454
- name: 'toolbar',
455
- component: 'ZdTag',
456
- tag: 'span',
457
- });
458
- const grid = setupInstance({
459
- name: 'grid',
460
- component: 'TekGrid',
461
- columns: [
462
- { name: 'id' },
463
- { name: 'name' },
464
- { name: 'salary' },
465
- ],
466
- });
467
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
468
- instance.parent = tag;
469
- tag.parent = grid;
470
-
471
- instance.onMounted({} as HTMLElement);
472
-
473
- instance.addLayout(newLayout);
474
-
475
- expect(instance.currentLayoutName).toBe('');
476
- expect(instance.layoutNames).toEqual(['Name first']);
477
- expect(instance.layouts).toEqual({ 'Name first': newLayout });
478
- expect(savedLayouts).toBe(JSON.stringify({
479
- currentLayoutName: '',
480
- layouts: { 'Name first': newLayout },
481
- }));
482
- });
483
- });
484
-
485
- describe('applyLayout()', () => {
486
- it('should change Layout and save layout', async () => {
487
- let viewCalled = false;
488
- const tag = new Tag({
489
- name: 'toolbar',
490
- component: 'ZdTag',
491
- tag: 'span',
492
- });
493
- const grid = setupInstance({
494
- name: 'grid',
495
- component: 'TekGrid',
496
- columns: [
497
- { name: 'id' },
498
- { name: 'name' },
499
- { name: 'salary' },
500
- ],
501
- });
502
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
503
- instance.viewApplyLayout = () => { viewCalled = true; };
504
- instance.parent = tag;
505
- tag.parent = grid;
506
-
507
- await instance.onMounted({} as HTMLElement);
508
-
509
- expect(instance.currentLayoutName).toBe('');
510
- instance.applyLayout('Name first');
511
- expect(instance.currentLayoutName).toBe('Name first');
512
- expect(viewCalled).toBeTruthy();
513
- });
514
-
515
- it('should change Layout and save layout using event', async () => {
516
- let eventSavedLayouts: ITekGridLayoutInfo = {};
517
- const tag = new Tag({
518
- name: 'toolbar',
519
- component: 'ZdTag',
520
- tag: 'span',
521
- });
522
- const grid = setupInstance({
523
- name: 'grid',
524
- component: 'TekGrid',
525
- columns: [
526
- { name: 'id' },
527
- { name: 'name' },
528
- { name: 'salary' },
529
- ],
530
- events: {
531
- saveLayouts: ({ layouts }) => { eventSavedLayouts = layouts; },
532
- },
533
- });
534
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
535
- instance.parent = tag;
536
- tag.parent = grid;
537
-
538
- await instance.onMounted({} as HTMLElement);
539
-
540
- expect(instance.currentLayoutName).toBe('');
541
- instance.applyLayout('Name first');
542
- expect(instance.currentLayoutName).toBe('Name first');
543
- expect(eventSavedLayouts.currentLayoutName).toBe('Name first');
544
- });
545
- });
546
-
547
- describe('deleteLayout()', () => {
548
- it('should delete layout and save', async () => {
549
- const tag = new Tag({
550
- name: 'toolbar',
551
- component: 'ZdTag',
552
- tag: 'span',
553
- });
554
- const grid = setupInstance({
555
- name: 'grid',
556
- component: 'TekGrid',
557
- columns: [
558
- { name: 'id' },
559
- { name: 'name' },
560
- { name: 'salary' },
561
- ],
562
- });
563
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
564
- instance.parent = tag;
565
- tag.parent = grid;
566
-
567
- await instance.onMounted({} as HTMLElement);
568
-
569
- instance.applyLayout('Name first');
570
- expect(instance.currentLayoutName).toBe('Name first');
571
- expect(instance.layoutNames).toEqual(['Name first']);
572
- instance.deleteLayout('Name first');
573
- expect(instance.currentLayoutName).toBe('');
574
- expect(instance.layoutNames).toEqual([]);
575
- });
576
-
577
- it('should delete layout without applying layout', async () => {
578
- const tag = new Tag({
579
- name: 'toolbar',
580
- component: 'ZdTag',
581
- tag: 'span',
582
- });
583
- const grid = setupInstance({
584
- name: 'grid',
585
- component: 'TekGrid',
586
- columns: [
587
- { name: 'id' },
588
- { name: 'name' },
589
- { name: 'salary' },
590
- ],
591
- });
592
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
593
- instance.parent = tag;
594
- tag.parent = grid;
595
-
596
- await instance.onMounted({} as HTMLElement);
597
-
598
- expect(instance.currentLayoutName).toBe('');
599
- expect(instance.layoutNames).toEqual(['Name first']);
600
- instance.deleteLayout('Name first');
601
- expect(instance.currentLayoutName).toBe('');
602
- expect(instance.layoutNames).toEqual([]);
603
- });
604
- });
605
-
606
- describe('updateLayout()', () => {
607
- it('should update layout and save', async () => {
608
- const tag = new Tag({
609
- name: 'toolbar',
610
- component: 'ZdTag',
611
- tag: 'span',
612
- });
613
- const grid = setupInstance({
614
- name: 'grid',
615
- component: 'TekGrid',
616
- columns: [
617
- { name: 'id' },
618
- { name: 'name' },
619
- { name: 'salary' },
620
- ],
621
- });
622
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
623
- instance.parent = tag;
624
- tag.parent = grid;
625
-
626
- await instance.onMounted({} as HTMLElement);
627
-
628
- instance.updateLayout('Name first', {
629
- name: 'Name first',
630
- gridWidth: '500px',
631
- filter: {
632
- name: 'a',
633
- },
634
- dynamicFilter: {
635
- name: [
636
- {
637
- operation: 'CONTAINS',
638
- relation: 'AND',
639
- value: 'a',
640
- },
641
- ],
642
- },
643
- });
644
-
645
- expect(instance.currentLayoutName).toBe('Name first');
646
- expect(instance.layoutNames).toEqual(['Name first']);
647
- expect(instance.layouts).toEqual({
648
- 'Name first': {
649
- name: 'Name first',
650
- gridWidth: '500px',
651
- columns: instance.originalColumnProps,
652
- filter: {
653
- name: 'a',
654
- },
655
- dynamicFilter: {
656
- name: [
657
- {
658
- operation: 'CONTAINS',
659
- relation: 'AND',
660
- value: 'a',
661
- },
662
- ],
663
- },
664
- },
665
- });
666
- });
667
- });
668
-
669
- describe('discardChanges()', () => {
670
- it('should discard changes and restore layout', async () => {
671
- const layouts: ITekGridLayoutInfo = {
672
- currentLayoutName: 'Name first',
673
- layouts: {
674
- 'Name first': {
675
- name: 'Name first',
676
- gridWidth: '544px',
677
- columns: [
678
- {
679
- name: 'id',
680
- width: '34px',
681
- isVisible: true,
682
- grouped: false,
683
- },
684
- {
685
- name: 'name',
686
- width: '107px',
687
- isVisible: true,
688
- grouped: false,
689
- },
690
- {
691
- name: 'salary',
692
- width: '114px',
693
- isVisible: true,
694
- grouped: false,
695
- },
696
- ],
697
- },
698
- },
699
- };
700
-
701
- let viewCalled = false;
702
-
703
- const tag = new Tag({
704
- name: 'toolbar',
705
- component: 'ZdTag',
706
- tag: 'span',
707
- });
708
- const grid = setupInstance({
709
- name: 'grid',
710
- component: 'TekGrid',
711
- columns: [
712
- { name: 'id' },
713
- { name: 'name' },
714
- { name: 'salary' },
715
- ],
716
- events: {
717
- loadLayouts: async () => layouts,
718
- },
719
- });
720
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
721
- instance.viewApplyLayout = () => { viewCalled = true; };
722
- instance.parent = tag;
723
- tag.parent = grid;
724
-
725
- await instance.onMounted({} as HTMLElement);
726
- instance.applyLayout('Name first');
727
- expect(viewCalled).toBeTruthy();
728
- expect(instance.layoutEdited).toBeFalsy();
729
- expect(instance.currentLayoutName).toBe('Name first');
730
-
731
- instance.layoutEdited = true;
732
-
733
- instance.discardChanges();
734
- expect(instance.layoutEdited).toBeFalsy();
735
- });
736
- });
737
-
738
- describe('updateDefaultLayout()', () => {
739
- it('should update default layout', async () => {
740
- const tag = new Tag({
741
- name: 'toolbar',
742
- component: 'ZdTag',
743
- tag: 'span',
744
- });
745
- const grid = setupInstance({
746
- name: 'grid',
747
- component: 'TekGrid',
748
- columns: [
749
- { name: 'id' },
750
- { name: 'name' },
751
- { name: 'salary' },
752
- ],
753
- });
754
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
755
- instance.parent = tag;
756
- tag.parent = grid;
757
-
758
- await instance.onMounted({} as HTMLElement);
759
-
760
- expect(instance.originalDatasourceOrder).toEqual([]);
761
- expect(instance.originalDatasourceFilter).toEqual({});
762
- expect(instance.originalDatasourceDynamicFilter).toEqual({});
763
- expect(instance.originalColumnProps.map((item) => item.name)).toEqual(['id', 'name', 'salary']);
764
-
765
- const newDynamicFilter = {
766
- name: [
767
- {
768
- operation: 'CONTAINS',
769
- relation: 'AND',
770
- value: 'a',
771
- },
772
- ],
773
- };
774
-
775
- instance.updateDefaultLayout({
776
- name: '',
777
- columns: [
778
- { name: 'name' },
779
- { name: 'id' },
780
- { name: 'hire_date' },
781
- ],
782
- order: ['name.asc'],
783
- filter: {
784
- name: 'a',
785
- },
786
- dynamicFilter: newDynamicFilter,
787
- });
788
-
789
- expect(instance.originalDatasourceOrder).toEqual(['name.asc']);
790
- expect(instance.originalDatasourceFilter).toEqual({ name: 'a' });
791
- expect(instance.originalDatasourceDynamicFilter).toEqual(newDynamicFilter);
792
- expect(instance.originalColumnProps.map((item) => item.name)).toEqual(['name', 'id', 'hire_date', 'salary']);
793
- });
794
-
795
- it('should update default layout with some values', async () => {
796
- const tag = new Tag({
797
- name: 'toolbar',
798
- component: 'ZdTag',
799
- tag: 'span',
800
- });
801
- const grid = setupInstance({
802
- name: 'grid',
803
- component: 'TekGrid',
804
- columns: [
805
- { name: 'id' },
806
- { name: 'name' },
807
- { name: 'salary' },
808
- ],
809
- });
810
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
811
- instance.parent = tag;
812
- tag.parent = grid;
813
-
814
- await instance.onMounted({} as HTMLElement);
815
-
816
- const applyLayoutSpy = jest.spyOn(instance, 'applyLayout');
817
-
818
- expect(instance.originalColumnProps.map((item) => item.name)).toEqual(['id', 'name', 'salary']);
819
-
820
- instance.updateDefaultLayout({
821
- name: 'default',
822
- columns: [
823
- { name: 'name' },
824
- { name: 'id' },
825
- { name: 'hire_date' },
826
- ],
827
- });
828
-
829
- expect(instance.originalColumnProps.map((item) => item.name)).toEqual(['name', 'id', 'hire_date', 'salary']);
830
- expect(applyLayoutSpy).toBeCalled();
831
- });
832
- });
833
-
834
- describe('loadLayouts()/saveLayouts()', () => {
835
- it('should load layouts using config endpoint', async () => {
836
- (Config as ITekConfig).loadGridLayoutsEndPoint = '/loadLayoutsRoute';
837
- const tag = new Tag({
838
- name: 'toolbar',
839
- component: 'ZdTag',
840
- tag: 'span',
841
- });
842
- const grid = setupInstance({
843
- name: 'grid',
844
- component: 'TekGrid',
845
- columns: [
846
- { name: 'id' },
847
- { name: 'name' },
848
- { name: 'salary' },
849
- ],
850
- });
851
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
852
- instance.parent = tag;
853
- tag.parent = grid;
854
-
855
- const layouts = {
856
- currentLayoutName: 'layout-test',
857
- layouts: {
858
- 'layout-test': {
859
- name: 'layout-test',
860
- gridWidth: '100px',
861
- columns: [
862
- {
863
- name: 'id',
864
- label: 'ID',
865
- },
866
- ],
867
- },
868
- },
869
- };
870
-
871
- const spy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({ data: { data: { layouts } } }));
872
-
873
- await instance.onMounted({} as HTMLElement);
874
- await grid.onMounted({} as HTMLElement);
875
-
876
- await flushPromises();
877
- expect(spy).toHaveBeenCalled();
878
- expect(instance.layouts).toEqual({
879
- 'layout-test': {
880
- name: 'layout-test',
881
- gridWidth: '100px',
882
- columns: [
883
- {
884
- name: 'id',
885
- label: 'ID',
886
- },
887
- ],
888
- },
889
- });
890
- spy.mockReset();
891
- (Config as ITekConfig).loadGridLayoutsEndPoint = '';
892
- });
893
-
894
- it('should load layouts using config endpoint with array data', async () => {
895
- (Config as ITekConfig).loadGridLayoutsEndPoint = '/loadLayoutsRoute';
896
- const tag = new Tag({
897
- name: 'toolbar',
898
- component: 'ZdTag',
899
- tag: 'span',
900
- });
901
- const grid = setupInstance({
902
- name: 'grid',
903
- component: 'TekGrid',
904
- columns: [
905
- { name: 'id' },
906
- { name: 'name' },
907
- { name: 'salary' },
908
- ],
909
- });
910
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
911
- instance.parent = tag;
912
- tag.parent = grid;
913
-
914
- const layouts = {
915
- currentLayoutName: 'layout-test',
916
- layouts: {
917
- 'layout-test': {
918
- name: 'layout-test',
919
- gridWidth: '100px',
920
- columns: [
921
- {
922
- name: 'id',
923
- label: 'ID',
924
- },
925
- ],
926
- },
927
- },
928
- };
929
-
930
- const spy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({ data: { data: [{ layouts }] } }));
931
-
932
- await instance.onMounted({} as HTMLElement);
933
- await grid.onMounted({} as HTMLElement);
934
-
935
- await flushPromises();
936
- expect(spy).toHaveBeenCalled();
937
- expect(instance.layouts).toEqual({
938
- 'layout-test': {
939
- name: 'layout-test',
940
- gridWidth: '100px',
941
- columns: [
942
- {
943
- name: 'id',
944
- label: 'ID',
945
- },
946
- ],
947
- },
948
- });
949
- spy.mockReset();
950
- (Config as ITekConfig).loadGridLayoutsEndPoint = '';
951
- });
952
-
953
- it('should load layouts using config endpoint with empty data', async () => {
954
- (Config as ITekConfig).loadGridLayoutsEndPoint = '/loadLayoutsRoute';
955
- const tag = new Tag({
956
- name: 'toolbar',
957
- component: 'ZdTag',
958
- tag: 'span',
959
- });
960
- const grid = setupInstance({
961
- name: 'grid',
962
- component: 'TekGrid',
963
- columns: [
964
- { name: 'id' },
965
- { name: 'name' },
966
- { name: 'salary' },
967
- ],
968
- });
969
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
970
- instance.parent = tag;
971
- tag.parent = grid;
972
-
973
- const spy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({ data: { data: '' } }));
974
-
975
- await instance.onMounted({} as HTMLElement);
976
- grid.onMounted({} as HTMLElement);
977
-
978
- await flushPromises();
979
- expect(spy).toHaveBeenCalled();
980
- expect(instance.layouts).toEqual({});
981
- spy.mockReset();
982
- (Config as ITekConfig).loadGridLayoutsEndPoint = '';
983
- });
984
-
985
- it('should save layout using endpoint', async () => {
986
- (Config as ITekConfig).saveGridLayoutsEndPoint = '/saveLayoutsRoute';
987
- const tag = new Tag({
988
- name: 'toolbar',
989
- component: 'ZdTag',
990
- tag: 'span',
991
- });
992
- const grid = setupInstance({
993
- name: 'grid',
994
- component: 'TekGrid',
995
- columns: [
996
- { name: 'id' },
997
- { name: 'name' },
998
- { name: 'salary' },
999
- ],
1000
- });
1001
- const layouts = {
1002
- name: 'layout-test',
1003
- gridWidth: '100px',
1004
- columns: [
1005
- {
1006
- name: 'id',
1007
- label: 'ID',
1008
- },
1009
- ],
1010
- };
1011
- const instance = new TekGridLayoutOptions({ name: 'layout', component: 'TekGridLayoutOptions' });
1012
- instance.grid = grid;
1013
- instance.parent = tag;
1014
- tag.parent = grid;
1015
- instance.newLayout(layouts);
1016
- expect(instance.currentLayoutName).toBe('layout-test');
1017
- (Config as ITekConfig).saveGridLayoutsEndPoint = '';
1018
- });
1019
- });
1020
- });