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