@zeedhi/teknisa-components-common 3.0.0 → 3.0.1
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/.package.json +4 -1
- package/dist/teknisa-components-common.js +3722 -32
- package/dist/teknisa-components-common.min.js +3722 -32
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
- package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
- package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
- package/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
- package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
- package/dist/types/components/tek-grid/index.d.ts +18 -0
- package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
- package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
- package/dist/types/components/tek-grid/layout-options.d.ts +39 -0
- package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
- package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
- package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
- package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
- package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
- package/dist/types/error/teknisa-common-error.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/config/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
- package/dist/types/utils/is-nil.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/index.ts +5 -12
- package/src/components/tek-datasource/index.ts +3 -0
- package/src/components/tek-datasource/interfaces.ts +36 -0
- package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
- package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
- package/src/components/tek-grid/columns-searcher.ts +22 -0
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
- package/src/components/tek-grid/filter-helper.ts +20 -0
- package/src/components/tek-grid/grid-filter-button.ts +419 -0
- package/src/components/tek-grid/grouped-data-manager.ts +448 -0
- package/src/components/tek-grid/grouped-data-selector.ts +40 -0
- package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
- package/src/components/tek-grid/index.ts +18 -0
- package/src/components/tek-grid/interfaces.ts +329 -0
- package/src/components/tek-grid/keymap-grouped.ts +20 -0
- package/src/components/tek-grid/layout-options.ts +248 -0
- package/src/components/tek-grid/tek-grid-column.ts +193 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
- package/src/components/tek-grid/tek-grid-controller.ts +140 -0
- package/src/components/tek-grid/tek-grid-events.ts +105 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
- package/src/components/tek-grid/tek-grid.ts +1118 -0
- package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
- package/src/components/tek-user-info/interfaces.ts +21 -0
- package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
- package/src/components/tek-user-info/tek-user-info.ts +337 -0
- package/src/error/tek-grid-delete-rows-error.ts +15 -0
- package/src/error/teknisa-common-error.ts +8 -0
- package/src/index.ts +1 -0
- package/src/utils/config/config.ts +8 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/is-filled-object/is-filled-object.ts +5 -0
- package/src/utils/is-nil.ts +3 -0
- package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +110 -241
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
- package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +77 -35
- package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
- package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +48 -6
- package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
- package/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,422 @@
|
|
|
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,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delete rows error
|
|
3
|
-
*/
|
|
4
|
-
export class TekGridDeleteRowsError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super('TekGrid can\'t automatically delete rows when selectAllPages property is true.'
|
|
7
|
-
+ ' You should delete them manually using the beforeDelete event and preventing'
|
|
8
|
-
+ ' the default execution');
|
|
9
|
-
this.name = 'TekGridDeleteRowsError';
|
|
10
|
-
}
|
|
11
|
-
}
|