@zeedhi/teknisa-components-common 3.1.0 → 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.
- package/dist/teknisa-components-common.es.js +3536 -0
- package/dist/types/components/tek-breadcrumb-header/breadcrumb-header.d.ts +2 -2
- package/dist/types/components/tek-breadcrumb-header/interfaces.d.ts +1 -1
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +1 -21
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +6 -28
- package/dist/types/components/tek-grid/filter-helper.d.ts +2 -2
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +1 -0
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +8 -1
- package/dist/types/components/tek-grid/interfaces.d.ts +8 -1
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +19 -17
- package/dist/types/components/tek-grid/tek-grid-data-editor.d.ts +11 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +1 -1
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +8 -1
- package/dist/types/components/tek-grid/tek-grid.d.ts +22 -5
- package/dist/types/components/tek-loading/interfaces.d.ts +1 -1
- package/dist/types/components/tek-loading/loading.d.ts +1 -1
- package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +4 -4
- package/dist/types/utils/extract-properties/extract-properties.d.ts +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/report-filter/report-filter.d.ts +12 -0
- package/package.json +30 -12
- package/coverage/clover.xml +0 -6
- package/coverage/coverage-final.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -101
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +0 -100
- package/coverage/lcov-report/tests/__helpers__/create-component.ts.html +0 -109
- package/coverage/lcov-report/tests/__helpers__/find-component.ts.html +0 -139
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +0 -166
- package/coverage/lcov-report/tests/__helpers__/index.html +0 -221
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +0 -106
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +0 -121
- package/coverage/lcov-report/tests/__helpers__/spy-on-all-methods.ts.html +0 -223
- package/coverage/lcov.info +0 -0
- package/dist/teknisa-components-common.js +0 -3808
- package/dist/teknisa-components-common.min.js +0 -3808
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +0 -14
- package/environments.json +0 -26
- package/jest.config.cjs +0 -23
- package/src/components/index.ts +0 -101
- package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +0 -29
- package/src/components/tek-breadcrumb-header/interfaces.ts +0 -7
- package/src/components/tek-datasource/index.ts +0 -3
- package/src/components/tek-datasource/interfaces.ts +0 -36
- package/src/components/tek-datasource/tek-memory-datasource.ts +0 -314
- package/src/components/tek-datasource/tek-rest-datasource.ts +0 -224
- package/src/components/tek-grid/columns-searcher.ts +0 -22
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +0 -20
- package/src/components/tek-grid/filter-helper.ts +0 -20
- package/src/components/tek-grid/grid-filter-button.ts +0 -421
- package/src/components/tek-grid/grouped-data-manager.ts +0 -448
- package/src/components/tek-grid/grouped-data-navigator.ts +0 -66
- package/src/components/tek-grid/grouped-data-selector.ts +0 -40
- package/src/components/tek-grid/index.ts +0 -18
- package/src/components/tek-grid/interfaces.ts +0 -329
- package/src/components/tek-grid/keymap-grouped.ts +0 -20
- package/src/components/tek-grid/layout-options.ts +0 -248
- package/src/components/tek-grid/tek-grid-column.ts +0 -193
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +0 -28
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +0 -38
- package/src/components/tek-grid/tek-grid-controller.ts +0 -140
- package/src/components/tek-grid/tek-grid-events.ts +0 -105
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +0 -26
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +0 -3
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +0 -6
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +0 -85
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +0 -2
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +0 -365
- package/src/components/tek-grid/tek-grid.ts +0 -1122
- package/src/components/tek-loading/interfaces.ts +0 -7
- package/src/components/tek-loading/loading.ts +0 -27
- package/src/components/tek-user-info/TekUserInfoController.ts +0 -87
- package/src/components/tek-user-info/interfaces.ts +0 -21
- package/src/components/tek-user-info/tek-user-info-list.ts +0 -64
- package/src/components/tek-user-info/tek-user-info.ts +0 -337
- package/src/error/tek-grid-delete-rows-error.ts +0 -15
- package/src/error/teknisa-common-error.ts +0 -8
- package/src/utils/config/config.ts +0 -8
- package/src/utils/index.ts +0 -3
- package/src/utils/is-filled-object/is-filled-object.ts +0 -5
- package/src/utils/is-nil.ts +0 -3
- package/tests/__helpers__/component-event-helper.ts +0 -5
- package/tests/__helpers__/create-component.ts +0 -8
- package/tests/__helpers__/find-component.ts +0 -18
- package/tests/__helpers__/flush-promises-helper.ts +0 -3
- package/tests/__helpers__/get-child-helper.ts +0 -27
- package/tests/__helpers__/index.ts +0 -7
- package/tests/__helpers__/mock-created-helper.ts +0 -12
- package/tests/__helpers__/spy-on-all-methods.ts +0 -46
- package/tests/__mocks__/@zeedhi/core/i18n.js +0 -75
- package/tests/__mocks__/@zeedhi/core.js +0 -5
- package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +0 -43
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +0 -463
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +0 -362
- package/tests/unit/components/tek-grid/button-option.spec.ts +0 -49
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +0 -112
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +0 -90
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +0 -56
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +0 -842
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +0 -593
- package/tests/unit/components/tek-grid/grouped-data-navigator.spec.ts +0 -143
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +0 -136
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +0 -20
- package/tests/unit/components/tek-grid/layout-options.spec.ts +0 -1020
- package/tests/unit/components/tek-grid/tek-grid-column.spec.ts +0 -318
- package/tests/unit/components/tek-grid/tek-grid-columns-button.spec.ts +0 -229
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +0 -253
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +0 -186
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +0 -34
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +0 -897
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +0 -482
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +0 -422
- package/tests/unit/components/tek-loading/loading.spec.ts +0 -29
- package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +0 -220
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +0 -96
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +0 -442
- package/tests/unit/utils/mock-console.ts +0 -18
- package/tests/unit/utils/setup.ts +0 -5
- package/tsconfig.build.json +0 -7
- package/tsconfig.eslint.json +0 -9
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { Http, Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
2
|
-
import {
|
|
3
|
-
IFilterOperation,
|
|
4
|
-
IFilterPropsComponent,
|
|
5
|
-
IFilterRelation,
|
|
6
|
-
ITekGridColumn,
|
|
7
|
-
TekGrid,
|
|
8
|
-
TekGridColumn,
|
|
9
|
-
} from '../../../../src';
|
|
10
|
-
import { flushPromises } from '../../../__helpers__';
|
|
11
|
-
|
|
12
|
-
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
13
|
-
|
|
14
|
-
describe('TekGridColumn', () => {
|
|
15
|
-
let baseProps: ITekGridColumn;
|
|
16
|
-
let httpSpy: jest.SpyInstance;
|
|
17
|
-
|
|
18
|
-
beforeAll(() => {
|
|
19
|
-
Loader.setBuilder(new SimpleControllerBuilder());
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
httpSpy = jest.spyOn(Http, 'get').mockImplementation((url: string) => {
|
|
24
|
-
if (url === '/zeedhi') {
|
|
25
|
-
return Promise.resolve({
|
|
26
|
-
data: {
|
|
27
|
-
data: [
|
|
28
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
29
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
30
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
31
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
32
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
33
|
-
{ id: 15, name: 'employee 15', department: 2 },
|
|
34
|
-
],
|
|
35
|
-
pagination: {
|
|
36
|
-
page: 1,
|
|
37
|
-
total: 5,
|
|
38
|
-
limit: 15,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (url === '/grid') {
|
|
45
|
-
return Promise.resolve({
|
|
46
|
-
data: {
|
|
47
|
-
data: [
|
|
48
|
-
{ id: 1, employee_id: 1, department: 1 },
|
|
49
|
-
{ id: 2, employee_id: 2, department: 1 },
|
|
50
|
-
{ id: 3, employee_id: 3, department: 1 },
|
|
51
|
-
],
|
|
52
|
-
pagination: {
|
|
53
|
-
page: 1,
|
|
54
|
-
total: 5,
|
|
55
|
-
limit: 15,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return Promise.reject();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
baseProps = {
|
|
65
|
-
name: 'employee_id',
|
|
66
|
-
componentProps: {
|
|
67
|
-
name: 'ZdSelect',
|
|
68
|
-
dataText: 'name',
|
|
69
|
-
datasource: {
|
|
70
|
-
type: 'tek-rest',
|
|
71
|
-
route: '/zeedhi',
|
|
72
|
-
lazyLoad: false,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
httpSpy.mockClear();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('constructor()', () => {
|
|
83
|
-
it('should create new column with default values', () => {
|
|
84
|
-
const props: ITekGridColumn = {
|
|
85
|
-
name: 'employee_id',
|
|
86
|
-
};
|
|
87
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
88
|
-
const column = new TekGridColumn(props, grid);
|
|
89
|
-
|
|
90
|
-
expect(column.filterProps).toEqual([]);
|
|
91
|
-
expect(column.groupLabelForEmptyValue).toBe('');
|
|
92
|
-
expect(column.filterable).toBeTruthy();
|
|
93
|
-
expect(column.isVisible).toBeTruthy();
|
|
94
|
-
expect(column.storeData).toBeTruthy();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should create new column replacing default values', () => {
|
|
98
|
-
const filterProps: IFilterPropsComponent = {
|
|
99
|
-
name: 'name',
|
|
100
|
-
relation: 'AND' as IFilterRelation,
|
|
101
|
-
operation: 'CONTAINS' as IFilterOperation,
|
|
102
|
-
};
|
|
103
|
-
const groupLabelForEmptyValue = 'Empty';
|
|
104
|
-
const props: ITekGridColumn = {
|
|
105
|
-
filterProps,
|
|
106
|
-
groupLabelForEmptyValue,
|
|
107
|
-
name: 'employee_id',
|
|
108
|
-
isVisible: false,
|
|
109
|
-
filterable: false,
|
|
110
|
-
storeData: false,
|
|
111
|
-
};
|
|
112
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
113
|
-
const column = new TekGridColumn(props, grid);
|
|
114
|
-
|
|
115
|
-
expect(column.filterProps).toEqual(filterProps);
|
|
116
|
-
expect(column.groupLabelForEmptyValue).toBe(groupLabelForEmptyValue);
|
|
117
|
-
expect(column.filterable).toBeFalsy();
|
|
118
|
-
expect(column.isVisible).toBeFalsy();
|
|
119
|
-
expect(column.storeData).toBeFalsy();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('getLookupData()', () => {
|
|
124
|
-
it('should get lookup data', async () => {
|
|
125
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
126
|
-
grid.onCreated();
|
|
127
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
128
|
-
column.initialize();
|
|
129
|
-
|
|
130
|
-
let data = column.getLookupData('name', 'employee 1');
|
|
131
|
-
setTimeout(async () => {
|
|
132
|
-
expect(data).toEqual({});
|
|
133
|
-
|
|
134
|
-
await flushPromises();
|
|
135
|
-
data = column.getLookupData('name', 'employee 1');
|
|
136
|
-
expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
|
|
137
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
138
|
-
}, 500);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should get lookup data using memory', async () => {
|
|
142
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
143
|
-
baseProps.componentProps!.datasource = {
|
|
144
|
-
data: [
|
|
145
|
-
{ id: 1, name: 'employee 1 memory', department: 1 },
|
|
146
|
-
{ id: 2, name: 'employee 2 memory', department: 1 },
|
|
147
|
-
{ id: 3, name: 'employee 3 memory', department: 1 },
|
|
148
|
-
{ id: 4, name: 'employee 4 memory', department: 2 },
|
|
149
|
-
{ id: 5, name: 'employee 5 memory', department: 2 },
|
|
150
|
-
{ id: 15, name: 'employee 15 memory', department: 2 },
|
|
151
|
-
],
|
|
152
|
-
};
|
|
153
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
154
|
-
|
|
155
|
-
const data = column.getLookupData('name', 'employee 1 memory');
|
|
156
|
-
expect(data).toEqual({ id: 1, name: 'employee 1 memory', department: 1 });
|
|
157
|
-
expect(httpSpy).toHaveBeenCalledTimes(0);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should get lookup data using filter when storeData is false', async () => {
|
|
161
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
162
|
-
grid.onCreated();
|
|
163
|
-
baseProps.storeData = false;
|
|
164
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
165
|
-
column.initialize();
|
|
166
|
-
|
|
167
|
-
let data = column.getLookupData('name', 'employee 1');
|
|
168
|
-
setTimeout(async () => {
|
|
169
|
-
expect(data).toEqual({});
|
|
170
|
-
|
|
171
|
-
await flushPromises();
|
|
172
|
-
data = column.getLookupData('name', 'employee 1');
|
|
173
|
-
expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
|
|
174
|
-
expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
|
|
175
|
-
params: expect.objectContaining({
|
|
176
|
-
name: ['employee 1'],
|
|
177
|
-
}),
|
|
178
|
-
}));
|
|
179
|
-
}, 500);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('getBatchLookupData', () => {
|
|
184
|
-
it('when called, should lookup for a batch of values asynchonously, adding them to lookupData', async () => {
|
|
185
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
186
|
-
baseProps.storeData = false;
|
|
187
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
188
|
-
|
|
189
|
-
const data = await column.getBatchLookupData('id', [1, 2]);
|
|
190
|
-
expect(data).toEqual([
|
|
191
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
192
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
193
|
-
]);
|
|
194
|
-
|
|
195
|
-
expect(column.getLookupData('id', '1')).toEqual({ id: 1, name: 'employee 1', department: 1 });
|
|
196
|
-
expect(column.getLookupData('id', '2')).toEqual({ id: 2, name: 'employee 2', department: 1 });
|
|
197
|
-
|
|
198
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('when called with values that are already in lookupData, should not call datasource.get', async () => {
|
|
202
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
203
|
-
baseProps.storeData = false;
|
|
204
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
205
|
-
|
|
206
|
-
column.lookupData = {
|
|
207
|
-
1: { id: 1, name: 'employee 1', department: 1 },
|
|
208
|
-
};
|
|
209
|
-
(column as any).lookupDatasource?.data.push({ id: 2, name: 'employee 2', department: 1 });
|
|
210
|
-
|
|
211
|
-
const data = await column.getBatchLookupData('id', [1, 2]);
|
|
212
|
-
expect(data).toEqual([
|
|
213
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
214
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
215
|
-
]);
|
|
216
|
-
|
|
217
|
-
expect(httpSpy).toHaveBeenCalledTimes(0);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe('memorySearch()', () => {
|
|
222
|
-
it('should search in memory', async () => {
|
|
223
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
224
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
225
|
-
|
|
226
|
-
let data = await column.memorySearch('employee 15');
|
|
227
|
-
expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
|
|
228
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
229
|
-
|
|
230
|
-
baseProps.componentProps!.dataText = ['id'];
|
|
231
|
-
const column2 = new TekGridColumn(baseProps, grid);
|
|
232
|
-
|
|
233
|
-
data = await column2.memorySearch('3');
|
|
234
|
-
expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
|
|
235
|
-
expect(httpSpy).toHaveBeenCalledTimes(2);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('should not make request if data is already in memory', async () => {
|
|
239
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
240
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
241
|
-
|
|
242
|
-
let data = await column.memorySearch('employee 15');
|
|
243
|
-
expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
|
|
244
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
245
|
-
|
|
246
|
-
data = await column.memorySearch('employee 2');
|
|
247
|
-
expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
|
|
248
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('should always make another request when storeData is false', async () => {
|
|
252
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
253
|
-
baseProps.storeData = false;
|
|
254
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
255
|
-
|
|
256
|
-
let data = await column.memorySearch('employee 15');
|
|
257
|
-
expect(data).toEqual([{ id: 15, name: 'employee 15', department: 2 }]);
|
|
258
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
259
|
-
|
|
260
|
-
data = await column.memorySearch('employee 2');
|
|
261
|
-
expect(data).toEqual([{ id: 2, name: 'employee 2', department: 1 }]);
|
|
262
|
-
expect(httpSpy).toHaveBeenCalledTimes(2);
|
|
263
|
-
|
|
264
|
-
data = await column.memorySearch('employee 3');
|
|
265
|
-
expect(data).toEqual([{ id: 3, name: 'employee 3', department: 1 }]);
|
|
266
|
-
expect(httpSpy).toHaveBeenCalledTimes(3);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('should throw error if column doesn\'t have a datasource', async () => {
|
|
270
|
-
baseProps = {
|
|
271
|
-
name: 'employee_id',
|
|
272
|
-
componentProps: {
|
|
273
|
-
name: 'ZdTextInput',
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
277
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
278
|
-
|
|
279
|
-
await expect(column.memorySearch('')).rejects.toThrow();
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
describe('change grouping', () => {
|
|
284
|
-
beforeEach(() => {
|
|
285
|
-
jest.useFakeTimers();
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('when grouped property changes, should call grid updateGrouping', () => {
|
|
289
|
-
const grid = { updateGrouping: jest.fn() } as any as TekGrid;
|
|
290
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
291
|
-
column.grouped = true;
|
|
292
|
-
|
|
293
|
-
jest.runAllTimers();
|
|
294
|
-
|
|
295
|
-
expect(grid.updateGrouping).toHaveBeenCalled();
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('when aggregation property changes, should call grid updateGrouping', () => {
|
|
299
|
-
const grid = { updateGrouping: jest.fn() } as any as TekGrid;
|
|
300
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
301
|
-
column.aggregation = 'COUNT';
|
|
302
|
-
|
|
303
|
-
jest.runAllTimers();
|
|
304
|
-
|
|
305
|
-
expect(grid.updateGrouping).toHaveBeenCalled();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('when groupOpened property changes, should call grid updateGrouping', () => {
|
|
309
|
-
const grid = { updateGrouping: jest.fn() } as any as TekGrid;
|
|
310
|
-
const column = new TekGridColumn(baseProps, grid);
|
|
311
|
-
column.groupOpened = true;
|
|
312
|
-
|
|
313
|
-
jest.runAllTimers();
|
|
314
|
-
|
|
315
|
-
expect(grid.updateGrouping).toHaveBeenCalled();
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
});
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { I18n, Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
2
|
-
import { Grid, Checkbox } from '@zeedhi/common';
|
|
3
|
-
import { TekGrid, TekGridColumnsButton, TekGridColumnsButtonController, ITekGridProps } from '../../../../src';
|
|
4
|
-
|
|
5
|
-
const setupInstance = (props: Partial<ITekGridProps> = {}) => {
|
|
6
|
-
const instance = new TekGrid({
|
|
7
|
-
name: 'Grid',
|
|
8
|
-
component: 'TekGrid',
|
|
9
|
-
columns: [
|
|
10
|
-
{ name: 'first' },
|
|
11
|
-
{ name: 'second' },
|
|
12
|
-
{ name: 'third' },
|
|
13
|
-
],
|
|
14
|
-
datasource: {
|
|
15
|
-
limit: 2,
|
|
16
|
-
page: 1,
|
|
17
|
-
data: [
|
|
18
|
-
{ id: 1 },
|
|
19
|
-
{ id: 2 },
|
|
20
|
-
{ id: 3 },
|
|
21
|
-
{ id: 4 },
|
|
22
|
-
{ id: 5 },
|
|
23
|
-
{ id: 6 },
|
|
24
|
-
{ id: 7 },
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
...props,
|
|
28
|
-
});
|
|
29
|
-
const elem = document.createElement('DIV');
|
|
30
|
-
instance.onCreated();
|
|
31
|
-
instance.onMounted(elem);
|
|
32
|
-
|
|
33
|
-
return instance;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
describe('TekGridColumnsButton', () => {
|
|
37
|
-
beforeAll(() => {
|
|
38
|
-
Loader.setBuilder(new SimpleControllerBuilder());
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('getAggregationSelectData', () => {
|
|
42
|
-
it('should get aggregation data', () => {
|
|
43
|
-
let I18Called = false;
|
|
44
|
-
const spy = jest.spyOn(I18n, 'translate').mockImplementation((code: string | string[]) => {
|
|
45
|
-
I18Called = true;
|
|
46
|
-
if (Array.isArray(code)) return code[0];
|
|
47
|
-
return code;
|
|
48
|
-
});
|
|
49
|
-
const grid = setupInstance({
|
|
50
|
-
name: 'grid-1',
|
|
51
|
-
component: 'TekGrid',
|
|
52
|
-
});
|
|
53
|
-
const instance = new TekGridColumnsButton({
|
|
54
|
-
name: 'columns-button-1',
|
|
55
|
-
component: 'TekGridColumnsButton',
|
|
56
|
-
parent: grid,
|
|
57
|
-
});
|
|
58
|
-
instance.onCreated();
|
|
59
|
-
let data = instance.getAggregationSelectData();
|
|
60
|
-
expect(data).toEqual([
|
|
61
|
-
{ text: 'TEKGRID_AGGREGATION_SUM', value: 'SUM' },
|
|
62
|
-
{ text: 'TEKGRID_AGGREGATION_MIN', value: 'MIN' },
|
|
63
|
-
{ text: 'TEKGRID_AGGREGATION_MAX', value: 'MAX' },
|
|
64
|
-
{ text: 'TEKGRID_AGGREGATION_AVG', value: 'AVG' },
|
|
65
|
-
{ text: 'TEKGRID_AGGREGATION_COUNT', value: 'COUNT' },
|
|
66
|
-
]);
|
|
67
|
-
expect(I18Called).toBeTruthy();
|
|
68
|
-
I18Called = false;
|
|
69
|
-
data = instance.getAggregationSelectData();
|
|
70
|
-
expect(I18Called).toBeFalsy();
|
|
71
|
-
spy.mockClear();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('controller', () => {
|
|
76
|
-
it('should create component controller', () => {
|
|
77
|
-
const checkbox = new Checkbox({
|
|
78
|
-
name: 'checkbox',
|
|
79
|
-
component: 'ZdCheckbox',
|
|
80
|
-
value: false,
|
|
81
|
-
});
|
|
82
|
-
const iterable = new Grid({
|
|
83
|
-
name: 'iterable',
|
|
84
|
-
component: 'ZdIterable',
|
|
85
|
-
columns: [
|
|
86
|
-
{
|
|
87
|
-
name: 'id',
|
|
88
|
-
grouped: false,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
const grid = setupInstance({
|
|
93
|
-
name: 'grid-1',
|
|
94
|
-
component: 'TekGrid',
|
|
95
|
-
parent: iterable,
|
|
96
|
-
});
|
|
97
|
-
const instance = new TekGridColumnsButton({
|
|
98
|
-
name: 'columns-button-2',
|
|
99
|
-
component: 'TekGridColumnsButton',
|
|
100
|
-
parent: grid,
|
|
101
|
-
});
|
|
102
|
-
instance.onCreated();
|
|
103
|
-
expect(instance.controller).toBeInstanceOf(TekGridColumnsButtonController);
|
|
104
|
-
expect(iterable.columns[0].isVisible).toBeTruthy();
|
|
105
|
-
instance.controller.showHideTekColumn(iterable.columns[0], { component: checkbox });
|
|
106
|
-
expect(iterable.columns[0].isVisible).toBeFalsy();
|
|
107
|
-
|
|
108
|
-
(iterable.columns[0] as any).grouped = true;
|
|
109
|
-
iterable.columns[0].isVisible = false;
|
|
110
|
-
instance.controller.showHideTekColumn(iterable.columns[0], { component: checkbox });
|
|
111
|
-
expect(iterable.columns[0].isVisible).toBeFalsy();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('changeGroupedColumn', () => {
|
|
115
|
-
const grid = setupInstance({
|
|
116
|
-
name: 'grid-2',
|
|
117
|
-
component: 'TekGrid',
|
|
118
|
-
columns: [
|
|
119
|
-
{
|
|
120
|
-
name: 'id',
|
|
121
|
-
label: 'id',
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'name',
|
|
125
|
-
label: 'name',
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'department',
|
|
129
|
-
label: 'department',
|
|
130
|
-
grouped: true,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
datasource: {
|
|
134
|
-
uniqueKey: 'id',
|
|
135
|
-
order: ['name.asc'],
|
|
136
|
-
data: [
|
|
137
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
138
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
139
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
140
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
141
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
const instance = new TekGridColumnsButton({
|
|
146
|
-
name: 'columns-button-3',
|
|
147
|
-
component: 'TekGridColumnsButton',
|
|
148
|
-
parent: grid,
|
|
149
|
-
});
|
|
150
|
-
instance.onCreated();
|
|
151
|
-
expect(grid.columns[0].grouped).toBeFalsy();
|
|
152
|
-
instance.controller.changeGroupedColumn(grid.columns[0], {
|
|
153
|
-
component: {
|
|
154
|
-
value: true,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
expect(grid.columns[0].grouped).toBeTruthy();
|
|
158
|
-
instance.controller.changeGroupedColumn(grid.columns[0], {
|
|
159
|
-
component: {
|
|
160
|
-
value: false,
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
expect(grid.columns[0].grouped).toBeFalsy();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('changeAggregationColumn', () => {
|
|
167
|
-
const grid = setupInstance({
|
|
168
|
-
name: 'grid-2',
|
|
169
|
-
component: 'TekGrid',
|
|
170
|
-
columns: [
|
|
171
|
-
{
|
|
172
|
-
name: 'id',
|
|
173
|
-
label: 'id',
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: 'name',
|
|
177
|
-
label: 'name',
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: 'department',
|
|
181
|
-
label: 'department',
|
|
182
|
-
grouped: true,
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
datasource: {
|
|
186
|
-
uniqueKey: 'id',
|
|
187
|
-
order: ['name.asc'],
|
|
188
|
-
data: [
|
|
189
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
190
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
191
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
192
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
193
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
const spy = jest.spyOn(grid, 'changeLayout');
|
|
198
|
-
const instance = new TekGridColumnsButton({
|
|
199
|
-
name: 'columns-button-4',
|
|
200
|
-
component: 'TekGridColumnsButton',
|
|
201
|
-
parent: grid,
|
|
202
|
-
});
|
|
203
|
-
instance.onCreated();
|
|
204
|
-
expect(grid.columns[0].aggregation).toBeUndefined();
|
|
205
|
-
expect(spy).toBeCalledTimes(0);
|
|
206
|
-
instance.controller.changeAggregationColumn(grid.columns[0], {
|
|
207
|
-
component: {
|
|
208
|
-
value: 'COUNT',
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
expect(spy).toBeCalledTimes(1);
|
|
212
|
-
instance.controller.changeAggregationColumn(grid.columns[0], {
|
|
213
|
-
component: {
|
|
214
|
-
value: 'COUNT',
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
expect(spy).toBeCalledTimes(1);
|
|
218
|
-
expect(grid.columns[0].aggregation).toBe('COUNT');
|
|
219
|
-
instance.controller.changeAggregationColumn(grid.columns[0], {
|
|
220
|
-
component: {
|
|
221
|
-
value: null,
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
expect(grid.columns[0].aggregation).toBeUndefined();
|
|
225
|
-
expect(spy).toBeCalledTimes(2);
|
|
226
|
-
spy.mockClear();
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|