@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,362 +0,0 @@
1
- import {
2
- type IConfig, Config, Router, Http, URL, type IDictionary, init,
3
- } from '@zeedhi/core';
4
- import {
5
- TekRestDatasource, type ITekRestDatasource,
6
- } from '../../../../src';
7
-
8
- describe('TekRestDatasource', () => {
9
- init({
10
- controllers: {
11
- AppController: class AppController {
12
- public value = '1';
13
-
14
- public join: string[] | number[] = ['1', '2'];
15
- },
16
- },
17
- });
18
- let datasource: ITekRestDatasource;
19
- let router: any;
20
- const config: IConfig = {
21
- endPoint: 'http://localhost:9000/',
22
- metadataEndPoint: 'http://localhost:9000/metadata/',
23
- title: 'Samples',
24
- mode: 'production',
25
- datasourceLimit: 10,
26
- };
27
- let httpSpy: jest.SpyInstance;
28
-
29
- beforeEach(() => {
30
- datasource = {
31
- uniqueKey: 'id',
32
- route: '/zeedhi',
33
- lazyLoad: true,
34
- };
35
- Config.set(config);
36
- router = {
37
- push: () => jest.fn,
38
- replace: (route: any) => {
39
- window.history.replaceState(null, '', `${window.location.pathname}?${URL.getFormattedQueryString(route.query)}`);
40
- },
41
- back: () => jest.fn,
42
- getCurrentRoute: () => ({
43
- path: '',
44
- hash: '',
45
- query: {},
46
- params: {},
47
- fullPath: '',
48
- }),
49
- getPath: () => '',
50
- getHash: () => '',
51
- getQuery: () => ({}),
52
- getParams: () => ({}),
53
- getFullPath: () => '',
54
- };
55
- Router.setInstance(router);
56
- httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
57
- data: {
58
- data: [
59
- { name: '1', id: 1 }, { name: '2', id: 2 }, { name: '3', id: 3 },
60
- { name: '4', id: 4 }, { name: '5', id: 5 }, { name: '6', id: 6 },
61
- ],
62
- pagination: {
63
- page: 1,
64
- total: 6,
65
- limit: 15,
66
- },
67
- },
68
- }));
69
- });
70
-
71
- afterEach(() => {
72
- httpSpy.mockClear();
73
- });
74
-
75
- describe('constuctor()', () => {
76
- it('should assign all properties', async () => {
77
- const flushPromises = () => new Promise(setImmediate);
78
- const instance = new TekRestDatasource({
79
- ...datasource,
80
- dynamicFilter: {
81
- name: { operation: 'EQUALS', relation: 'AND', value: '1' },
82
- },
83
- searchJoin: { col1: ['1', '2'], col2: [2], col3: [] },
84
- });
85
- await flushPromises();
86
-
87
- expect(instance.route).toBe('/zeedhi');
88
- expect(instance.lazyLoad).toBeTruthy();
89
- expect(instance.dynamicFilter).toEqual({ name: { operation: 'EQUALS', relation: 'AND', value: '1' } });
90
- expect(instance.data.length).toBe(0);
91
- expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
92
- });
93
-
94
- it('should assign all properties', async () => {
95
- const flushPromises = () => new Promise(setImmediate);
96
- const instance = new TekRestDatasource({
97
- ...datasource,
98
- dynamicFilter: {
99
- name: { operation: 'EQUALS', relation: 'AND', value: '{{AppController.value}}' },
100
- },
101
- searchJoin: { col1: '{{AppController.join}}' as any, col2: [2], col3: [] },
102
- });
103
- await flushPromises();
104
-
105
- expect(instance.route).toBe('/zeedhi');
106
- expect(instance.lazyLoad).toBeTruthy();
107
- expect(instance.dynamicFilter).toEqual({ name: { operation: 'EQUALS', relation: 'AND', value: '1' } });
108
- expect(instance.data.length).toBe(0);
109
- expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
110
- });
111
-
112
- it('should create without lazyLoad', async () => {
113
- const flushPromises = () => new Promise(setImmediate);
114
- const instance = new TekRestDatasource({
115
- ...datasource,
116
- lazyLoad: false,
117
- dynamicFilter: {
118
- name: { operation: 'EQUALS', relation: 'AND', value: '1' },
119
- },
120
- });
121
- await flushPromises();
122
-
123
- expect(instance.data.length).toBe(6);
124
- });
125
-
126
- it('should set values from url', () => {
127
- router.getFullPath = () => 'localhost/?page=2&limit=10&order=id.asc&search=2&id=1&filter=applied';
128
- datasource.watchUrl = true;
129
- const instance = new TekRestDatasource(datasource);
130
- expect(instance.filter).toEqual({ id: '1' });
131
- expect(instance.limit).toBe(10);
132
- expect(instance.order).toEqual(['id.asc']);
133
- expect(instance.page).toBe(2);
134
- expect(instance.search).toBe('2');
135
- });
136
-
137
- it('should set dynamicFilter from url', () => {
138
- router.getFullPath = () => 'localhost/?dynamic_filter=eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0='; // eslint-disable-line max-len
139
- datasource.watchUrl = true;
140
- const instance = new TekRestDatasource(datasource);
141
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
142
- });
143
-
144
- it('should set searchJoin from url', () => {
145
- router.getFullPath = () => 'localhost/?search_join=eyAiY29sMSI6IFsiMSIsICIyIl0sICJjb2wyIjogWzJdLCAiY29sMyI6IFtdIH0='; // eslint-disable-line max-len
146
- datasource.watchUrl = true;
147
- const instance = new TekRestDatasource(datasource);
148
- expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
149
- });
150
- });
151
-
152
- describe('addDynamicFilter()', () => {
153
- it('should add/remove dynamic filter value', () => {
154
- datasource.watchUrl = false;
155
- const instance = new TekRestDatasource(datasource);
156
- instance.addDynamicFilter('name', [{ operation: 'EQUALS', relation: 'AND', value: '1' }]);
157
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
158
- instance.addDynamicFilter('name', [{ operation: 'foo', relation: 'AND', value: '1' }]);
159
- expect(instance.dynamicFilter).toEqual({});
160
- });
161
- });
162
-
163
- describe('setDynamicFilter()', () => {
164
- it('should add/remove dynamic filter value', () => {
165
- datasource.watchUrl = false;
166
- const instance = new TekRestDatasource(datasource);
167
- instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
168
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
169
-
170
- instance.setDynamicFilter({ name: [{ operation: 'foo', relation: 'AND', value: '1' }] });
171
- expect(instance.dynamicFilter).toEqual({});
172
-
173
- instance.setDynamicFilter({
174
- department_id: undefined, hire_date: null, name: [], id: [{}],
175
- });
176
- expect(instance.dynamicFilter).toEqual({});
177
- });
178
-
179
- it('should add dynamic filter value with watchUrl', () => {
180
- let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
181
- router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
182
- const urlSpy = jest.spyOn(URL, 'updateQueryString');
183
-
184
- datasource.watchUrl = true;
185
- const instance = new TekRestDatasource(datasource);
186
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
187
-
188
- dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMiJ9XX0=';
189
- instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
190
- expect(urlSpy).toHaveBeenCalledWith({
191
- dynamic_filter: dynamicFilterValue,
192
- });
193
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
194
- urlSpy.mockClear();
195
- });
196
- });
197
-
198
- describe('clearDynamicFilter()', () => {
199
- it('should clear dynamic filter', () => {
200
- datasource.watchUrl = false;
201
- const instance = new TekRestDatasource(datasource);
202
- instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
203
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
204
- instance.clearDynamicFilter();
205
- expect(instance.dynamicFilter).toEqual({});
206
- });
207
-
208
- it('should clear dynamic filter value with watchUrl', () => {
209
- let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
210
- router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
211
- const urlSpy = jest.spyOn(URL, 'updateQueryString');
212
-
213
- datasource.watchUrl = true;
214
- const instance = new TekRestDatasource(datasource);
215
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
216
-
217
- dynamicFilterValue = '';
218
- instance.clearDynamicFilter();
219
- expect(urlSpy).toHaveBeenCalledWith({
220
- dynamic_filter: undefined,
221
- });
222
- expect(instance.dynamicFilter).toEqual({});
223
- urlSpy.mockClear();
224
- });
225
- });
226
-
227
- describe('get()', () => {
228
- it('should send dynamic filter and searchJoin on get request params', async () => {
229
- datasource.watchUrl = false;
230
- const instance = new TekRestDatasource(datasource);
231
- const dynFilter = { name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] };
232
- const searchJoin = { join: [1, 2, 3] };
233
- instance.setDynamicFilter(dynFilter);
234
- instance.searchJoin = searchJoin;
235
-
236
- await instance.get();
237
-
238
- const expectedFilter = btoa(JSON.stringify(dynFilter));
239
- const expectedSJoin = btoa(JSON.stringify(searchJoin));
240
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
241
- expect.objectContaining({
242
- params: expect.objectContaining({
243
- dynamic_filter: expectedFilter,
244
- search_join: expectedSJoin,
245
- }),
246
- }));
247
- });
248
-
249
- it('should send dynamic filter on get request params', async () => {
250
- datasource.watchUrl = false;
251
- const instance = new TekRestDatasource(datasource);
252
- const dynFilter = { name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] };
253
- instance.setDynamicFilter(dynFilter);
254
-
255
- await instance.get();
256
-
257
- const expectedFilter = btoa(JSON.stringify(dynFilter));
258
-
259
- // should have dynamic_filter
260
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
261
- expect.objectContaining({
262
- params: expect.objectContaining({
263
- dynamic_filter: expectedFilter,
264
- }),
265
- }));
266
- // should not have search_join
267
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
268
- expect.objectContaining({
269
- params: expect.not.objectContaining({
270
- search_join: expect.anything(),
271
- }),
272
- }));
273
- });
274
-
275
- it('should send search join on get request params', async () => {
276
- datasource.watchUrl = false;
277
- const instance = new TekRestDatasource(datasource);
278
- const searchJoin = { join: [1, 2, 3] };
279
- instance.searchJoin = searchJoin;
280
-
281
- await instance.get();
282
-
283
- const expectedSJoin = btoa(JSON.stringify(searchJoin));
284
- // should have search_join
285
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
286
- expect.objectContaining({
287
- params: expect.objectContaining({
288
- search_join: expectedSJoin,
289
- }),
290
- }));
291
- // should not have dynamic_filter
292
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
293
- expect.objectContaining({
294
- params: expect.not.objectContaining({
295
- dynamic_filter: expect.anything(),
296
- }),
297
- }));
298
- });
299
-
300
- it('should not send empty dynamic filter properties', async () => {
301
- const filter: IDictionary = {
302
- department_id: undefined, hire_date: null, name: [], id: [{}],
303
- };
304
- const instance = new TekRestDatasource(datasource);
305
- instance.dynamicFilter = filter;
306
-
307
- await instance.get();
308
-
309
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
310
- params: {
311
- in: [],
312
- order: [],
313
- search: undefined,
314
- search_in: [],
315
- page: 1,
316
- limit: 10,
317
- search_in_params: '{}',
318
- },
319
- }));
320
- });
321
- });
322
-
323
- describe('clone', () => {
324
- it('should return an object with all datasource props', async () => {
325
- const data = [{ value: 'item 1' }];
326
- const dynamicFilter = {
327
- name: { operation: 'EQUALS', relation: 'AND', value: 'item 1' },
328
- };
329
- const searchJoin = { col1: ['1', '2'], col2: [2], col3: [] };
330
- const instance = new TekRestDatasource({
331
- route: '/zeedhi',
332
- data,
333
- dynamicFilter,
334
- searchJoin,
335
- });
336
-
337
- const props = instance.clone();
338
-
339
- expect(props).toEqual({
340
- data,
341
- dynamicFilter,
342
- searchJoin,
343
- currentRow: {},
344
- filter: {},
345
- find: {},
346
- limit: 10,
347
- order: [],
348
- page: 1,
349
- search: '',
350
- searchIn: [],
351
- uniqueKey: 'id',
352
- watchUrl: false,
353
- events: {},
354
- loadAll: false,
355
- lazyLoad: true,
356
- arrayFormat: 'repeat',
357
- route: '/zeedhi',
358
- type: 'tek-rest',
359
- });
360
- });
361
- });
362
- });
@@ -1,112 +0,0 @@
1
- import type { IDictionary } from '@zeedhi/core';
2
- import { TekDragGrid } from '../../../../src/components/tek-drag-grid/tek-drag-grid';
3
-
4
- const dragFromXToY = (from: number, to: number, data: IDictionary[]) => {
5
- const row = data[from];
6
- data.splice(from, 1);
7
- data.splice(to, 0, row);
8
- const event = {
9
- oldIndex: from,
10
- newIndex: to,
11
- } as any;
12
- const element = {} as HTMLElement;
13
-
14
- return { event, element, row };
15
- };
16
-
17
- describe('DragGrid', () => {
18
- describe('constructor()', () => {
19
- it('create instance', () => {
20
- const instance = new TekDragGrid({
21
- name: 'DragGrid',
22
- component: 'DragGrid',
23
- orderColumnName: 'order',
24
- });
25
-
26
- expect(instance.orderColumnName).toBe('order');
27
- expect(instance.orderMode).toBe('asc');
28
-
29
- instance.orderColumnName = 'newOrder';
30
- instance.orderMode = 'desc';
31
-
32
- expect(instance.orderColumnName).toBe('newOrder');
33
- expect(instance.orderMode).toBe('desc');
34
- });
35
- });
36
-
37
- describe('onDragMove', () => {
38
- it('should call onDragMove event', () => {
39
- const onDragMove = jest.fn();
40
-
41
- const instance = new TekDragGrid({
42
- name: 'DragGrid',
43
- component: 'DragGrid',
44
- orderColumnName: 'order',
45
- events: {
46
- onDragMove,
47
- },
48
- });
49
-
50
- const event = {} as Event;
51
- const row = {};
52
- const element = {} as HTMLElement;
53
-
54
- instance.onDragMove(event, row, element);
55
-
56
- expect(onDragMove).toHaveBeenCalled();
57
- });
58
- });
59
-
60
- describe('onDragStart', () => {
61
- it('should call onDragStart event', () => {
62
- const onDragStart = jest.fn();
63
-
64
- const instance = new TekDragGrid({
65
- name: 'DragGrid',
66
- component: 'DragGrid',
67
- orderColumnName: 'order',
68
- events: {
69
- onDragStart,
70
- },
71
- });
72
-
73
- const event = {} as Event;
74
- const row = {};
75
- const element = {} as HTMLElement;
76
-
77
- instance.onDragStart(event, row, element);
78
-
79
- expect(onDragStart).toHaveBeenCalled();
80
- });
81
- });
82
-
83
- describe('onDragEnd()', () => {
84
- it('when called, should change order columns of the rows', () => {
85
- const instance = new TekDragGrid({
86
- name: 'DragGrid',
87
- component: 'DragGrid',
88
- orderColumnName: 'order',
89
- datasource: {
90
- uniqueKey: 'id',
91
- data: [
92
- { id: 1, name: 'a', order: 0 },
93
- { id: 2, name: 'b', order: 1 },
94
- { id: 3, name: 'c', order: 2 },
95
- { id: 4, name: 'd', order: 3 },
96
- ],
97
- },
98
- });
99
-
100
- const { event, row, element } = dragFromXToY(0, 1, instance.datasource.data);
101
- instance.onDragEnd(event, row, element);
102
-
103
- const editedrows = instance.getEditedRows();
104
- expect(editedrows).toEqual(
105
- expect.arrayContaining([
106
- { id: 1, name: 'a', order: 1 },
107
- { id: 2, name: 'b', order: 0 },
108
- ]),
109
- );
110
- });
111
- });
112
- });
@@ -1,49 +0,0 @@
1
- import { Button } from '@zeedhi/common';
2
- import { TekGrid, ButtonOption } from '../../../../src';
3
- import { Loader, SimpleControllerBuilder } from '@zeedhi/core';
4
-
5
- describe('ButtonOption', () => {
6
- beforeAll(() => {
7
- Loader.setBuilder(new SimpleControllerBuilder());
8
- });
9
-
10
- describe('buildComponent()', () => {
11
- it('when called, should build a simple button component', () => {
12
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
13
- const config = {
14
- type: 'pdf',
15
- label: 'Exportar PDF',
16
- };
17
- const option = new ButtonOption(config);
18
-
19
- const component = option.buildComponent(grid);
20
-
21
- expect(component).toEqual(expect.objectContaining({
22
- label: config.label,
23
- name: 'Grid_export_pdf_portrait',
24
- component: 'ZdButton',
25
- iconName: undefined,
26
- flat: true,
27
- }));
28
- });
29
-
30
- it('the generated button component should call grid.getReport on click', () => {
31
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
32
- const spy = jest.fn();
33
- grid.getReport = spy;
34
- const config = {
35
- type: 'pdf',
36
- label: 'Exportar PDF',
37
- portrait: false,
38
- };
39
- const option = new ButtonOption(config);
40
-
41
- const component = option.buildComponent(grid);
42
-
43
- const instance = new Button(component);
44
- instance.click();
45
-
46
- expect(spy).toHaveBeenCalledTimes(1);
47
- });
48
- });
49
- });
@@ -1,112 +0,0 @@
1
- import { ColumnsSearcher, ITekGridColumn } from '../../../../src';
2
-
3
- describe("ColumnsSearcher", () => {
4
- let columnsSearcher: ColumnsSearcher;
5
-
6
- beforeEach(() => {
7
- columnsSearcher = new ColumnsSearcher();
8
- });
9
-
10
- describe("searchColumn", () => {
11
- it("should return empty object when search string is empty", async () => {
12
- const columns: ITekGridColumn[] = [
13
- {
14
- name: "testColumn",
15
- componentProps: { name: 'testColumnName', datasource: { uniqueKey: "id" } },
16
- memorySearch: jest.fn(),
17
- },
18
- ];
19
- const search = "";
20
-
21
- const result = await columnsSearcher.searchColumn(columns, search);
22
-
23
- expect(result).toEqual({});
24
- expect(columns[0].memorySearch).not.toHaveBeenCalled();
25
- });
26
-
27
- it("should skip columns without datasource", async () => {
28
- const columns: ITekGridColumn[] = [
29
- {
30
- name: "noDataSourceColumn",
31
- componentProps: { name: 'noDataSourceColumnName' },
32
- memorySearch: jest.fn(),
33
- },
34
- {
35
- name: "validColumn",
36
- componentProps: { name: 'validColumnName', datasource: { uniqueKey: "id" } },
37
- memorySearch: jest.fn().mockResolvedValue([{ id: 1 }]),
38
- },
39
- ];
40
- const search = "test";
41
-
42
- const result = await columnsSearcher.searchColumn(columns, search);
43
-
44
- expect(result).toEqual({ validColumn: [1] });
45
- expect(columns[0].memorySearch).not.toHaveBeenCalled();
46
- expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
47
- });
48
-
49
- it("should skip columns with skipLookupSearch=true", async () => {
50
- const columns: ITekGridColumn[] = [
51
- {
52
- name: "skippedColumn",
53
- componentProps: { name: 'skippedColumnName', datasource: { uniqueKey: "id" } },
54
- skipLookupSearch: true,
55
- memorySearch: jest.fn(),
56
- },
57
- {
58
- name: "validColumn",
59
- componentProps: { name: 'validColumnName', datasource: { uniqueKey: "id" } },
60
- memorySearch: jest.fn().mockResolvedValue([{ id: 1 }]),
61
- },
62
- ];
63
- const search = "test";
64
-
65
- const result = await columnsSearcher.searchColumn(columns, search);
66
-
67
- expect(result).toEqual({ validColumn: [1] });
68
- expect(columns[0].memorySearch).not.toHaveBeenCalled();
69
- expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
70
- });
71
-
72
- it("should process multiple columns in parallel", async () => {
73
- const columns: ITekGridColumn[] = [
74
- {
75
- name: "column1",
76
- componentProps: { name: 'column1Name', datasource: { uniqueKey: "id" } },
77
- memorySearch: jest.fn().mockResolvedValue([{ id: 1 }, { id: 2 }]),
78
- },
79
- {
80
- name: "column2",
81
- componentProps: { name: 'column2Name', datasource: { uniqueKey: "code" } },
82
- memorySearch: jest.fn().mockResolvedValue([{ code: "A" }, { code: "B" }]),
83
- },
84
- ];
85
- const search = "test";
86
-
87
- const result = await columnsSearcher.searchColumn(columns, search);
88
-
89
- expect(result).toEqual({
90
- column1: [1, 2],
91
- column2: ["A", "B"],
92
- });
93
- expect(columns[0].memorySearch).toHaveBeenCalledWith("test");
94
- expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
95
- });
96
-
97
- it("should handle empty search results", async () => {
98
- const columns: ITekGridColumn[] = [
99
- {
100
- name: "emptyResultsColumn",
101
- componentProps: { name: 'emptyResultsColumnName', datasource: { uniqueKey: "id" } },
102
- memorySearch: jest.fn().mockResolvedValue([]),
103
- },
104
- ];
105
- const search = "test";
106
-
107
- const result = await columnsSearcher.searchColumn(columns, search);
108
-
109
- expect(result).toEqual({ emptyResultsColumn: [] });
110
- });
111
- });
112
- });