@zeedhi/teknisa-components-common 1.107.1 → 1.108.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 (77) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +7 -7
  3. package/coverage/clover.xml +772 -692
  4. package/coverage/coverage-final.json +47 -47
  5. package/coverage/lcov-report/index.html +15 -15
  6. package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
  7. package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
  8. package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +7 -7
  9. package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
  10. package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
  11. package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
  12. package/coverage/lcov.info +1459 -1275
  13. package/dist/tek-components-common.esm.js +375 -252
  14. package/dist/tek-components-common.umd.js +375 -252
  15. package/jest.config.js +1 -1
  16. package/package.json +2 -2
  17. package/tests/__helpers__/component-event-helper.ts +5 -5
  18. package/tests/__helpers__/flush-promises-helper.ts +3 -3
  19. package/tests/__helpers__/get-child-helper.ts +27 -27
  20. package/tests/__helpers__/index.ts +3 -3
  21. package/tests/__helpers__/mock-created-helper.ts +12 -12
  22. package/tests/__mocks__/@zeedhi/core/i18n.js +74 -74
  23. package/tests/__mocks__/@zeedhi/core.js +4 -4
  24. package/tests/unit/components/crud/crud-add-button.spec.ts +56 -56
  25. package/tests/unit/components/crud/crud-button.spec.ts +94 -94
  26. package/tests/unit/components/crud/crud-cancel-button.spec.ts +91 -91
  27. package/tests/unit/components/crud/crud-delete-button.spec.ts +122 -122
  28. package/tests/unit/components/crud/crud-form.spec.ts +165 -165
  29. package/tests/unit/components/crud/crud-save-button.spec.ts +118 -118
  30. package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +42 -42
  31. package/tests/unit/components/tek-card-title/CardTitle.spec.ts +34 -34
  32. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +470 -470
  33. package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +364 -364
  34. package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -112
  35. package/tests/unit/components/tek-grid/filter-helper.spec.ts +148 -148
  36. package/tests/unit/components/tek-grid/grid-column.spec.ts +270 -270
  37. package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +195 -195
  38. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +967 -967
  39. package/tests/unit/components/tek-grid/grid.spec.ts +3340 -3116
  40. package/tests/unit/components/tek-grid/layout_options.spec.ts +980 -980
  41. package/tests/unit/components/tek-image/Image.spec.ts +67 -67
  42. package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +37 -37
  43. package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +200 -200
  44. package/tests/unit/components/tek-loading/Loading.spec.ts +30 -30
  45. package/tests/unit/components/tek-notifications/notifications.spec.ts +201 -201
  46. package/tests/unit/components/tek-product-card/product-card.spec.ts +61 -61
  47. package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +220 -220
  48. package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +86 -86
  49. package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +430 -430
  50. package/tests/unit/components/tree-grid/tree-grid.spec.ts +776 -776
  51. package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +24 -0
  52. package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -44
  53. package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -135
  54. package/tests/unit/utils/grid-base/grid-controller.spec.ts +267 -174
  55. package/tests/unit/utils/report-filter/report-filter.spec.ts +66 -66
  56. package/tsconfig.eslint.json +8 -8
  57. package/types/components/tek-datasource/memory-datasource.d.ts +2 -4
  58. package/types/components/tek-datasource/rest-datasource.d.ts +6 -3
  59. package/types/components/tek-grid/grid.d.ts +50 -6
  60. package/types/components/tek-grid/interfaces.d.ts +5 -3
  61. package/types/components/tek-tree-grid/tree-grid.d.ts +5 -1
  62. package/types/utils/grid-base/grid-base.d.ts +12 -229
  63. package/types/utils/grid-base/grid-controller.d.ts +1 -3
  64. package/types/components/tek-ag-grid/default-icons.d.ts +0 -53
  65. package/types/components/tek-ag-grid/interfaces.d.ts +0 -9
  66. package/types/components/tek-ag-grid/tek-ag-grid.d.ts +0 -35
  67. package/types/components/tek-datasource/datasource.d.ts +0 -94
  68. package/types/components/tek-grid/default-icons.d.ts +0 -53
  69. package/types/components/tek-grid/filter-dynamic-values.d.ts +0 -9
  70. package/types/components/tek-grid/grid-controller.d.ts +0 -19
  71. package/types/components/tek-grid/grid_column.d.ts +0 -14
  72. package/types/components/tek-grid/grid_controller.d.ts +0 -15
  73. package/types/components/tek-grid/tek-grid.d.ts +0 -35
  74. package/types/components/tek-login/interfaces.d.ts +0 -3
  75. package/types/components/tek-login/login-children.d.ts +0 -3
  76. package/types/components/tek-login/login.d.ts +0 -58
  77. package/types/components/tek-login/login_children.d.ts +0 -3
