@zeedhi/teknisa-components-common 1.37.0 → 1.41.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 (31) hide show
  1. package/coverage/clover.xml +789 -617
  2. package/coverage/coverage-final.json +30 -27
  3. package/coverage/lcov-report/block-navigation.js +8 -0
  4. package/coverage/lcov-report/index.html +55 -19
  5. package/coverage/lcov-report/sorter.js +26 -0
  6. package/coverage/lcov.info +1506 -1181
  7. package/dist/tek-components-common.esm.js +1808 -1347
  8. package/dist/tek-components-common.umd.js +1808 -1344
  9. package/package.json +2 -2
  10. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +20 -4
  11. package/tests/unit/components/tek-grid/filter-helper.spec.ts +145 -0
  12. package/tests/unit/components/tek-grid/grid.spec.ts +376 -58
  13. package/tests/unit/components/tek-grid/layout_options.spec.ts +58 -0
  14. package/tests/unit/components/tek-loading/Loading.spec.ts +30 -0
  15. package/tests/unit/components/tree-grid/tree-grid.spec.ts +469 -0
  16. package/tests/unit/{components/tek-grid → utils/grid-base}/grid-controller.spec.ts +3 -3
  17. package/types/components/index.d.ts +5 -0
  18. package/types/components/tek-datasource/memory-datasource.d.ts +1 -0
  19. package/types/components/tek-grid/filter-dynamic-values.d.ts +9 -0
  20. package/types/components/tek-grid/filter-helper.d.ts +9 -0
  21. package/types/components/tek-grid/grid-columns-button.d.ts +2 -0
  22. package/types/components/tek-grid/grid.d.ts +12 -19
  23. package/types/components/tek-grid/interfaces.d.ts +15 -1
  24. package/types/components/tek-grid/layout-options.d.ts +3 -2
  25. package/types/components/tek-loading/interfaces.d.ts +6 -0
  26. package/types/components/tek-loading/loading.d.ts +24 -0
  27. package/types/components/tek-tree-grid/interfaces.d.ts +19 -0
  28. package/types/components/tek-tree-grid/tree-grid.d.ts +76 -0
  29. package/types/utils/grid-base/grid-base.d.ts +267 -0
  30. package/types/utils/grid-base/grid-controller.d.ts +20 -0
  31. package/types/utils/index.d.ts +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.37.0",
3
+ "version": "1.41.0",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -28,5 +28,5 @@
28
28
  "peerDependencies": {
29
29
  "@zeedhi/core": "*"
30
30
  },
31
- "gitHead": "2083d86e2b1722ac34c9a7ee71ab7587340ce386"
31
+ "gitHead": "bce3adcbc8986e99a5467d491971d8d26a1a84fd"
32
32
  }
