@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,27 +0,0 @@
|
|
|
1
|
-
import type { IComponent } from '@zeedhi/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Search for a component inside an array of children
|
|
5
|
-
*
|
|
6
|
-
* The children array can be either an array of IComponent or an array of Component
|
|
7
|
-
*/
|
|
8
|
-
const getChild = <T extends IComponent>(children: any[], name: string): T => {
|
|
9
|
-
let found: any;
|
|
10
|
-
|
|
11
|
-
children.forEach((child) => {
|
|
12
|
-
if (child.name === name) {
|
|
13
|
-
found = child;
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (child.children && child.children.length > 0) {
|
|
18
|
-
const result = getChild<T>(child.children, name) as T;
|
|
19
|
-
|
|
20
|
-
if (result) found = result;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return found;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { getChild };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './component-event-helper';
|
|
2
|
-
export * from './get-child-helper';
|
|
3
|
-
export * from './mock-created-helper';
|
|
4
|
-
export * from './spy-on-all-methods';
|
|
5
|
-
export * from './flush-promises-helper';
|
|
6
|
-
export * from './create-component';
|
|
7
|
-
export * from './find-component';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ComponentRender } from '@zeedhi/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Function used to spy on a class' onCreated and always assign the componentId as 1
|
|
5
|
-
*/
|
|
6
|
-
const mockCreated = <T extends ComponentRender>(component: T, prototype: any) => {
|
|
7
|
-
jest.spyOn(prototype, 'onCreated').mockImplementation(() => {
|
|
8
|
-
component.componentId = 1;
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { mockCreated };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { IDictionary } from "@zeedhi/core";
|
|
2
|
-
|
|
3
|
-
// add a spy on all methods from a class prototype
|
|
4
|
-
const spyOnAllMethods = (
|
|
5
|
-
prototype: any,
|
|
6
|
-
mockImplementations: IDictionary = {},
|
|
7
|
-
alreadySpiedMethods: Set<string> = new Set(),
|
|
8
|
-
depth: number = 0,
|
|
9
|
-
maxDepth: number = 10 // Safety limit
|
|
10
|
-
) => {
|
|
11
|
-
// Safety check against infinite recursion
|
|
12
|
-
if (depth > maxDepth || prototype === null || prototype === Object.prototype) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const methods = Object.getOwnPropertyNames(prototype).filter(
|
|
17
|
-
(prop) => typeof prototype[prop] === 'function' && prop !== 'constructor'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const spyObj: IDictionary<jest.SpyInstance> = {};
|
|
21
|
-
|
|
22
|
-
methods.forEach((method) => {
|
|
23
|
-
if (!alreadySpiedMethods.has(method)) {
|
|
24
|
-
const mockImplementation = mockImplementations[method] || jest.fn();
|
|
25
|
-
spyObj[method] = jest.spyOn(prototype, method).mockImplementation(mockImplementation);
|
|
26
|
-
alreadySpiedMethods.add(method);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Get the parent prototype carefully
|
|
31
|
-
const parentPrototype = Object.getPrototypeOf(prototype);
|
|
32
|
-
if (parentPrototype && parentPrototype !== prototype) { // Additional check to prevent cycles
|
|
33
|
-
const parentSpyObj = spyOnAllMethods(
|
|
34
|
-
parentPrototype,
|
|
35
|
-
mockImplementations,
|
|
36
|
-
alreadySpiedMethods,
|
|
37
|
-
depth + 1,
|
|
38
|
-
maxDepth
|
|
39
|
-
);
|
|
40
|
-
Object.assign(spyObj, parentSpyObj);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return spyObj;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { spyOnAllMethods };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock for @zeedhi/core I18n API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const words = {
|
|
6
|
-
TEKGRID_CONTAINS: 'contains',
|
|
7
|
-
TEKGRID_NOT_CONTAINS: 'does not contain',
|
|
8
|
-
TEKGRID_EQUALS: 'is equal to',
|
|
9
|
-
TEKGRID_NOT_EQUALS: 'is different from',
|
|
10
|
-
TEKGRID_GREATER_THAN: 'is greater than',
|
|
11
|
-
TEKGRID_LESS_THAN: 'is less than',
|
|
12
|
-
TEKGRID_GREATER_THAN_EQUALS: 'is greater or equals to',
|
|
13
|
-
TEKGRID_LESS_THAN_EQUALS: 'is less or equals to',
|
|
14
|
-
TEKGRID_IN: 'is in',
|
|
15
|
-
TEKGRID_NOT_IN: 'is not in',
|
|
16
|
-
TEKGRID_BETWEEN: 'is between',
|
|
17
|
-
TEKGRID_AND: 'and',
|
|
18
|
-
TEKGRID_OR: 'or',
|
|
19
|
-
TEKGRID_ADD: 'Add',
|
|
20
|
-
TEKGRID_DELETE: 'Delete',
|
|
21
|
-
TEKGRID_REFRESH: 'Refresh',
|
|
22
|
-
TEKGRID_COLUMNS: 'Columns',
|
|
23
|
-
TEKGRID_SAVE: 'Save',
|
|
24
|
-
TEKGRID_CANCEL: 'Cancel',
|
|
25
|
-
TEKGRID_FILTER: 'Filter',
|
|
26
|
-
TEKGRID_MULTIPLE_VALUE_HINT: 'Separate values using ";"',
|
|
27
|
-
TEKGRID_EXPORT: 'Export',
|
|
28
|
-
TEKGRID_EXPORT_AS: 'Export as {{type}}',
|
|
29
|
-
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
30
|
-
TEKGRID_COLUMN_GROUPED: 'Grouped',
|
|
31
|
-
TEKGRID_COLUMN_AGGREGATION: 'Aggregation',
|
|
32
|
-
TEKGRID_AGGREGATION_SUM: 'Sum',
|
|
33
|
-
TEKGRID_AGGREGATION_AVG: 'Average',
|
|
34
|
-
TEKGRID_AGGREGATION_MAX: 'Maximum',
|
|
35
|
-
TEKGRID_AGGREGATION_MIN: 'Minimum',
|
|
36
|
-
TEKGRID_AGGREGATION_COUNT: 'Count',
|
|
37
|
-
NO_NOTIFICATIONS: 'No Notifications',
|
|
38
|
-
MARK_ALL_AS_READ: 'Mark all as read',
|
|
39
|
-
NOTIFICATIONS: 'Notifications',
|
|
40
|
-
SEE_ALL_NOTIFICATIONS: 'See all notifications',
|
|
41
|
-
UNAVAILABLE_IMAGE: 'Unavailable image',
|
|
42
|
-
REFRESH: 'Refresh',
|
|
43
|
-
ACTIONS: 'Actions',
|
|
44
|
-
FILTER: 'Filter',
|
|
45
|
-
LAYOUT: 'Layout: ',
|
|
46
|
-
NEW_LAYOUT: 'New layout',
|
|
47
|
-
DEFAULT_LAYOUT: 'Default',
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const notImplemented = (name, isMethod = true) => {
|
|
51
|
-
const member = isMethod ? `I18n.${name}() method` : `I18n.${name} property`;
|
|
52
|
-
throw new Error(`The ${member} is not yet implemented/mocked by the mock in 'tests/__mocks__/@zeedhi/core/i18n.ts'.`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const mock = {
|
|
56
|
-
translate: (value, variables) => {
|
|
57
|
-
let result = words[value] || value;
|
|
58
|
-
const keys = variables ? Object.keys(variables) : undefined;
|
|
59
|
-
if (keys) {
|
|
60
|
-
keys.forEach((key) => {
|
|
61
|
-
result = result.replace(`{{${key}}}`, variables[key]);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return result;
|
|
66
|
-
},
|
|
67
|
-
registerChangeListener: () => notImplemented('registerChangeListener'),
|
|
68
|
-
unregisterChangeListener: () => notImplemented('unregisterChangeListener'),
|
|
69
|
-
init: () => notImplemented('init'),
|
|
70
|
-
changeLanguage: () => notImplemented('changeLanguage'),
|
|
71
|
-
get instance() { return { language: 'en-US'} },
|
|
72
|
-
set instance(_value) { notImplemented('instance setter') },
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = mock;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BreadcrumbHeader } from '../../../../src';
|
|
2
|
-
import { Image } from '@zeedhi/common';
|
|
3
|
-
|
|
4
|
-
describe('BreadcrumbHeader', () => {
|
|
5
|
-
describe('constructor()', () => {
|
|
6
|
-
it('should create new BreadcrumbHeader with default values', () => {
|
|
7
|
-
const instance = new BreadcrumbHeader({
|
|
8
|
-
name: 'BreadcrumbHeader',
|
|
9
|
-
component: 'TekBreadcrumbHeader',
|
|
10
|
-
title: '',
|
|
11
|
-
breadcrumb: {
|
|
12
|
-
name: 'breadcrumb',
|
|
13
|
-
component: 'ZdBreadcrumb',
|
|
14
|
-
divider: '>',
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
expect(instance.title).toBe('');
|
|
18
|
-
expect(instance.rightSlot).toStrictEqual([]);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should create new BreadcrumbHeader with rightSlot values', () => {
|
|
22
|
-
const image = new Image({
|
|
23
|
-
name: 'image',
|
|
24
|
-
component: 'tekImage',
|
|
25
|
-
src: '/img/zeedhi.svg',
|
|
26
|
-
to: 'google.com.br',
|
|
27
|
-
});
|
|
28
|
-
const instance = new BreadcrumbHeader({
|
|
29
|
-
name: 'BreadcrumbHeader',
|
|
30
|
-
component: 'TekBreadcrumbHeader',
|
|
31
|
-
title: '',
|
|
32
|
-
breadcrumb: {
|
|
33
|
-
name: 'breadcrumb',
|
|
34
|
-
component: 'ZdBreadcrumb',
|
|
35
|
-
divider: '>',
|
|
36
|
-
},
|
|
37
|
-
rightSlot: [image],
|
|
38
|
-
});
|
|
39
|
-
expect(instance.title).toBe('');
|
|
40
|
-
expect(instance.rightSlot).toEqual([image]);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init,
|
|
3
|
-
Router,
|
|
4
|
-
URL,
|
|
5
|
-
} from '@zeedhi/core';
|
|
6
|
-
import {
|
|
7
|
-
TekMemoryDatasource, type ITekMemoryDatasource,
|
|
8
|
-
} from '../../../../src';
|
|
9
|
-
import { flushPromises } from '../../../__helpers__';
|
|
10
|
-
|
|
11
|
-
describe('TekMemoryDatasource', () => {
|
|
12
|
-
init({
|
|
13
|
-
controllers: {
|
|
14
|
-
AppController: class AppController {
|
|
15
|
-
public value = '1';
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
let datasource: ITekMemoryDatasource;
|
|
21
|
-
let router: any;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
datasource = {
|
|
25
|
-
uniqueKey: 'id',
|
|
26
|
-
data: [
|
|
27
|
-
{ name: 'name 1', id: 1 }, { name: 'name 2', id: 2 }, { name: 'name 3', id: 3 },
|
|
28
|
-
{ name: 'name 4', id: 4 }, { name: 'name 5', id: 5 }, { name: 'name 6', id: 6 },
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
router = {
|
|
32
|
-
push: () => jest.fn,
|
|
33
|
-
replace: (route: any) => {
|
|
34
|
-
window.history.replaceState(null, '', `${window.location.pathname}?${URL.getFormattedQueryString(route.query)}`);
|
|
35
|
-
},
|
|
36
|
-
back: () => jest.fn,
|
|
37
|
-
getCurrentRoute: () => ({
|
|
38
|
-
path: '',
|
|
39
|
-
hash: '',
|
|
40
|
-
query: {},
|
|
41
|
-
params: {},
|
|
42
|
-
fullPath: '',
|
|
43
|
-
}),
|
|
44
|
-
getPath: () => '',
|
|
45
|
-
getHash: () => '',
|
|
46
|
-
getQuery: () => ({}),
|
|
47
|
-
getParams: () => ({}),
|
|
48
|
-
getFullPath: () => '',
|
|
49
|
-
};
|
|
50
|
-
Router.setInstance(router);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('constuctor()', () => {
|
|
54
|
-
it('should assign all properties', async () => {
|
|
55
|
-
const flushPromises = () => new Promise(setImmediate);
|
|
56
|
-
const instance = new TekMemoryDatasource({
|
|
57
|
-
...datasource,
|
|
58
|
-
dynamicFilter: {
|
|
59
|
-
name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }],
|
|
60
|
-
},
|
|
61
|
-
searchJoin: { col1: ['1', '2'], col2: [2], col3: [] },
|
|
62
|
-
});
|
|
63
|
-
await flushPromises();
|
|
64
|
-
|
|
65
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
66
|
-
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should assign all properties with accessor', async () => {
|
|
70
|
-
const flushPromises = () => new Promise(setImmediate);
|
|
71
|
-
const instance = new TekMemoryDatasource({
|
|
72
|
-
...datasource,
|
|
73
|
-
dynamicFilter: {
|
|
74
|
-
name: [{ operation: 'EQUALS', relation: 'AND', value: '{{AppController.value}}' }],
|
|
75
|
-
},
|
|
76
|
-
searchJoin: { col1: ['1', '2'], col2: [2], col3: [] },
|
|
77
|
-
});
|
|
78
|
-
await flushPromises();
|
|
79
|
-
|
|
80
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
81
|
-
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should create using default parameters', async () => {
|
|
85
|
-
const instance = new TekMemoryDatasource({});
|
|
86
|
-
|
|
87
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
88
|
-
expect(instance.searchJoin).toEqual({});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should set values from url', () => {
|
|
92
|
-
router.getFullPath = () => 'localhost/?page=2&limit=10&order=id.asc&search=2&id=1';
|
|
93
|
-
const instance = new TekMemoryDatasource({
|
|
94
|
-
...datasource,
|
|
95
|
-
watchUrl: true,
|
|
96
|
-
});
|
|
97
|
-
expect(instance.filter).toEqual({ id: '1' });
|
|
98
|
-
expect(instance.limit).toBe(10);
|
|
99
|
-
expect(instance.order).toEqual(['id.asc']);
|
|
100
|
-
expect(instance.page).toBe(2);
|
|
101
|
-
expect(instance.search).toBe('2');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should set dynamicFilter from url', () => {
|
|
105
|
-
router.getFullPath = () => 'localhost/?dynamic_filter=eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0='; // eslint-disable-line max-len
|
|
106
|
-
datasource.watchUrl = true;
|
|
107
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
108
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should set searchJoin from url', () => {
|
|
112
|
-
router.getFullPath = () => 'localhost/?search_join=eyAiY29sMSI6IFsiMSIsICIyIl0sICJjb2wyIjogWzJdLCAiY29sMyI6IFtdIH0='; // eslint-disable-line max-len
|
|
113
|
-
datasource.watchUrl = true;
|
|
114
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
115
|
-
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('dynamicFilter', () => {
|
|
120
|
-
it('should retrieve data using dynamic filter', async () => {
|
|
121
|
-
const flushPromises = () => new Promise(setImmediate);
|
|
122
|
-
datasource.watchUrl = false;
|
|
123
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
124
|
-
instance.initialize();
|
|
125
|
-
|
|
126
|
-
await flushPromises();
|
|
127
|
-
expect(instance.data.length).toBe(6);
|
|
128
|
-
|
|
129
|
-
instance.dynamicFilter = {
|
|
130
|
-
name: [
|
|
131
|
-
{ operation: 'CONTAINS', relation: 'AND', value: '1' },
|
|
132
|
-
],
|
|
133
|
-
};
|
|
134
|
-
await instance.get();
|
|
135
|
-
expect(instance.data.length).toBe(1);
|
|
136
|
-
|
|
137
|
-
instance.dynamicFilter = {
|
|
138
|
-
name: [
|
|
139
|
-
{ operation: 'CONTAINS', relation: 'AND', value: 'name' },
|
|
140
|
-
],
|
|
141
|
-
};
|
|
142
|
-
await instance.get();
|
|
143
|
-
expect(instance.data.length).toBe(6);
|
|
144
|
-
|
|
145
|
-
instance.dynamicFilter = {
|
|
146
|
-
name: [
|
|
147
|
-
{ operation: 'CONTAINS', relation: 'AND', value: '1' },
|
|
148
|
-
{ operation: 'CONTAINS', relation: 'OR', value: '2' },
|
|
149
|
-
],
|
|
150
|
-
};
|
|
151
|
-
await instance.get();
|
|
152
|
-
expect(instance.data.length).toBe(2);
|
|
153
|
-
|
|
154
|
-
instance.dynamicFilter = {
|
|
155
|
-
name: [
|
|
156
|
-
{ operation: 'CONTAINS', relation: 'AND', value: '1' },
|
|
157
|
-
{ operation: 'CONTAINS', relation: 'AND', value: '2' },
|
|
158
|
-
],
|
|
159
|
-
};
|
|
160
|
-
await instance.get();
|
|
161
|
-
expect(instance.data.length).toBe(0);
|
|
162
|
-
|
|
163
|
-
instance.dynamicFilter = {
|
|
164
|
-
name: [
|
|
165
|
-
{ operation: 'CONTAINS', relation: 'AND', value: '1' },
|
|
166
|
-
],
|
|
167
|
-
id: [
|
|
168
|
-
{ operation: 'CONTAINS', relation: 'OR', value: '2' },
|
|
169
|
-
],
|
|
170
|
-
};
|
|
171
|
-
await instance.get();
|
|
172
|
-
expect(instance.data.length).toBe(2);
|
|
173
|
-
|
|
174
|
-
instance.dynamicFilter = {
|
|
175
|
-
name: [
|
|
176
|
-
{ operation: 'NOT_CONTAINS', relation: 'AND', value: '1' },
|
|
177
|
-
],
|
|
178
|
-
};
|
|
179
|
-
await instance.get();
|
|
180
|
-
expect(instance.data.length).toBe(5);
|
|
181
|
-
|
|
182
|
-
instance.dynamicFilter = {
|
|
183
|
-
name: [
|
|
184
|
-
{ operation: 'EQUALS', relation: 'AND', value: '1' },
|
|
185
|
-
],
|
|
186
|
-
};
|
|
187
|
-
await instance.get();
|
|
188
|
-
expect(instance.data.length).toBe(0);
|
|
189
|
-
|
|
190
|
-
instance.dynamicFilter = {
|
|
191
|
-
name: [
|
|
192
|
-
{ operation: 'EQUALS', relation: 'AND', value: 'name 1' },
|
|
193
|
-
],
|
|
194
|
-
};
|
|
195
|
-
await instance.get();
|
|
196
|
-
expect(instance.data.length).toBe(1);
|
|
197
|
-
|
|
198
|
-
instance.dynamicFilter = {
|
|
199
|
-
name: [
|
|
200
|
-
{ operation: 'NOT_EQUALS', relation: 'AND', value: 'name 1' },
|
|
201
|
-
],
|
|
202
|
-
};
|
|
203
|
-
await instance.get();
|
|
204
|
-
expect(instance.data.length).toBe(5);
|
|
205
|
-
|
|
206
|
-
instance.dynamicFilter = {
|
|
207
|
-
id: [
|
|
208
|
-
{ operation: 'GREATER_THAN', relation: 'AND', value: '2' },
|
|
209
|
-
],
|
|
210
|
-
};
|
|
211
|
-
await instance.get();
|
|
212
|
-
expect(instance.data.length).toBe(4);
|
|
213
|
-
|
|
214
|
-
instance.dynamicFilter = {
|
|
215
|
-
id: [
|
|
216
|
-
{ operation: 'LESS_THAN', relation: 'AND', value: '2' },
|
|
217
|
-
],
|
|
218
|
-
};
|
|
219
|
-
await instance.get();
|
|
220
|
-
expect(instance.data.length).toBe(1);
|
|
221
|
-
|
|
222
|
-
instance.dynamicFilter = {
|
|
223
|
-
id: [
|
|
224
|
-
{ operation: 'GREATER_THAN_EQUALS', relation: 'AND', value: '2' },
|
|
225
|
-
],
|
|
226
|
-
};
|
|
227
|
-
await instance.get();
|
|
228
|
-
expect(instance.data.length).toBe(5);
|
|
229
|
-
|
|
230
|
-
instance.dynamicFilter = {
|
|
231
|
-
id: [
|
|
232
|
-
{ operation: 'LESS_THAN_EQUALS', relation: 'AND', value: '2' },
|
|
233
|
-
],
|
|
234
|
-
};
|
|
235
|
-
await instance.get();
|
|
236
|
-
expect(instance.data.length).toBe(2);
|
|
237
|
-
|
|
238
|
-
instance.dynamicFilter = {
|
|
239
|
-
name: [
|
|
240
|
-
{ operation: 'GREATER_THAN', relation: 'AND', value: 'name 2' },
|
|
241
|
-
],
|
|
242
|
-
};
|
|
243
|
-
await instance.get();
|
|
244
|
-
expect(instance.data.length).toBe(4);
|
|
245
|
-
|
|
246
|
-
instance.dynamicFilter = {
|
|
247
|
-
name: [
|
|
248
|
-
{ operation: 'LESS_THAN', relation: 'AND', value: 'name 2' },
|
|
249
|
-
],
|
|
250
|
-
};
|
|
251
|
-
await instance.get();
|
|
252
|
-
expect(instance.data.length).toBe(1);
|
|
253
|
-
|
|
254
|
-
instance.dynamicFilter = {
|
|
255
|
-
name: [
|
|
256
|
-
{ operation: 'GREATER_THAN_EQUALS', relation: 'AND', value: 'name 2' },
|
|
257
|
-
],
|
|
258
|
-
};
|
|
259
|
-
await instance.get();
|
|
260
|
-
expect(instance.data.length).toBe(5);
|
|
261
|
-
|
|
262
|
-
instance.dynamicFilter = {
|
|
263
|
-
name: [
|
|
264
|
-
{ operation: 'LESS_THAN_EQUALS', relation: 'AND', value: 'name 2' },
|
|
265
|
-
],
|
|
266
|
-
};
|
|
267
|
-
await instance.get();
|
|
268
|
-
expect(instance.data.length).toBe(2);
|
|
269
|
-
|
|
270
|
-
instance.dynamicFilter = {
|
|
271
|
-
id: [
|
|
272
|
-
{ operation: 'IN', relation: 'AND', value: ['1', '2'] },
|
|
273
|
-
],
|
|
274
|
-
};
|
|
275
|
-
await instance.get();
|
|
276
|
-
expect(instance.data.length).toBe(2);
|
|
277
|
-
|
|
278
|
-
instance.dynamicFilter = {
|
|
279
|
-
id: [
|
|
280
|
-
{ operation: 'NOT_IN', relation: 'AND', value: ['1', '2'] },
|
|
281
|
-
],
|
|
282
|
-
};
|
|
283
|
-
await instance.get();
|
|
284
|
-
expect(instance.data.length).toBe(4);
|
|
285
|
-
|
|
286
|
-
instance.dynamicFilter = {
|
|
287
|
-
id: [
|
|
288
|
-
{ operation: 'BETWEEN', relation: 'AND', value: ['2', '5'] },
|
|
289
|
-
],
|
|
290
|
-
};
|
|
291
|
-
await instance.get();
|
|
292
|
-
expect(instance.data.length).toBe(4);
|
|
293
|
-
|
|
294
|
-
instance.dynamicFilter = {
|
|
295
|
-
name: [
|
|
296
|
-
{ operation: 'BETWEEN', relation: 'AND', value: ['name 2', 'name 5'] },
|
|
297
|
-
],
|
|
298
|
-
};
|
|
299
|
-
await instance.get();
|
|
300
|
-
expect(instance.data.length).toBe(4);
|
|
301
|
-
|
|
302
|
-
instance.dynamicFilter = {
|
|
303
|
-
name: [
|
|
304
|
-
{ operation: '', relation: 'AND', value: ['1', '2'] },
|
|
305
|
-
],
|
|
306
|
-
};
|
|
307
|
-
await instance.get();
|
|
308
|
-
expect(instance.data.length).toBe(0);
|
|
309
|
-
|
|
310
|
-
instance.dynamicFilter = {
|
|
311
|
-
name: [
|
|
312
|
-
{ operation: '', relation: 'AND', value: '1' },
|
|
313
|
-
],
|
|
314
|
-
};
|
|
315
|
-
await instance.get();
|
|
316
|
-
expect(instance.data.length).toBe(0);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('should not retrieve data with wrong operator', async () => {
|
|
320
|
-
const flushPromises = () => new Promise(setImmediate);
|
|
321
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
322
|
-
|
|
323
|
-
await flushPromises();
|
|
324
|
-
expect(instance.data.length).toBe(6);
|
|
325
|
-
|
|
326
|
-
instance.dynamicFilter = {
|
|
327
|
-
name: [
|
|
328
|
-
{ operation: 'TEST', relation: 'AND', value: '1' },
|
|
329
|
-
],
|
|
330
|
-
};
|
|
331
|
-
await instance.get();
|
|
332
|
-
expect(instance.data.length).toBe(0);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
describe('searchJoin', () => {
|
|
337
|
-
it('should retrieve data using search join', async () => {
|
|
338
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
339
|
-
instance.initialize();
|
|
340
|
-
|
|
341
|
-
await flushPromises();
|
|
342
|
-
expect(instance.data.length).toBe(6);
|
|
343
|
-
|
|
344
|
-
instance.searchJoin = {
|
|
345
|
-
name: ['name 1', 'name 2'],
|
|
346
|
-
};
|
|
347
|
-
instance.search = 'aaa';
|
|
348
|
-
await instance.get();
|
|
349
|
-
expect(instance.data.length).toBe(2);
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
describe('addDynamicFilter()', () => {
|
|
354
|
-
it('should add/remove dynamic filter value', () => {
|
|
355
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
356
|
-
instance.addDynamicFilter('name', [{ operation: 'EQUALS', relation: 'AND', value: '1' }]);
|
|
357
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
358
|
-
instance.addDynamicFilter('name', [{ operation: 'foo', relation: 'AND', value: '1' }]);
|
|
359
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
describe('setDynamicFilter()', () => {
|
|
364
|
-
it('should add/remove dynamic filter value', () => {
|
|
365
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
366
|
-
instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
367
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
368
|
-
|
|
369
|
-
instance.setDynamicFilter({ name: [{ operation: 'foo', relation: 'AND', value: '1' }] });
|
|
370
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
371
|
-
|
|
372
|
-
instance.setDynamicFilter({
|
|
373
|
-
name: [], id: [{}],
|
|
374
|
-
});
|
|
375
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it('should add dynamic filter value with watchUrl', () => {
|
|
379
|
-
let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
|
|
380
|
-
router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
|
|
381
|
-
const urlSpy = jest.spyOn(URL, 'updateQueryString');
|
|
382
|
-
|
|
383
|
-
datasource.watchUrl = true;
|
|
384
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
385
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
386
|
-
|
|
387
|
-
dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMiJ9XX0=';
|
|
388
|
-
instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
|
|
389
|
-
expect(urlSpy).toHaveBeenCalledWith({
|
|
390
|
-
dynamic_filter: dynamicFilterValue,
|
|
391
|
-
});
|
|
392
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '2' }] });
|
|
393
|
-
urlSpy.mockClear();
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
describe('clearDynamicFilter()', () => {
|
|
398
|
-
it('should clear dynamic filter', () => {
|
|
399
|
-
datasource.watchUrl = false;
|
|
400
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
401
|
-
instance.setDynamicFilter({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
402
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
403
|
-
instance.clearDynamicFilter();
|
|
404
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
it('should clear dynamic filter value with watchUrl', () => {
|
|
408
|
-
let dynamicFilterValue = 'eyJuYW1lIjpbeyJvcGVyYXRpb24iOiJFUVVBTFMiLCJyZWxhdGlvbiI6IkFORCIsInZhbHVlIjoiMSJ9XX0=';
|
|
409
|
-
router.getFullPath = () => `localhost/?dynamic_filter=${dynamicFilterValue}`;
|
|
410
|
-
const urlSpy = jest.spyOn(URL, 'updateQueryString');
|
|
411
|
-
|
|
412
|
-
datasource.watchUrl = true;
|
|
413
|
-
const instance = new TekMemoryDatasource(datasource);
|
|
414
|
-
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
415
|
-
|
|
416
|
-
dynamicFilterValue = '';
|
|
417
|
-
instance.clearDynamicFilter();
|
|
418
|
-
expect(urlSpy).toHaveBeenCalledWith({
|
|
419
|
-
dynamic_filter: undefined,
|
|
420
|
-
});
|
|
421
|
-
expect(instance.dynamicFilter).toEqual({});
|
|
422
|
-
urlSpy.mockClear();
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
describe('clone', () => {
|
|
427
|
-
it('should return an object with all datasource props', async () => {
|
|
428
|
-
const data = [{ value: 'item 1' }];
|
|
429
|
-
const dynamicFilter = {
|
|
430
|
-
name: { operation: 'EQUALS', relation: 'AND', value: 'item 1' },
|
|
431
|
-
};
|
|
432
|
-
const searchJoin = { col1: ['1', '2'], col2: [2], col3: [] };
|
|
433
|
-
const instance = new TekMemoryDatasource({
|
|
434
|
-
route: '/zeedhi',
|
|
435
|
-
data,
|
|
436
|
-
dynamicFilter,
|
|
437
|
-
searchJoin,
|
|
438
|
-
});
|
|
439
|
-
instance.initialize();
|
|
440
|
-
|
|
441
|
-
const props = instance.clone();
|
|
442
|
-
|
|
443
|
-
expect(props).toEqual({
|
|
444
|
-
data,
|
|
445
|
-
dynamicFilter,
|
|
446
|
-
searchJoin,
|
|
447
|
-
currentRow: {},
|
|
448
|
-
filter: {},
|
|
449
|
-
limit: 10,
|
|
450
|
-
order: [],
|
|
451
|
-
page: 1,
|
|
452
|
-
search: '',
|
|
453
|
-
searchIn: [],
|
|
454
|
-
uniqueKey: 'id',
|
|
455
|
-
watchUrl: false,
|
|
456
|
-
events: {},
|
|
457
|
-
loadAll: false,
|
|
458
|
-
type: 'tek-memory',
|
|
459
|
-
translate: false,
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
});
|