@@ -1,270 +1,270 @@
1
- import { Http } from '@zeedhi/core';
2
- import {
3
- IFilterOperation,
4
- IFilterPropsComponent,
5
- IFilterRelation,
6
- ITekGridColumn,
7
- TekGrid,
8
- TekGridColumn,
9
- } from '../../../../src';
10
-
11
- jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
12
- const flushPromises = () => new Promise(setImmediate);
13
-
14
- describe('TekGridColumn', () => {
15
- let baseProps: ITekGridColumn;
16
- let httpSpy: jest.SpyInstance;
17
-
18
- beforeEach(() => {
19
- httpSpy = jest.spyOn(Http, 'get').mockImplementation((url: string) => {
20
- if (url === '/zeedhi') {
21
- return Promise.resolve({
22
- data: {
23
- data: [
24
- { id: 1, name: 'employee 1', department: 1 },
25
- { id: 2, name: 'employee 2', department: 1 },
26
- { id: 3, name: 'employee 3', department: 1 },
27
- { id: 4, name: 'employee 4', department: 2 },
28
- { id: 5, name: 'employee 5', department: 2 },
29
- { id: 15, name: 'employee 15', department: 2 },
30
- ],
31
- pagination: {
32
- page: 1,
33
- total: 5,
34
- limit: 15,
35
- },
36
- },
37
- });
38
- }
39
-
40
- if (url === '/grid') {
41
- return Promise.resolve({
42
- data: {
43
- data: [
44
- { id: 1, employee_id: 1, department: 1 },
45
- { id: 2, employee_id: 2, department: 1 },
46
- { id: 3, employee_id: 3, department: 1 },
47
- ],
48
- pagination: {
49
- page: 1,
50
- total: 5,
51
- limit: 15,
52
- },
53
- },
54
- });
55
- }
56
-
57
- return Promise.reject();
58
- });
59
-
60
- baseProps = {
61
- name: 'employee_id',
62
- componentProps: {
63
- name: 'ZdSelect',
64
- dataText: 'name',
65
- datasource: {
66
- type: 'tek-rest',
67
- route: '/zeedhi',
68
- lazyLoad: false,
69
- },
70
- },
71
- };
72
- });
73
-
74
- afterEach(() => {
75
- httpSpy.mockClear();
76
- });
77
-
78
- describe('constructor()', () => {
79
- it('should create new column with default values', () => {
80
- const props: ITekGridColumn = {
81
- name: 'employee_id',
82
- };
83
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
84
- const column = new TekGridColumn(props, grid);
85
-
86
- expect(column.filterProps).toEqual([]);
87
- expect(column.groupLabelForEmptyValue).toBe('');
88
- expect(column.filterable).toBeTruthy();
89
- expect(column.isVisible).toBeTruthy();
90
- expect(column.storeData).toBeTruthy();
91
- });
92
-
93
- it('should create new column replacing default values', () => {
94
- const filterProps: IFilterPropsComponent = {
95
- name: 'name',
96
- relation: 'AND' as IFilterRelation,
97
- operation: 'CONTAINS' as IFilterOperation,
98
- };
99
- const groupLabelForEmptyValue = 'Empty';
100
- const props: ITekGridColumn = {
101
- filterProps,
102
- groupLabelForEmptyValue,
103
- name: 'employee_id',
104
- isVisible: false,
105
- filterable: false,
106
- storeData: false,
107
- };
108
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
109
- const column = new TekGridColumn(props, grid);
110
-
111
- expect(column.filterProps).toEqual(filterProps);
112
- expect(column.groupLabelForEmptyValue).toBe(groupLabelForEmptyValue);
113
- expect(column.filterable).toBeFalsy();
114
- expect(column.isVisible).toBeFalsy();
115
- expect(column.storeData).toBeFalsy();
116
- });
117
- });
118
-
119
- describe('getLookupData()', () => {
120
- it('should get lookup data', async () => {
121
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
122
- const column = new TekGridColumn(baseProps, grid);
123
-
124
- let data = column.getLookupData('name', 'employee 1');
125
- expect(data).toEqual({});
126
-
127
- await flushPromises();
128
- data = column.getLookupData('name', 'employee 1');
129
- expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
130
- expect(httpSpy).toHaveBeenCalledTimes(1);
131
- });
132
-
133
- it('should get lookup data using memory', async () => {
134
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
135
- baseProps.componentProps!.datasource = {
136
- data: [
137
- { id: 1, name: 'employee 1 memory', department: 1 },
138
- { id: 2, name: 'employee 2 memory', department: 1 },
139
- { id: 3, name: 'employee 3 memory', department: 1 },
140
- { id: 4, name: 'employee 4 memory', department: 2 },
141
- { id: 5, name: 'employee 5 memory', department: 2 },
142
- { id: 15, name: 'employee 15 memory', department: 2 },
143
- ],
144
- };
145
- const column = new TekGridColumn(baseProps, grid);
146
-
147
- const data = column.getLookupData('name', 'employee 1 memory');
148
- expect(data).toEqual({ id: 1, name: 'employee 1 memory', department: 1 });
149
- expect(httpSpy).toHaveBeenCalledTimes(0);
150
- });
151
-
152
- it('should get lookup data using filter when storeData is false', async () => {
153
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
154
- baseProps.storeData = false;
155
- const column = new TekGridColumn(baseProps, grid);
156
-
157
- let data = column.getLookupData('name', 'employee 1');
158
- expect(data).toEqual({});
159
-
160
- await flushPromises();
161
- data = column.getLookupData('name', 'employee 1');
162
- expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
163
- expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
164
- params: expect.objectContaining({
165
- name: ['employee 1'],
166
- }),
167
- }));
168
- });
169
- });
170
-
171
- describe('getBatchLookupData', () => {
172
- it('when called, should lookup for a batch of values asynchonously, adding them to lookupData', async () => {
173
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
174
- baseProps.storeData = false;
175
- const column = new TekGridColumn(baseProps, grid);
176
-
177
- const data = await column.getBatchLookupData('id', [1, 2]);
178
- expect(data).toEqual([
179
- { id: 1, name: 'employee 1', department: 1 },
180
- { id: 2, name: 'employee 2', department: 1 },
181
- ]);
182
-
183
- expect(column.getLookupData('id', '1')).toEqual({ id: 1, name: 'employee 1', department: 1 });
184
- expect(column.getLookupData('id', '2')).toEqual({ id: 2, name: 'employee 2', department: 1 });
185
-
186
- expect(httpSpy).toHaveBeenCalledTimes(1);
187
- });
188
-
189
- it('when called with values that are already in lookupData, should not call datasource.get', async () => {
190
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
191
- baseProps.storeData = false;
192
- const column = new TekGridColumn(baseProps, grid);
193
-
194
- column.lookupData = {
195
- 1: { id: 1, name: 'employee 1', department: 1 },
196
- };
197
- (column as any).lookupDatasource?.data.push({ id: 2, name: 'employee 2', department: 1 });
198
-
199
- const data = await column.getBatchLookupData('id', [1, 2]);
200
- expect(data).toEqual([
201
- { id: 1, name: 'employee 1', department: 1 },
202
- { id: 2, name: 'employee 2', department: 1 },
203
- ]);
204
-
205
- expect(httpSpy).toHaveBeenCalledTimes(0);
206
- });
207
- });
208
-
209
- describe('memorySearch()', () => {
210
- it('should search in memory', async () => {
211
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
212
- const column = new TekGridColumn(baseProps, grid);
213
-
214
- let data = await column.memorySearch('employee 15');
215
- expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
216
- expect(httpSpy).toHaveBeenCalledTimes(1);
217
-
218
- baseProps.componentProps!.dataText = ['id'];
219
- const column2 = new TekGridColumn(baseProps, grid);
220
-
221
- data = await column2.memorySearch('3');
222
- expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
223
- expect(httpSpy).toHaveBeenCalledTimes(2);
224
- });
225
-
226
- it('should not make request if data is already in memory', async () => {
227
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
228
- const column = new TekGridColumn(baseProps, grid);
229
-
230
- let data = await column.memorySearch('employee 15');
231
- expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
232
- expect(httpSpy).toHaveBeenCalledTimes(1);
233
-
234
- data = await column.memorySearch('employee 2');
235
- expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
236
- expect(httpSpy).toHaveBeenCalledTimes(1);
237
- });
238
-
239
- it('should always make another request when storeData is false', async () => {
240
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
241
- baseProps.storeData = false;
242
- const column = new TekGridColumn(baseProps, grid);
243
-
244
- let data = await column.memorySearch('employee 15');
245
- expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
246
- expect(httpSpy).toHaveBeenCalledTimes(1);
247
-
248
- data = await column.memorySearch('employee 2');
249
- expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
250
- expect(httpSpy).toHaveBeenCalledTimes(2);
251
-
252
- data = await column.memorySearch('employee 3');
253
- expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
254
- expect(httpSpy).toHaveBeenCalledTimes(3);
255
- });
256
-
257
- it('should throw error if column doesn\'t have a datasource', async () => {
258
- baseProps = {
259
- name: 'employee_id',
260
- componentProps: {
261
- name: 'ZdTextInput',
262
- },
263
- };
264
- const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
265
- const column = new TekGridColumn(baseProps, grid);
266
-
267
- await expect(column.memorySearch('')).rejects.toThrow();
268
- });
269
- });
270
- });
1
+ import { Http } from '@zeedhi/core';
2
+ import {
3
+ IFilterOperation,
4
+ IFilterPropsComponent,
5
+ IFilterRelation,
6
+ ITekGridColumn,
7
+ TekGrid,
8
+ TekGridColumn,
9
+ } from '../../../../src';
10
+
11
+ jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
12
+ const flushPromises = () => new Promise(setImmediate);
13
+
14
+ describe('TekGridColumn', () => {
15
+ let baseProps: ITekGridColumn;
16
+ let httpSpy: jest.SpyInstance;
17
+
18
+ beforeEach(() => {
19
+ httpSpy = jest.spyOn(Http, 'get').mockImplementation((url: string) => {
20
+ if (url === '/zeedhi') {
21
+ return Promise.resolve({
22
+ data: {
23
+ data: [
24
+ { id: 1, name: 'employee 1', department: 1 },
25
+ { id: 2, name: 'employee 2', department: 1 },
26
+ { id: 3, name: 'employee 3', department: 1 },
27
+ { id: 4, name: 'employee 4', department: 2 },
28
+ { id: 5, name: 'employee 5', department: 2 },
29
+ { id: 15, name: 'employee 15', department: 2 },
30
+ ],
31
+ pagination: {
32
+ page: 1,
33
+ total: 5,
34
+ limit: 15,
35
+ },
36
+ },
37
+ });
38
+ }
39
+
40
+ if (url === '/grid') {
41
+ return Promise.resolve({
42
+ data: {
43
+ data: [
44
+ { id: 1, employee_id: 1, department: 1 },
45
+ { id: 2, employee_id: 2, department: 1 },
46
+ { id: 3, employee_id: 3, department: 1 },
47
+ ],
48
+ pagination: {
49
+ page: 1,
50
+ total: 5,
51
+ limit: 15,
52
+ },
53
+ },
54
+ });
55
+ }
56
+
57
+ return Promise.reject();
58
+ });
59
+
60
+ baseProps = {
61
+ name: 'employee_id',
62
+ componentProps: {
63
+ name: 'ZdSelect',
64
+ dataText: 'name',
65
+ datasource: {
66
+ type: 'tek-rest',
67
+ route: '/zeedhi',
68
+ lazyLoad: false,
69
+ },
70
+ },
71
+ };
72
+ });
73
+
74
+ afterEach(() => {
75
+ httpSpy.mockClear();
76
+ });
77
+
78
+ describe('constructor()', () => {
79
+ it('should create new column with default values', () => {
80
+ const props: ITekGridColumn = {
81
+ name: 'employee_id',
82
+ };
83
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
84
+ const column = new TekGridColumn(props, grid);
85
+
86
+ expect(column.filterProps).toEqual([]);
87
+ expect(column.groupLabelForEmptyValue).toBe('');
88
+ expect(column.filterable).toBeTruthy();
89
+ expect(column.isVisible).toBeTruthy();
90
+ expect(column.storeData).toBeTruthy();
91
+ });
92
+
93
+ it('should create new column replacing default values', () => {
94
+ const filterProps: IFilterPropsComponent = {
95
+ name: 'name',
96
+ relation: 'AND' as IFilterRelation,
97
+ operation: 'CONTAINS' as IFilterOperation,
98
+ };
99
+ const groupLabelForEmptyValue = 'Empty';
100
+ const props: ITekGridColumn = {
101
+ filterProps,
102
+ groupLabelForEmptyValue,
103
+ name: 'employee_id',
104
+ isVisible: false,
105
+ filterable: false,
106
+ storeData: false,
107
+ };
108
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
109
+ const column = new TekGridColumn(props, grid);
110
+
111
+ expect(column.filterProps).toEqual(filterProps);
112
+ expect(column.groupLabelForEmptyValue).toBe(groupLabelForEmptyValue);
113
+ expect(column.filterable).toBeFalsy();
114
+ expect(column.isVisible).toBeFalsy();
115
+ expect(column.storeData).toBeFalsy();
116
+ });
117
+ });
118
+
119
+ describe('getLookupData()', () => {
120
+ it('should get lookup data', async () => {
121
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
122
+ const column = new TekGridColumn(baseProps, grid);
123
+
124
+ let data = column.getLookupData('name', 'employee 1');
125
+ expect(data).toEqual({});
126
+
127
+ await flushPromises();
128
+ data = column.getLookupData('name', 'employee 1');
129
+ expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
130
+ expect(httpSpy).toHaveBeenCalledTimes(1);
131
+ });
132
+
133
+ it('should get lookup data using memory', async () => {
134
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
135
+ baseProps.componentProps!.datasource = {
136
+ data: [
137
+ { id: 1, name: 'employee 1 memory', department: 1 },
138
+ { id: 2, name: 'employee 2 memory', department: 1 },
139
+ { id: 3, name: 'employee 3 memory', department: 1 },
140
+ { id: 4, name: 'employee 4 memory', department: 2 },
141
+ { id: 5, name: 'employee 5 memory', department: 2 },
142
+ { id: 15, name: 'employee 15 memory', department: 2 },
143
+ ],
144
+ };
145
+ const column = new TekGridColumn(baseProps, grid);
146
+
147
+ const data = column.getLookupData('name', 'employee 1 memory');
148
+ expect(data).toEqual({ id: 1, name: 'employee 1 memory', department: 1 });
149
+ expect(httpSpy).toHaveBeenCalledTimes(0);
150
+ });
151
+
152
+ it('should get lookup data using filter when storeData is false', async () => {
153
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
154
+ baseProps.storeData = false;
155
+ const column = new TekGridColumn(baseProps, grid);
156
+
157
+ let data = column.getLookupData('name', 'employee 1');
158
+ expect(data).toEqual({});
159
+
160
+ await flushPromises();
161
+ data = column.getLookupData('name', 'employee 1');
162
+ expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
163
+ expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
164
+ params: expect.objectContaining({
165
+ name: ['employee 1'],
166
+ }),
167
+ }));
168
+ });
169
+ });
170
+
171
+ describe('getBatchLookupData', () => {
172
+ it('when called, should lookup for a batch of values asynchonously, adding them to lookupData', async () => {
173
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
174
+ baseProps.storeData = false;
175
+ const column = new TekGridColumn(baseProps, grid);
176
+
177
+ const data = await column.getBatchLookupData('id', [1, 2]);
178
+ expect(data).toEqual([
179
+ { id: 1, name: 'employee 1', department: 1 },
180
+ { id: 2, name: 'employee 2', department: 1 },
181
+ ]);
182
+
183
+ expect(column.getLookupData('id', '1')).toEqual({ id: 1, name: 'employee 1', department: 1 });
184
+ expect(column.getLookupData('id', '2')).toEqual({ id: 2, name: 'employee 2', department: 1 });
185
+
186
+ expect(httpSpy).toHaveBeenCalledTimes(1);
187
+ });
188
+
189
+ it('when called with values that are already in lookupData, should not call datasource.get', async () => {
190
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
191
+ baseProps.storeData = false;
192
+ const column = new TekGridColumn(baseProps, grid);
193
+
194
+ column.lookupData = {
195
+ 1: { id: 1, name: 'employee 1', department: 1 },
196
+ };
197
+ (column as any).lookupDatasource?.data.push({ id: 2, name: 'employee 2', department: 1 });
198
+
199
+ const data = await column.getBatchLookupData('id', [1, 2]);
200
+ expect(data).toEqual([
201
+ { id: 1, name: 'employee 1', department: 1 },
202
+ { id: 2, name: 'employee 2', department: 1 },
203
+ ]);
204
+
205
+ expect(httpSpy).toHaveBeenCalledTimes(0);
206
+ });
207
+ });
208
+
209
+ describe('memorySearch()', () => {
210
+ it('should search in memory', async () => {
211
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
212
+ const column = new TekGridColumn(baseProps, grid);
213
+
214
+ let data = await column.memorySearch('employee 15');
215
+ expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
216
+ expect(httpSpy).toHaveBeenCalledTimes(1);
217
+
218
+ baseProps.componentProps!.dataText = ['id'];
219
+ const column2 = new TekGridColumn(baseProps, grid);
220
+
221
+ data = await column2.memorySearch('3');
222
+ expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
223
+ expect(httpSpy).toHaveBeenCalledTimes(2);
224
+ });
225
+
226
+ it('should not make request if data is already in memory', async () => {
227
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
228
+ const column = new TekGridColumn(baseProps, grid);
229
+
230
+ let data = await column.memorySearch('employee 15');
231
+ expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
232
+ expect(httpSpy).toHaveBeenCalledTimes(1);
233
+
234
+ data = await column.memorySearch('employee 2');
235
+ expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
236
+ expect(httpSpy).toHaveBeenCalledTimes(1);
237
+ });
238
+
239
+ it('should always make another request when storeData is false', async () => {
240
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
241
+ baseProps.storeData = false;
242
+ const column = new TekGridColumn(baseProps, grid);
243
+
244
+ let data = await column.memorySearch('employee 15');
245
+ expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
246
+ expect(httpSpy).toHaveBeenCalledTimes(1);
247
+
248
+ data = await column.memorySearch('employee 2');
249
+ expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
250
+ expect(httpSpy).toHaveBeenCalledTimes(2);
251
+
252
+ data = await column.memorySearch('employee 3');
253
+ expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
254
+ expect(httpSpy).toHaveBeenCalledTimes(3);
255
+ });
256
+
257
+ it('should throw error if column doesn\'t have a datasource', async () => {
258
+ baseProps = {
259
+ name: 'employee_id',
260
+ componentProps: {
261
+ name: 'ZdTextInput',
262
+ },
263
+ };
264
+ const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
265
+ const column = new TekGridColumn(baseProps, grid);
266
+
267
+ await expect(column.memorySearch('')).rejects.toThrow();
268
+ });
269
+ });
270
+ });