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