@@ -243,7 +243,7 @@ describe('TekMemoryDatasource', () => {
243
243
 
244
244
  instance.dynamicFilter = {
245
245
  id: [
246
- { operation: 'IN', relation: 'AND', value: '1;2' },
246
+ { operation: 'IN', relation: 'AND', value: ['1', '2'] },
247
247
  ],
248
248
  };
249
249
  await instance.get();
@@ -251,7 +251,7 @@ describe('TekMemoryDatasource', () => {
251
251
 
252
252
  instance.dynamicFilter = {
253
253
  id: [
254
- { operation: 'NOT_IN', relation: 'AND', value: '1;2' },
254
+ { operation: 'NOT_IN', relation: 'AND', value: ['1', '2'] },
255
255
  ],
256
256
  };
257
257
  await instance.get();
@@ -259,7 +259,7 @@ describe('TekMemoryDatasource', () => {
259
259
 
260
260
  instance.dynamicFilter = {
261
261
  id: [
262
- { operation: 'BETWEEN', relation: 'AND', value: '2;5' },
262
+ { operation: 'BETWEEN', relation: 'AND', value: ['2', '5'] },
263
263
  ],
264
264
  };
265
265
  await instance.get();
@@ -267,11 +267,27 @@ describe('TekMemoryDatasource', () => {
267
267
 
268
268
  instance.dynamicFilter = {
269
269
  name: [
270
- { operation: 'BETWEEN', relation: 'AND', value: 'name 2;name 5' },
270
+ { operation: 'BETWEEN', relation: 'AND', value: ['name 2', 'name 5'] },
271
271
  ],
272
272
  };
273
273
  await instance.get();
274
274
  expect(instance.data.length).toBe(4);
275
+
276
+ instance.dynamicFilter = {
277
+ name: [
278
+ { operation: '', relation: 'AND', value: ['1', '2'] },
279
+ ],
280
+ };
281
+ await instance.get();
282
+ expect(instance.data.length).toBe(0);
283
+
284
+ instance.dynamicFilter = {
285
+ name: [
286
+ { operation: '', relation: 'AND', value: '1' },
287
+ ],
288
+ };
289
+ await instance.get();
290
+ expect(instance.data.length).toBe(0);
275
291
  });
276
292
 
277
293
  it('should not retrieve data with wrong operator', async () => {
@@ -0,0 +1,145 @@
1
+ import { Config, dayjs } from '@zeedhi/core';
2
+ import { TekFilterHelper, TekGrid } from '../../../../src';
3
+
4
+ describe('TekFilterHelper', () => {
5
+ describe('getLabel', () => {
6
+ it('should return helper label', () => {
7
+ expect(TekFilterHelper.getLabel('TODAY')).toBe('TEKGRID_HELPERVALUE_TODAY');
8
+ });
9
+ });
10
+
11
+ describe('getValue', () => {
12
+ it('should return helper value', () => {
13
+ const grid = new TekGrid({
14
+ name: 'grid',
15
+ component: 'TekGrid',
16
+ columns: [
17
+ {
18
+ name: 'date',
19
+ componentProps: {
20
+ name: 'date-comp',
21
+ component: 'ZdDate',
22
+ dateFormat: 'YYYY-MM-DD',
23
+ },
24
+ },
25
+ ],
26
+ });
27
+ const today = dayjs().format('YYYY-MM-DD');
28
+ const tomorrow = dayjs().add(1, 'day').format('YYYY-MM-DD');
29
+ const yesterday = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
30
+ const last7Days = [
31
+ dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
32
+ dayjs().format('YYYY-MM-DD'),
33
+ ];
34
+ const next7Days = [
35
+ dayjs().format('YYYY-MM-DD'),
36
+ dayjs().add(7, 'day').format('YYYY-MM-DD'),
37
+ ];
38
+ const currentWeek = [
39
+ dayjs().startOf('week').format('YYYY-MM-DD'),
40
+ dayjs().endOf('week').format('YYYY-MM-DD'),
41
+ ];
42
+ const currentMonth = [
43
+ dayjs().startOf('month').format('YYYY-MM-DD'),
44
+ dayjs().endOf('month').format('YYYY-MM-DD'),
45
+ ];
46
+ const currentYear = [
47
+ dayjs().startOf('year').format('YYYY-MM-DD'),
48
+ dayjs().endOf('year').format('YYYY-MM-DD'),
49
+ ];
50
+ expect(TekFilterHelper.getValue('TODAY', grid.columns[0])).toBe(today);
51
+ expect(TekFilterHelper.getValue('TOMORROW', grid.columns[0])).toBe(tomorrow);
52
+ expect(TekFilterHelper.getValue('YESTERDAY', grid.columns[0])).toBe(yesterday);
53
+ expect(TekFilterHelper.getValue('LAST_7_DAYS', grid.columns[0])).toEqual(last7Days);
54
+ expect(TekFilterHelper.getValue('NEXT_7_DAYS', grid.columns[0])).toEqual(next7Days);
55
+ expect(TekFilterHelper.getValue('CURRENT_WEEK', grid.columns[0])).toEqual(currentWeek);
56
+ expect(TekFilterHelper.getValue('CURRENT_MONTH', grid.columns[0])).toEqual(currentMonth);
57
+ expect(TekFilterHelper.getValue('CURRENT_YEAR', grid.columns[0])).toEqual(currentYear);
58
+ });
59
+
60
+ it('should use default date format if column does not have it', () => {
61
+ const grid = new TekGrid({
62
+ name: 'grid',
63
+ component: 'TekGrid',
64
+ columns: [
65
+ {
66
+ name: 'date',
67
+ },
68
+ ],
69
+ });
70
+ const today = dayjs().format(Config.dateFormat);
71
+ expect(TekFilterHelper.getValue('TODAY', grid.columns[0])).toBe(today);
72
+ });
73
+ });
74
+
75
+ describe('register', () => {
76
+ it('should register new functions', () => {
77
+ const grid = new TekGrid({
78
+ name: 'grid',
79
+ component: 'TekGrid',
80
+ columns: [
81
+ {
82
+ name: 'date',
83
+ componentProps: {
84
+ name: 'date-comp',
85
+ component: 'ZdDate',
86
+ dateFormat: 'YYYY-MM-DD',
87
+ },
88
+ },
89
+ ],
90
+ });
91
+
92
+ TekFilterHelper.register('NEXT_FIFTH_OF_THE_MONTH', 'Next fifth day of the month', () => {
93
+ const today = dayjs();
94
+ if (today.date() <= 5) return today.date(5).toDate();
95
+ return today.add(1, 'month').date(5).toDate();
96
+ });
97
+
98
+ TekFilterHelper.register('NEXT_WEEK', 'Next Week', () => {
99
+ const startOfNextWeek = dayjs().startOf('week').add(1, 'week').toDate();
100
+ const endOfNextWeek = dayjs().endOf('week').add(1, 'week').toDate();
101
+ return [startOfNextWeek, endOfNextWeek];
102
+ });
103
+
104
+ const today = dayjs();
105
+ let nextFifth = '';
106
+ if (today.date() <= 5) {
107
+ nextFifth = today.date(5).format('YYYY-MM-DD');
108
+ } else {
109
+ nextFifth = today.add(1, 'month').date(5).format('YYYY-MM-DD');
110
+ }
111
+
112
+ const nextWeek = [
113
+ dayjs().startOf('week').add(1, 'week').format('YYYY-MM-DD'),
114
+ dayjs().endOf('week').add(1, 'week').format('YYYY-MM-DD'),
115
+ ];
116
+ expect(TekFilterHelper.getValue('NEXT_FIFTH_OF_THE_MONTH', grid.columns[0])).toBe(nextFifth);
117
+ expect(TekFilterHelper.getValue('NEXT_WEEK', grid.columns[0])).toEqual(nextWeek);
118
+ });
119
+ });
120
+
121
+ describe('unregister', () => {
122
+ it('should unregister new functions', () => {
123
+ const grid = new TekGrid({
124
+ name: 'grid',
125
+ component: 'TekGrid',
126
+ columns: [
127
+ {
128
+ name: 'date',
129
+ componentProps: {
130
+ name: 'date-comp',
131
+ component: 'ZdDate',
132
+ dateFormat: 'YYYY-MM-DD',
133
+ },
134
+ },
135
+ ],
136
+ });
137
+
138
+ TekFilterHelper.unregister('NEXT_FIFTH_OF_THE_MONTH');
139
+ TekFilterHelper.unregister('NEXT_WEEK');
140
+
141
+ expect(TekFilterHelper.getValue('NEXT_FIFTH_OF_THE_MONTH', grid.columns[0])).toBe('');
142
+ expect(TekFilterHelper.getValue('NEXT_WEEK', grid.columns[0])).toEqual('');
143
+ });
144
+ });
145
+ });