@zeedhi/teknisa-components-common 1.117.1 → 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 +43 -0
- package/dist/teknisa-components-common.js +3802 -0
- package/dist/teknisa-components-common.min.js +3802 -0
- package/dist/types/components/index.d.ts +7 -0
- package/{types → dist/types}/components/tek-breadcrumb-header/breadcrumb-header.d.ts +12 -12
- package/{types → dist/types}/components/tek-breadcrumb-header/interfaces.d.ts +6 -6
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/{types → dist/types}/components/tek-datasource/interfaces.d.ts +16 -16
- package/{types/components/tek-datasource/memory-datasource.d.ts → dist/types/components/tek-datasource/tek-memory-datasource.d.ts} +93 -100
- package/{types/components/tek-datasource/rest-datasource.d.ts → dist/types/components/tek-datasource/tek-rest-datasource.d.ts} +95 -103
- 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/{types → dist/types}/components/tek-grid/filter-helper.d.ts +7 -7
- package/{types → dist/types}/components/tek-grid/grid-filter-button.d.ts +29 -31
- 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/{types → dist/types}/components/tek-grid/layout-options.d.ts +39 -31
- package/{types/components/tek-grid/grid-column.d.ts → dist/types/components/tek-grid/tek-grid-column.d.ts} +42 -45
- package/{types/components/tek-grid/grid-columns-button-controller.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts} +8 -8
- package/{types/components/tek-grid/grid-columns-button.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts} +13 -12
- 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/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/button-option.d.ts +17 -16
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/index.d.ts +3 -3
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/multi-option.d.ts +12 -12
- 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/{types → dist/types}/components/tek-user-info/TekUserInfoController.d.ts +22 -21
- package/{types → dist/types}/components/tek-user-info/interfaces.d.ts +27 -28
- package/{types → dist/types}/components/tek-user-info/tek-user-info-list.d.ts +32 -31
- package/{types → dist/types}/components/tek-user-info/tek-user-info.d.ts +37 -38
- package/{types → dist/types}/error/delete-rows-error.d.ts +6 -6
- 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 +2 -0
- package/{types → dist/types}/utils/config/config.d.ts +7 -7
- 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/environments.json +14 -0
- package/package.json +26 -18
- package/src/components/index.ts +101 -0
- package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +29 -0
- package/src/components/tek-breadcrumb-header/interfaces.ts +7 -0
- 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 +2 -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/__helpers__/component-event-helper.ts +1 -1
- package/tests/__helpers__/get-child-helper.ts +1 -1
- package/tests/__helpers__/mock-created-helper.ts +1 -1
- package/tests/unit/components/crud/crud-button.spec.ts +1 -1
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +1 -11
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +5 -7
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +1 -1
- 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 +114 -239
- 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} +70 -30
- 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} +44 -2
- 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/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +1 -1
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +10 -14
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +4 -28
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +2 -2
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +17 -152
- package/tsconfig.build.json +7 -0
- package/coverage/clover.xml +0 -2007
- package/coverage/coverage-final.json +0 -48
- 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 -431
- 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__/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 -176
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +0 -121
- package/coverage/lcov.info +0 -3885
- package/dist/tek-components-common.esm.js +0 -4833
- package/dist/tek-components-common.umd.js +0 -4870
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -3377
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +0 -24
- package/types/components/crud/crud-add-button.d.ts +0 -38
- package/types/components/crud/crud-button.d.ts +0 -27
- package/types/components/crud/crud-cancel-button.d.ts +0 -28
- package/types/components/crud/crud-delete-button.d.ts +0 -42
- package/types/components/crud/crud-form.d.ts +0 -46
- package/types/components/crud/crud-save-button.d.ts +0 -24
- package/types/components/crud/interfaces.d.ts +0 -15
- package/types/components/index.d.ts +0 -41
- package/types/components/tek-card-title/card-title.d.ts +0 -14
- package/types/components/tek-card-title/interfaces.d.ts +0 -9
- package/types/components/tek-drag-grid/interfaces.d.ts +0 -7
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +0 -36
- package/types/components/tek-grid/grid.d.ts +0 -267
- package/types/components/tek-grid/interfaces.d.ts +0 -203
- package/types/components/tek-image/image.d.ts +0 -55
- package/types/components/tek-image/interfaces.d.ts +0 -12
- package/types/components/tek-iterable-carousel/interfaces.d.ts +0 -5
- package/types/components/tek-iterable-carousel/iterable-carousel.d.ts +0 -13
- package/types/components/tek-iterable-component-render/interfaces.d.ts +0 -3
- package/types/components/tek-iterable-component-render/iterable-component-render.d.ts +0 -10
- package/types/components/tek-loading/interfaces.d.ts +0 -6
- package/types/components/tek-loading/loading.d.ts +0 -24
- package/types/components/tek-notifications/interfaces.d.ts +0 -22
- package/types/components/tek-notifications/notifications.d.ts +0 -35
- package/types/components/tek-product-card/interfaces.d.ts +0 -19
- package/types/components/tek-product-card/product-card.d.ts +0 -66
- package/types/components/tek-tree-grid/interfaces.d.ts +0 -30
- package/types/components/tek-tree-grid/tree-grid.d.ts +0 -102
- package/types/error/incomplete-groups-error.d.ts +0 -8
- package/types/index.d.ts +0 -2
- package/types/utils/extract-properties.d.ts +0 -7
- package/types/utils/grid-base/export-options/interfaces.d.ts +0 -5
- package/types/utils/grid-base/grid-base.d.ts +0 -59
- package/types/utils/grid-base/grid-controller.d.ts +0 -27
- package/types/utils/index.d.ts +0 -6
- package/types/utils/report-filter/report-filter.d.ts +0 -12
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import { ListItem } from '@zeedhi/common';
|
|
2
2
|
import { Metadata } from '@zeedhi/core';
|
|
3
3
|
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
4
|
-
import { TekUserInfo, TekUserInfoList, ITekUserInfo } from '../../../../src';
|
|
4
|
+
import { TekUserInfo, TekUserInfoList, type ITekUserInfo } from '../../../../src';
|
|
5
5
|
import { mockCreated } from '../../../__helpers__/mock-created-helper';
|
|
6
6
|
|
|
7
7
|
function instantiateAndCreate(props: ITekUserInfo) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Button, ListItem, Modal, ModalService,
|
|
2
|
+
Button, ListItem, type Modal, ModalService,
|
|
3
3
|
} from '@zeedhi/common';
|
|
4
4
|
import { Metadata, Http } from '@zeedhi/core';
|
|
5
5
|
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
6
|
-
import { ITekUserInfo, TekUserInfo, TekUserInfoList } from '../../../../src';
|
|
6
|
+
import { type ITekUserInfo, TekUserInfo, TekUserInfoList } from '../../../../src';
|
|
7
7
|
import { mockCreated } from '../../../__helpers__/mock-created-helper';
|
|
8
8
|
|
|
9
9
|
function instantiateAndCreate(props: ITekUserInfo) {
|
|
@@ -84,14 +84,12 @@ describe('TekUserInfo', () => {
|
|
|
84
84
|
children: [
|
|
85
85
|
{
|
|
86
86
|
component: 'ZdHeader',
|
|
87
|
-
leftSlot: [
|
|
88
|
-
{
|
|
89
|
-
component: 'ZdTag',
|
|
90
|
-
children: [{ component: 'ZdImage', src: 'path' }],
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
87
|
rightSlot: [{ component: 'ZdModalCloseButton' }],
|
|
94
88
|
},
|
|
89
|
+
{
|
|
90
|
+
component: 'ZdTag',
|
|
91
|
+
children: [{ component: 'ZdImage', src: 'path' }],
|
|
92
|
+
},
|
|
95
93
|
{
|
|
96
94
|
component: 'ZdTabs',
|
|
97
95
|
tabs: [
|
|
@@ -152,14 +150,12 @@ describe('TekUserInfo', () => {
|
|
|
152
150
|
children: [
|
|
153
151
|
{
|
|
154
152
|
component: 'ZdHeader',
|
|
155
|
-
leftSlot: [
|
|
156
|
-
{
|
|
157
|
-
component: 'ZdTag',
|
|
158
|
-
children: [{ component: 'ZdImage', src: '' }],
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
153
|
rightSlot: [{ component: 'ZdModalCloseButton' }],
|
|
162
154
|
},
|
|
155
|
+
{
|
|
156
|
+
component: 'ZdTag',
|
|
157
|
+
children: [{ component: 'ZdImage', src: '' }],
|
|
158
|
+
},
|
|
163
159
|
{
|
|
164
160
|
component: 'ZdTabs',
|
|
165
161
|
tabs: [
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Button, Dropdown, Form, IButton, IForm, IModal, Modal, ModalService, Report, Search, Text, TextInput,
|
|
2
|
+
Button, Dropdown, Form, type IButton, type IForm, type IModal, Modal, ModalService, Report, Search, Text, TextInput,
|
|
3
3
|
} from '@zeedhi/common';
|
|
4
4
|
import {
|
|
5
|
-
Http, IDictionary, KeyMap, Metadata,
|
|
5
|
+
Http, type IDictionary, KeyMap, Metadata,
|
|
6
6
|
} from '@zeedhi/core';
|
|
7
7
|
import {
|
|
8
|
-
ITekGridFilterButton,
|
|
9
|
-
ITekTreeGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource, TekTreeGrid,
|
|
8
|
+
type ITekGridFilterButton,
|
|
9
|
+
type ITekTreeGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource, TekTreeGrid,
|
|
10
10
|
} from '../../../../src';
|
|
11
11
|
import { getChild, setClick } from '../../../__helpers__';
|
|
12
12
|
|
|
@@ -63,18 +63,6 @@ describe('TekTreeGrid', () => {
|
|
|
63
63
|
],
|
|
64
64
|
columnsButton: true,
|
|
65
65
|
columnsButtonIgnore: ['id'],
|
|
66
|
-
modalFilterProps: {
|
|
67
|
-
name: 'name',
|
|
68
|
-
height: 'auto',
|
|
69
|
-
persistent: true,
|
|
70
|
-
cssClass: '',
|
|
71
|
-
cssStyle: '',
|
|
72
|
-
dark: false,
|
|
73
|
-
draggable: false,
|
|
74
|
-
fullscreen: false,
|
|
75
|
-
dragHandle: '',
|
|
76
|
-
title: 'EXAMPLE',
|
|
77
|
-
},
|
|
78
66
|
});
|
|
79
67
|
expect(instance.title).toBe('title');
|
|
80
68
|
expect(instance.addButton).toBeTruthy();
|
|
@@ -88,18 +76,6 @@ describe('TekTreeGrid', () => {
|
|
|
88
76
|
expect(instance.columns[0]).toBeInstanceOf(TekGridColumn);
|
|
89
77
|
expect(instance.columnsButton).toBeTruthy();
|
|
90
78
|
expect(instance.columnsButtonIgnore).toEqual(['id']);
|
|
91
|
-
expect(instance.modalFilterProps).toEqual({
|
|
92
|
-
name: 'name',
|
|
93
|
-
height: 'auto',
|
|
94
|
-
persistent: true,
|
|
95
|
-
cssClass: '',
|
|
96
|
-
cssStyle: '',
|
|
97
|
-
dark: false,
|
|
98
|
-
draggable: false,
|
|
99
|
-
fullscreen: false,
|
|
100
|
-
dragHandle: '',
|
|
101
|
-
title: 'EXAMPLE',
|
|
102
|
-
});
|
|
103
79
|
});
|
|
104
80
|
|
|
105
81
|
it('should create toolbar and footer', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Button, IText, Text } from '@zeedhi/common';
|
|
2
|
-
import { ITekGridExportConfig, TekGrid } from '../../../../../src/components';
|
|
1
|
+
import { Button, type IText, Text } from '@zeedhi/common';
|
|
2
|
+
import { type ITekGridExportConfig, TekGrid } from '../../../../../src/components';
|
|
3
3
|
import { MultiOption } from '../../../../../src/utils';
|
|
4
4
|
|
|
5
5
|
describe('MultiOption', () => {
|