@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,422 +0,0 @@
1
- import {
2
- IConfig, Config, Router, Http, URL, IDictionary, init,
3
- } from '@zeedhi/core';
4
- import {
5
- TekRestDatasource, ITekRestDatasource,
6
- } from '../../../../src';
7
- import { flushPromises } from '../../__helpers__';
8
-
9
- describe('TekRestDatasource', () => {
10
- init({
11
- controllers: {
12
- AppController: class AppController {
13
- public value = '1';
14
-
15
- public join: string[] | number[] = ['1', '2'];
16
- },
17
- },
18
- });
19
- let datasource: ITekRestDatasource;
20
- let router: any;
21
- const config: IConfig = {
22
- endPoint: 'http://localhost:9000/',
23
- metadataEndPoint: 'http://localhost:9000/metadata/',
24
- title: 'Samples',
25
- mode: 'production',
26
- datasourceLimit: 10,
27
- };
28
- let httpSpy: jest.SpyInstance;
29
-
30
- beforeEach(() => {
31
- datasource = {
32
- uniqueKey: 'id',
33
- route: '/zeedhi',
34
- lazyLoad: true,
35
- };
36
- Config.set(config);
37
- router = {
38
- push: () => jest.fn,
39
- replace: (route: any) => {
40
- window.history.replaceState(null, '', `${window.location.pathname}?${URL.getFormattedQueryString(route.query)}`);
41
- },
42
- back: () => jest.fn,
43
- getCurrentRoute: () => ({
44
- path: '',
45
- hash: '',
46
- query: {},
47
- params: {},
48
- fullPath: '',
49
- }),
50
- getPath: () => '',
51
- getHash: () => '',
52
- getQuery: () => ({}),
53
- getParams: () => ({}),
54
- getFullPath: () => '',
55
- };
56
- Router.setInstance(router);
57
- httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
58
- data: {
59
- data: [
60
- { name: '1', id: 1 }, { name: '2', id: 2 }, { name: '3', id: 3 },
61
- { name: '4', id: 4 }, { name: '5', id: 5 }, { name: '6', id: 6 },
62
- ],
63
- pagination: {
64
- page: 1,
65
- total: 6,
66
- limit: 15,
67
- },
68
- },
69
- }));
70
- });
71
-
72
- afterEach(() => {
73
- httpSpy.mockClear();
74
- });
75
-
76
- describe('constuctor()', () => {
77
- it('should assign all properties', async () => {
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 instance = new TekRestDatasource({
96
- ...datasource,
97
- dynamicFilter: {
98
- name: { operation: 'EQUALS', relation: 'AND', value: '{{AppController.value}}' },
99
- },
100
- searchJoin: { col1: '{{AppController.join}}' as any, col2: [2], col3: [] },
101
- });
102
- await flushPromises();
103
-
104
- expect(instance.route).toBe('/zeedhi');
105
- expect(instance.lazyLoad).toBeTruthy();
106
- expect(instance.dynamicFilter).toEqual({ name: { operation: 'EQUALS', relation: 'AND', value: '1' } });
107
- expect(instance.data.length).toBe(0);
108
- expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
109
- });
110
-
111
- it('should create without lazyLoad', async () => {
112
- const instance = new TekRestDatasource({
113
- ...datasource,
114
- lazyLoad: false,
115
- dynamicFilter: {
116
- name: { operation: 'EQUALS', relation: 'AND', value: '1' },
117
- },
118
- });
119
- instance.initialize();
120
- await flushPromises();
121
-
122
- expect(instance.data.length).toBe(6);
123
- });
124
-
125
- it('should set values from url', () => {
126
- router.getFullPath = () => 'localhost/?page=2&limit=10&order=id.asc&search=2&id=1&filter=applied';
127
- datasource.watchUrl = true;
128
- const instance = new TekRestDatasource(datasource);
129
- expect(instance.filter).toEqual({ id: '1' });
130
- expect(instance.limit).toBe(10);
131
- expect(instance.order).toEqual(['id.asc']);
132
- expect(instance.page).toBe(2);
133
- expect(instance.search).toBe('2');
134
- });
135
- });
136
-
137
- describe('urlHasChanged()', () => {
138
- it('should return true when url query string is different from datasource query string', () => {
139
- datasource.watchUrl = true;
140
- const spy = jest.spyOn(URL, 'getParsedQueryStringFromUrl').mockReturnValue({
141
- dynamic_filter: 'eyJuYW1lIjpbeyJ2YWx1ZSI6IjIiLCJvcGVyYXRpb24iOiJDT05UQUlOUyIsInJlbGF0aW9uIjoiQU5EIn1dfQ==',
142
- search_join: 'eyJjb2wxIjpbIjEiLCIyIl19',
143
- });
144
- const instance = new TekRestDatasource(datasource);
145
- instance.dynamicFilter = { name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] };
146
- instance.searchJoin = { col1: ['1', '2'], col2: [2], col3: [] };
147
- instance.initialize();
148
- expect(instance.urlHasChanged()).toBeTruthy();
149
-
150
- spy.mockClear();
151
- });
152
- });
153
-
154
- describe('addDynamicFilter()', () => {
155
- it('should add/remove dynamic filter value', () => {
156
- datasource.watchUrl = false;
157
- const instance = new TekRestDatasource(datasource);
158
- instance.addDynamicFilter('name', [{ operation: 'EQUALS', relation: 'AND', value: '1' }]);
159
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
160
- instance.addDynamicFilter('name', [{ operation: 'foo', relation: 'AND', value: '1' }]);
161
- expect(instance.dynamicFilter).toEqual({});
162
- });
163
- });
164
-
165
- describe('setDynamicFilter()', () => {
166
- it('should add/remove dynamic filter value', () => {
167
- datasource.watchUrl = false;
168
- const instance = new TekRestDatasource(datasource);
169
- instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
170
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
171
-
172
- instance.setDynamicFilter({ name: [{ operation: 'foo', relation: 'AND', value: '1' }] });
173
- expect(instance.dynamicFilter).toEqual({});
174
-
175
- instance.setDynamicFilter({
176
- department_id: undefined, hire_date: null, name: [], id: [{}],
177
- });
178
- expect(instance.dynamicFilter).toEqual({});
179
- });
180
-
181
- // it('should add dynamic filter value with watchUrl', () => {
182
- // let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
183
- // router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
184
- // const urlSpy = jest.spyOn(URL, 'updateQueryString');
185
-
186
- // datasource.watchUrl = true;
187
- // const instance = new TekRestDatasource(datasource);
188
- // instance.initialize();
189
- // expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
190
-
191
- // dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMiJ9XX0=';
192
- // instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
193
- // expect(urlSpy).toHaveBeenCalledWith({
194
- // dynamic_filter: dynamicFilterValue,
195
- // });
196
- // expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
197
- // urlSpy.mockClear();
198
- // });
199
- });
200
-
201
- describe('clearDynamicFilter()', () => {
202
- it('should clear dynamic filter', () => {
203
- datasource.watchUrl = false;
204
- const instance = new TekRestDatasource(datasource);
205
- instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
206
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
207
- instance.clearDynamicFilter();
208
- expect(instance.dynamicFilter).toEqual({});
209
- });
210
-
211
- // it('should clear dynamic filter value with watchUrl', () => {
212
- // let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
213
- // router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
214
- // const urlSpy = jest.spyOn(URL, 'updateQueryString');
215
-
216
- // datasource.watchUrl = true;
217
- // const instance = new TekRestDatasource(datasource);
218
- // instance.initialize();
219
- // expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
220
-
221
- // dynamicFilterValue = '';
222
- // instance.clearDynamicFilter();
223
- // expect(urlSpy).toHaveBeenCalledWith({
224
- // dynamic_filter: undefined,
225
- // });
226
- // expect(instance.dynamicFilter).toEqual({});
227
- // urlSpy.mockClear();
228
- // });
229
- });
230
-
231
- describe('get()', () => {
232
- it('should send dynamic filter and searchJoin on get request params', async () => {
233
- datasource.watchUrl = false;
234
- const instance = new TekRestDatasource(datasource);
235
- const dynFilter = { name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] };
236
- const searchJoin = { join: [1, 2, 3] };
237
- instance.setDynamicFilter(dynFilter);
238
- instance.searchJoin = searchJoin;
239
-
240
- await instance.get();
241
-
242
- const expectedFilter = btoa(JSON.stringify(dynFilter));
243
- const expectedSJoin = btoa(JSON.stringify(searchJoin));
244
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
245
- expect.objectContaining({
246
- params: expect.objectContaining({
247
- dynamic_filter: expectedFilter,
248
- search_join: expectedSJoin,
249
- }),
250
- }));
251
- });
252
-
253
- it('should send dynamic filter on get request params', async () => {
254
- datasource.watchUrl = false;
255
- const instance = new TekRestDatasource(datasource);
256
- const dynFilter = { name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] };
257
- instance.setDynamicFilter(dynFilter);
258
-
259
- await instance.get();
260
-
261
- const expectedFilter = btoa(JSON.stringify(dynFilter));
262
-
263
- // should have dynamic_filter
264
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
265
- expect.objectContaining({
266
- params: expect.objectContaining({
267
- dynamic_filter: expectedFilter,
268
- }),
269
- }));
270
- // should not have search_join
271
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
272
- expect.objectContaining({
273
- params: expect.not.objectContaining({
274
- search_join: expect.anything(),
275
- }),
276
- }));
277
- });
278
-
279
- it('should send search join on get request params', async () => {
280
- datasource.watchUrl = false;
281
- const instance = new TekRestDatasource(datasource);
282
- const searchJoin = { join: [1, 2, 3] };
283
- instance.searchJoin = searchJoin;
284
-
285
- await instance.get();
286
-
287
- const expectedSJoin = btoa(JSON.stringify(searchJoin));
288
- // should have search_join
289
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
290
- expect.objectContaining({
291
- params: expect.objectContaining({
292
- search_join: expectedSJoin,
293
- }),
294
- }));
295
- // should not have dynamic_filter
296
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi',
297
- expect.objectContaining({
298
- params: expect.not.objectContaining({
299
- dynamic_filter: expect.anything(),
300
- }),
301
- }));
302
- });
303
-
304
- it('should not send empty dynamic filter properties', async () => {
305
- const filter: IDictionary = {
306
- department_id: undefined, hire_date: null, name: [], id: [{}],
307
- };
308
- const instance = new TekRestDatasource(datasource);
309
- instance.initialize();
310
- instance.dynamicFilter = filter;
311
-
312
- await instance.get();
313
-
314
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
315
- params: {
316
- in: [],
317
- order: [],
318
- search: undefined,
319
- search_in: [],
320
- page: 1,
321
- limit: 10,
322
- },
323
- }));
324
- });
325
-
326
- it('when using watchUrl, should update the dynamicFilter using the value from url query string', async () => {
327
- const instance = new TekRestDatasource(datasource);
328
- instance.initialize();
329
- instance.watchUrl = true;
330
- const spy = jest.spyOn(URL, 'getParsedQueryStringFromUrl').mockReturnValue({ dynamic_filter: 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=' });
331
-
332
- await instance.get();
333
-
334
- expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
335
- spy.mockClear();
336
- });
337
- });
338
-
339
- describe('clone', () => {
340
- it('should return an object with all datasource props', async () => {
341
- const data = [{ value: 'item 1' }];
342
- const dynamicFilter = {
343
- name: { operation: 'EQUALS', relation: 'AND', value: 'item 1' },
344
- };
345
- const searchJoin = { col1: ['1', '2'], col2: [2], col3: [] };
346
- const instance = new TekRestDatasource({
347
- route: '/zeedhi',
348
- data,
349
- dynamicFilter,
350
- searchJoin,
351
- });
352
- instance.initialize();
353
-
354
- const props = instance.clone();
355
-
356
- expect(props).toEqual({
357
- data,
358
- dynamicFilter,
359
- searchJoin,
360
- currentRow: {},
361
- filter: {},
362
- find: {},
363
- limit: 10,
364
- order: [],
365
- page: 1,
366
- search: '',
367
- searchIn: [],
368
- uniqueKey: 'id',
369
- watchUrl: false,
370
- events: {},
371
- loadAll: false,
372
- lazyLoad: true,
373
- arrayFormat: 'repeat',
374
- route: '/zeedhi',
375
- type: 'tek-rest',
376
- });
377
- });
378
- });
379
-
380
- describe('hasFilter()', () => {
381
- it('should return true if there is a filter for the column', () => {
382
- const instance = new TekRestDatasource(datasource);
383
- instance.initialize();
384
- expect(instance.hasFilter('name')).toBeFalsy();
385
- instance.dynamicFilter = { name: [{ value: 'name 1', operation: 'CONTAINS', relation: 'AND' }] };
386
- expect(instance.hasFilter('name')).toBeTruthy();
387
- });
388
- });
389
-
390
- describe('updateDynamicFilter()', () => {
391
- it('when watching url, should update the url with the new dynamic filter', async () => {
392
- const instance = new TekRestDatasource(datasource);
393
- instance.initialize();
394
- const dynamicFilter = { name: [{ value: 'name 1', operation: 'CONTAINS', relation: 'AND' }] };
395
- instance.dynamicFilter = { ...dynamicFilter };
396
- instance.watchUrl = true;
397
- const spy = jest.spyOn(URL, 'updateQueryString');
398
-
399
- await instance.updateDynamicFilter();
400
-
401
- expect(spy).toHaveBeenCalledWith({
402
- dynamic_filter: btoa(JSON.stringify(dynamicFilter)),
403
- });
404
- spy.mockClear();
405
- });
406
-
407
- it('when watching url, when dynamicFilter is empty, should update the url with undefined', async () => {
408
- const instance = new TekRestDatasource(datasource);
409
- instance.initialize();
410
- instance.dynamicFilter = {};
411
- instance.watchUrl = true;
412
- const spy = jest.spyOn(URL, 'updateQueryString');
413
-
414
- await instance.updateDynamicFilter();
415
-
416
- expect(spy).toHaveBeenCalledWith({
417
- dynamic_filter: undefined,
418
- });
419
- spy.mockClear();
420
- });
421
- });
422
- });
@@ -1,67 +0,0 @@
1
- import { Image } from '../../../../src';
2
-
3
- describe('Image', () => {
4
- describe('constructor()', () => {
5
- it('should create new Image with default values', () => {
6
- const instance = new Image({
7
- name: 'image',
8
- component: 'Image',
9
- });
10
- expect(instance.src).toBe('');
11
- expect(instance.to).toBe('');
12
- expect(instance.height).toBe('auto');
13
- expect(instance.minHeight).toBe('auto');
14
- expect(instance.maxHeight).toBe('none');
15
- expect(instance.fillHeight).toBeFalsy();
16
- expect(instance.width).toBe('auto');
17
- expect(instance.minWidth).toBe('auto');
18
- expect(instance.maxWidth).toBe('none');
19
- });
20
-
21
- it('should create new image replacing default values', () => {
22
- const instance = new Image({
23
- name: 'image',
24
- component: 'Image',
25
- src: '/img/zeedhi.svg',
26
- to: 'google.com.br',
27
- height: '400px',
28
- maxHeight: '500px',
29
- minHeight: '500px',
30
- width: '400px',
31
- maxWidth: '500px',
32
- minWidth: '500px',
33
- fillHeight: true,
34
- });
35
- expect(instance.src).toBe('/img/zeedhi.svg');
36
- expect(instance.to).toBe('google.com.br');
37
- expect(instance.height).toBe('400px');
38
- expect(instance.maxHeight).toBe('500px');
39
- expect(instance.minHeight).toBe('500px');
40
- expect(instance.width).toBe('400px');
41
- expect(instance.maxWidth).toBe('500px');
42
- expect(instance.minWidth).toBe('500px');
43
- expect(instance.fillHeight).toBeTruthy();
44
- });
45
- });
46
-
47
- describe('load event', () => {
48
- it('should call load event', () => {
49
- const load = jest.fn();
50
- const instance = new Image({
51
- name: 'image',
52
- component: 'TekImage',
53
- events: {
54
- load,
55
- },
56
- });
57
-
58
- const event = {} as Event;
59
- const element = {} as HTMLElement;
60
- instance.load(event, element);
61
-
62
- expect(load).toHaveBeenCalledWith({
63
- event, element, component: instance,
64
- });
65
- });
66
- });
67
- });
@@ -1,37 +0,0 @@
1
- import { IterableComponentRender } from '@zeedhi/common';
2
- import { IterableCarousel } from '../../../../src';
3
-
4
- describe('IterableCarousel', () => {
5
- describe('constructor()', () => {
6
- it('should create new IterableCarousel with default values', () => {
7
- const instance = new IterableCarousel({
8
- name: 'iterable',
9
- component: 'TekIterableCarousel',
10
- });
11
- expect(instance.iterable).toBeInstanceOf(IterableComponentRender);
12
- });
13
-
14
- it('should create new IterableCarousel replace default values', () => {
15
- const instance = new IterableCarousel({
16
- name: 'iterable',
17
- component: 'TekIterableCarousel',
18
- iterable: {
19
- cssClass: 'test',
20
- },
21
- children: [],
22
- });
23
- expect(instance.iterable.cssClass).toBe('test');
24
- expect(instance.children).toEqual([]);
25
- });
26
-
27
- it('Throw error', () => {
28
- const instance = new IterableCarousel({
29
- name: 'iterable',
30
- component: 'TekIterableCarousel',
31
- });
32
- expect(() => {
33
- instance.children = [{ name: 'childrenItem', component: 'Text' }];
34
- }).toThrow('You should not change children when using IterableCarousel');
35
- });
36
- });
37
- });