@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
|
@@ -1,3377 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Button, Dropdown, IModal, Modal, ModalService, Search, TextInput, Text, Report,
|
|
5
|
-
AlertService,
|
|
6
|
-
EmptyDataError,
|
|
7
|
-
IComponentRender,
|
|
8
|
-
} from '@zeedhi/common';
|
|
9
|
-
import {
|
|
10
|
-
KeyMap, Http, Metadata, IDictionary, IEventParam,
|
|
11
|
-
Datasource,
|
|
12
|
-
init,
|
|
13
|
-
} from '@zeedhi/core';
|
|
14
|
-
import {
|
|
15
|
-
ITekGrid,
|
|
16
|
-
ITekGridFilterButton,
|
|
17
|
-
ITekGridGroupFooter,
|
|
18
|
-
TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
|
|
19
|
-
} from '../../../../src';
|
|
20
|
-
import { ReportFilter } from '../../../../src/utils';
|
|
21
|
-
import { setClick, getChild } from '../../../__helpers__';
|
|
22
|
-
import { flushPromises } from '../../../__helpers__/flush-promises-helper';
|
|
23
|
-
import { TekGridDeleteRowsError } from '../../../../src/error/delete-rows-error';
|
|
24
|
-
|
|
25
|
-
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
26
|
-
|
|
27
|
-
jest.useFakeTimers();
|
|
28
|
-
|
|
29
|
-
class AppController {
|
|
30
|
-
public datasource = {
|
|
31
|
-
uniqueKey: 'id',
|
|
32
|
-
data: [{ id: '1' }],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const clickOnFilterButton = (grid: TekGrid, event?: any) => {
|
|
37
|
-
const buttonProps = getChild<ITekGridFilterButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
|
|
38
|
-
const filterButton = new TekGridFilterButton(buttonProps);
|
|
39
|
-
setClick(filterButton, event);
|
|
40
|
-
|
|
41
|
-
return filterButton;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const createAndMount = (props: ITekGrid) => {
|
|
45
|
-
const instance = new TekGrid(props);
|
|
46
|
-
instance.onMounted({} as HTMLElement);
|
|
47
|
-
return instance;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const createGroupedGrid = async (props: Partial<ITekGrid> = {}) => {
|
|
51
|
-
const grid = createAndMount({
|
|
52
|
-
name: 'grid',
|
|
53
|
-
component: 'TekGrid',
|
|
54
|
-
columns: [
|
|
55
|
-
{ name: 'id' },
|
|
56
|
-
{ name: 'name' },
|
|
57
|
-
{ name: 'month' },
|
|
58
|
-
{ name: 'department', grouped: true },
|
|
59
|
-
],
|
|
60
|
-
datasource: {
|
|
61
|
-
uniqueKey: 'id',
|
|
62
|
-
data: [
|
|
63
|
-
{
|
|
64
|
-
id: '1', name: 'First', month: 11, department: 1, salary: 10,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: '2', name: 'Second', month: 11, department: 1, salary: 10,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: '3', name: 'Third', month: 11, department: 2, salary: 10,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: '4', name: 'Fourth', month: 12, department: 1, salary: 10,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
id: '5', name: 'Fifth', month: 12, department: 2, salary: 10,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
...props,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await flushPromises();
|
|
84
|
-
return grid;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const getNthFooter = (grid: TekGrid, n: number): ITekGridGroupFooter => {
|
|
88
|
-
const { groupedData } = grid;
|
|
89
|
-
|
|
90
|
-
return groupedData.filter((row) => row.groupFooter)[n] as ITekGridGroupFooter;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const getLastFooter = (grid: TekGrid) : ITekGridGroupFooter => {
|
|
94
|
-
const { groupedData } = grid;
|
|
95
|
-
return groupedData.filter((row) => row.groupFooter).reverse()[0] as ITekGridGroupFooter;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
describe('TekGrid', () => {
|
|
99
|
-
beforeEach(() => {
|
|
100
|
-
// clear all metadata instances before testing
|
|
101
|
-
const { instances } = Metadata as any;
|
|
102
|
-
Object.keys(instances).forEach((key) => {
|
|
103
|
-
Metadata.clearInstance(key, instances[key].componentId);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
jest.clearAllTimers();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('constructor()', () => {
|
|
110
|
-
it('should create new grid with default values', () => {
|
|
111
|
-
const instance = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
112
|
-
expect(instance.title).toBe('');
|
|
113
|
-
expect(instance.addButton).toBeFalsy();
|
|
114
|
-
expect(instance.deleteButton).toBe('none');
|
|
115
|
-
expect(instance.filterButton).toBeFalsy();
|
|
116
|
-
expect(instance.modalFilterProps).toEqual(
|
|
117
|
-
expect.objectContaining({
|
|
118
|
-
height: 'auto',
|
|
119
|
-
persistent: true,
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
expect(instance.columnFilterButton).toBeFalsy();
|
|
123
|
-
expect(instance.dragColumns).toBeTruthy();
|
|
124
|
-
expect(instance.resizeColumns).toBeTruthy();
|
|
125
|
-
expect(instance.showLayoutOptions).toBeTruthy();
|
|
126
|
-
expect(instance.showSearch).toBeTruthy();
|
|
127
|
-
expect(instance.showSummaryTotal).toBeTruthy();
|
|
128
|
-
expect(instance.showReload).toBeTruthy();
|
|
129
|
-
expect(instance.columnsButton).toBeFalsy();
|
|
130
|
-
expect(instance.columnsButtonIgnore).toEqual([]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should create new Grid replacing default values', () => {
|
|
134
|
-
const instance = new TekGrid({
|
|
135
|
-
name: 'grid',
|
|
136
|
-
component: 'TekGrid',
|
|
137
|
-
title: 'title',
|
|
138
|
-
addButton: true,
|
|
139
|
-
deleteButton: 'selection',
|
|
140
|
-
filterButton: true,
|
|
141
|
-
modalFilterProps: {
|
|
142
|
-
name: 'teste',
|
|
143
|
-
height: 'auto',
|
|
144
|
-
persistent: false,
|
|
145
|
-
cssClass: 'class-test',
|
|
146
|
-
cssStyle: 'background: red',
|
|
147
|
-
draggable: true,
|
|
148
|
-
fullscreen: true,
|
|
149
|
-
light: false,
|
|
150
|
-
dark: true,
|
|
151
|
-
},
|
|
152
|
-
columnFilterButton: true,
|
|
153
|
-
dragColumns: false,
|
|
154
|
-
resizeColumns: false,
|
|
155
|
-
showLayoutOptions: false,
|
|
156
|
-
showSearch: false,
|
|
157
|
-
showSummaryTotal: false,
|
|
158
|
-
showReload: false,
|
|
159
|
-
columns: [
|
|
160
|
-
{ name: 'id' },
|
|
161
|
-
],
|
|
162
|
-
columnsButton: true,
|
|
163
|
-
columnsButtonIgnore: ['id'],
|
|
164
|
-
});
|
|
165
|
-
expect(instance.title).toBe('title');
|
|
166
|
-
expect(instance.addButton).toBeTruthy();
|
|
167
|
-
expect(instance.deleteButton).toBe('selection');
|
|
168
|
-
expect(instance.filterButton).toBeTruthy();
|
|
169
|
-
expect(instance.modalFilterProps).toEqual(
|
|
170
|
-
expect.objectContaining({
|
|
171
|
-
height: 'auto',
|
|
172
|
-
persistent: false,
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
expect(instance.columnFilterButton).toBeTruthy();
|
|
176
|
-
expect(instance.dragColumns).toBeFalsy();
|
|
177
|
-
expect(instance.resizeColumns).toBeFalsy();
|
|
178
|
-
expect(instance.showLayoutOptions).toBeFalsy();
|
|
179
|
-
expect(instance.showSearch).toBeFalsy();
|
|
180
|
-
expect(instance.showSummaryTotal).toBeFalsy();
|
|
181
|
-
expect(instance.showReload).toBeFalsy();
|
|
182
|
-
expect(instance.columns[0]).toBeInstanceOf(TekGridColumn);
|
|
183
|
-
expect(instance.columnsButton).toBeTruthy();
|
|
184
|
-
expect(instance.columnsButtonIgnore).toEqual(['id']);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('should create toolbar and footer', () => {
|
|
188
|
-
const instance = new TekGrid({
|
|
189
|
-
name: 'grid',
|
|
190
|
-
component: 'TekGrid',
|
|
191
|
-
title: 'title',
|
|
192
|
-
addButton: true,
|
|
193
|
-
deleteButton: 'selection',
|
|
194
|
-
filterButton: true,
|
|
195
|
-
columnFilterButton: true,
|
|
196
|
-
dragColumns: false,
|
|
197
|
-
resizeColumns: false,
|
|
198
|
-
showLayoutOptions: false,
|
|
199
|
-
});
|
|
200
|
-
instance.onCreated();
|
|
201
|
-
expect(instance.toolbarSlot.length).toBe(3);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('should overwrite toolbar', () => {
|
|
205
|
-
const instance = new TekGrid({
|
|
206
|
-
name: 'grid',
|
|
207
|
-
component: 'TekGrid',
|
|
208
|
-
title: 'title',
|
|
209
|
-
addButton: true,
|
|
210
|
-
deleteButton: 'selection',
|
|
211
|
-
filterButton: true,
|
|
212
|
-
columnFilterButton: true,
|
|
213
|
-
dragColumns: false,
|
|
214
|
-
resizeColumns: false,
|
|
215
|
-
showLayoutOptions: false,
|
|
216
|
-
toolbarSlot: [],
|
|
217
|
-
});
|
|
218
|
-
instance.onCreated();
|
|
219
|
-
expect(instance.toolbarSlot.length).toBe(0);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should change export buttons from exportConfig', () => {
|
|
223
|
-
const instance = new TekGrid({
|
|
224
|
-
name: 'grid',
|
|
225
|
-
component: 'TekGrid',
|
|
226
|
-
exportConfig: [
|
|
227
|
-
{
|
|
228
|
-
type: 'pdf',
|
|
229
|
-
iconName: 'icon',
|
|
230
|
-
portrait: false,
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
expect((instance as any).gridBase.exportConfigButtons[0].label).toBeUndefined();
|
|
236
|
-
expect((instance as any).gridBase.exportConfigButtons[0].iconName).toBe('icon');
|
|
237
|
-
expect((instance as any).gridBase.exportConfigButtons[0].name).toBe('grid_export_pdf_landscape');
|
|
238
|
-
expect((instance as any).gridBase.exportConfigButtons[0].component).toBe('ZdButton');
|
|
239
|
-
expect((instance as any).gridBase.exportConfigButtons[0].flat).toBeTruthy();
|
|
240
|
-
expect((instance as any).gridBase.exportConfigButtons[0].events).toBeDefined();
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('should create new TekGrid with accessor datasource', () => {
|
|
244
|
-
init({
|
|
245
|
-
controllers: {
|
|
246
|
-
AppController,
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
const instance = new TekGrid({
|
|
250
|
-
name: 'grid',
|
|
251
|
-
component: 'TekGrid',
|
|
252
|
-
datasource: '{{AppController.datasource}}' as any,
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
expect(instance.datasource).toBeInstanceOf(Datasource);
|
|
256
|
-
expect(instance.datasource.data).toEqual([{ id: '1' }]);
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
describe('getReport()', () => {
|
|
261
|
-
let httpReportSpy: jest.SpyInstance;
|
|
262
|
-
let reportSpy: jest.SpyInstance;
|
|
263
|
-
|
|
264
|
-
beforeEach(() => {
|
|
265
|
-
reportSpy = jest.spyOn(Report.prototype, 'getReport').mockReturnValue(Promise.resolve(''));
|
|
266
|
-
httpReportSpy = jest.spyOn(Http, 'post').mockImplementation((url) => {
|
|
267
|
-
if (url === 'https://zhreport.teknisa.com/generateReport') {
|
|
268
|
-
return Promise.resolve({
|
|
269
|
-
data: { messages: [{ message: 'pdf-report.html' }] },
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return Promise.reject();
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
afterEach(() => {
|
|
278
|
-
reportSpy.mockClear();
|
|
279
|
-
httpReportSpy.mockReset();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('should call window open on getReport method', async () => {
|
|
283
|
-
(window as any).open = jest.fn();
|
|
284
|
-
|
|
285
|
-
const instance = new TekGrid({
|
|
286
|
-
name: 'grid',
|
|
287
|
-
component: 'TekGrid',
|
|
288
|
-
events: {
|
|
289
|
-
beforeOpenReport: jest.fn(),
|
|
290
|
-
},
|
|
291
|
-
columns: [
|
|
292
|
-
{
|
|
293
|
-
name: 'id',
|
|
294
|
-
label: 'ID',
|
|
295
|
-
aggregation: 'COUNT',
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
name: 'department_id',
|
|
299
|
-
label: 'Department ID',
|
|
300
|
-
grouped: true,
|
|
301
|
-
},
|
|
302
|
-
],
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
const spy = jest.spyOn(window, 'open');
|
|
306
|
-
await instance.getReport('pdf');
|
|
307
|
-
|
|
308
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
309
|
-
|
|
310
|
-
(window as any).open.mockClear();
|
|
311
|
-
spy.mockReset();
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it('when reportLabelFormatter is defined, it should be passed to getReport', async () => {
|
|
315
|
-
(window as any).open = jest.fn();
|
|
316
|
-
const reportLabelFormatter = jest.fn();
|
|
317
|
-
const spy = jest.spyOn(Report.prototype, 'getReport').mockImplementationOnce(async () => '');
|
|
318
|
-
|
|
319
|
-
const instance = new TekGrid({
|
|
320
|
-
reportLabelFormatter,
|
|
321
|
-
name: 'grid',
|
|
322
|
-
component: 'TekGrid',
|
|
323
|
-
columns: [
|
|
324
|
-
{
|
|
325
|
-
name: 'id',
|
|
326
|
-
label: 'ID',
|
|
327
|
-
aggregation: 'COUNT',
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
name: 'department_id',
|
|
331
|
-
label: 'Department ID',
|
|
332
|
-
grouped: true,
|
|
333
|
-
},
|
|
334
|
-
],
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
await instance.getReport('pdf');
|
|
338
|
-
|
|
339
|
-
expect(spy).toHaveBeenLastCalledWith('pdf', undefined, expect.any(Object), undefined, reportLabelFormatter);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it('when called with a dynamicFilter, should format the filter values', async () => {
|
|
343
|
-
(window as any).open = jest.fn();
|
|
344
|
-
const spy = jest.spyOn(Report.prototype, 'getReport').mockImplementationOnce(async () => '');
|
|
345
|
-
const instance = new TekGrid({
|
|
346
|
-
name: 'grid_getReport',
|
|
347
|
-
component: 'TekGrid',
|
|
348
|
-
columns: [
|
|
349
|
-
{
|
|
350
|
-
name: 'department_id',
|
|
351
|
-
label: 'Department',
|
|
352
|
-
componentProps: {
|
|
353
|
-
component: 'ZdSelect',
|
|
354
|
-
name: 'select',
|
|
355
|
-
dataText: [
|
|
356
|
-
'id',
|
|
357
|
-
'name',
|
|
358
|
-
],
|
|
359
|
-
dataValue: 'id',
|
|
360
|
-
datasource: {
|
|
361
|
-
uniqueKey: 'id',
|
|
362
|
-
data: [
|
|
363
|
-
{ id: 1, name: 'Department 1' },
|
|
364
|
-
{ id: 2, name: 'Department 2' },
|
|
365
|
-
],
|
|
366
|
-
},
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
name: 'name',
|
|
371
|
-
label: 'Name',
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
datasource: {
|
|
375
|
-
type: 'tek-rest',
|
|
376
|
-
route: '/employees',
|
|
377
|
-
lazyLoad: true,
|
|
378
|
-
dynamicFilter: {
|
|
379
|
-
department_id: [
|
|
380
|
-
{
|
|
381
|
-
relation: 'OR',
|
|
382
|
-
operation: 'EQUALS',
|
|
383
|
-
value: 1,
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
relation: 'OR',
|
|
387
|
-
operation: 'EQUALS',
|
|
388
|
-
value: 2,
|
|
389
|
-
},
|
|
390
|
-
],
|
|
391
|
-
name: [
|
|
392
|
-
{
|
|
393
|
-
relation: 'OR',
|
|
394
|
-
operation: 'EQUALS',
|
|
395
|
-
value: 'Employee 1',
|
|
396
|
-
},
|
|
397
|
-
],
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
const filter = new ReportFilter({
|
|
403
|
-
Department: [
|
|
404
|
-
{
|
|
405
|
-
relation: 'OR',
|
|
406
|
-
operation: 'EQUALS',
|
|
407
|
-
value: '1 | Department 1',
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
relation: 'OR',
|
|
411
|
-
operation: 'EQUALS',
|
|
412
|
-
value: '2 | Department 2',
|
|
413
|
-
},
|
|
414
|
-
],
|
|
415
|
-
Name: [
|
|
416
|
-
{
|
|
417
|
-
relation: 'OR',
|
|
418
|
-
operation: 'EQUALS',
|
|
419
|
-
value: 'Employee 1',
|
|
420
|
-
},
|
|
421
|
-
],
|
|
422
|
-
}).build();
|
|
423
|
-
|
|
424
|
-
await instance.getReport('pdf');
|
|
425
|
-
|
|
426
|
-
expect(spy).toHaveBeenLastCalledWith('pdf', undefined, expect.objectContaining({
|
|
427
|
-
metaData: expect.objectContaining({
|
|
428
|
-
filter,
|
|
429
|
-
}),
|
|
430
|
-
}), undefined, undefined);
|
|
431
|
-
(window as any).open.mockClear();
|
|
432
|
-
spy.mockReset();
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('when called with a dynamicFilter, should handle exceptions', async () => {
|
|
436
|
-
(window as any).open = jest.fn();
|
|
437
|
-
const spy = jest.spyOn(Report.prototype, 'getReport').mockImplementationOnce(async () => '');
|
|
438
|
-
const instance = new TekGrid({
|
|
439
|
-
name: 'grid_getReport',
|
|
440
|
-
component: 'TekGrid',
|
|
441
|
-
datasource: {
|
|
442
|
-
type: 'tek-rest',
|
|
443
|
-
route: '/employees',
|
|
444
|
-
lazyLoad: true,
|
|
445
|
-
dynamicFilter: {
|
|
446
|
-
invisible_column: [
|
|
447
|
-
{
|
|
448
|
-
relation: 'OR',
|
|
449
|
-
operation: 'EQUALS',
|
|
450
|
-
value: 1,
|
|
451
|
-
},
|
|
452
|
-
],
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
const getReport = async () => { await instance.getReport('pdf'); };
|
|
458
|
-
|
|
459
|
-
expect(getReport).not.toThrow();
|
|
460
|
-
|
|
461
|
-
const getColumnSpy = jest.spyOn(instance, 'getColumn').mockImplementationOnce(() => {
|
|
462
|
-
throw Error();
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
expect(getReport()).rejects.toEqual(new Error());
|
|
466
|
-
|
|
467
|
-
(window as any).open.mockClear();
|
|
468
|
-
spy.mockReset();
|
|
469
|
-
getColumnSpy.mockReset();
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it('should call getReport always with "xls" when there is no group', async () => {
|
|
473
|
-
(window as any).open = jest.fn();
|
|
474
|
-
|
|
475
|
-
const instance = new TekGrid({
|
|
476
|
-
name: 'grid',
|
|
477
|
-
component: 'TekGrid',
|
|
478
|
-
columns: [
|
|
479
|
-
{
|
|
480
|
-
name: 'id',
|
|
481
|
-
label: 'ID',
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
name: 'department_id',
|
|
485
|
-
label: 'Department ID',
|
|
486
|
-
},
|
|
487
|
-
],
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
await instance.getReport('xls2');
|
|
491
|
-
|
|
492
|
-
expect(reportSpy).toHaveBeenCalledWith('xls', undefined, {
|
|
493
|
-
metaData: {
|
|
494
|
-
columns: {}, filter: undefined, groups: [], xlsDefaultType: undefined,
|
|
495
|
-
},
|
|
496
|
-
}, undefined, undefined);
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
it('when data is empty, should show alert', async () => {
|
|
500
|
-
reportSpy = jest.spyOn(Report.prototype, 'getReport').mockImplementation(() => { throw new EmptyDataError(); });
|
|
501
|
-
const alertSpy = jest.spyOn(AlertService, 'show').mockImplementation(() => 1);
|
|
502
|
-
|
|
503
|
-
const instance = new TekGrid({
|
|
504
|
-
name: 'grid',
|
|
505
|
-
component: 'TekGrid',
|
|
506
|
-
datasource: {
|
|
507
|
-
data: [],
|
|
508
|
-
},
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
expect(async () => instance.getReport('xls2')).not.toThrow();
|
|
512
|
-
|
|
513
|
-
expect(alertSpy).toHaveBeenCalledWith({ name: 'no-data-warning', text: 'TEKGRID_NO_DATA', color: 'warning' });
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
it('when an error happens, should throw normally', async () => {
|
|
517
|
-
reportSpy = jest.spyOn(Report.prototype, 'getReport').mockImplementation(() => { throw new Error(); });
|
|
518
|
-
|
|
519
|
-
const instance = new TekGrid({
|
|
520
|
-
name: 'grid',
|
|
521
|
-
component: 'TekGrid',
|
|
522
|
-
datasource: {
|
|
523
|
-
data: [],
|
|
524
|
-
},
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
expect(async () => instance.getReport('xls2')).rejects.toThrow();
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
describe('saveChanges()', () => {
|
|
532
|
-
it('should call saveEditedRows', () => {
|
|
533
|
-
const instance = new TekGrid({
|
|
534
|
-
name: 'grid_saveChanges1',
|
|
535
|
-
component: 'TekGrid',
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
const spy = jest.spyOn(instance, 'saveEditedRows');
|
|
539
|
-
instance.onCreated();
|
|
540
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
541
|
-
if (toolbarDiv.children) {
|
|
542
|
-
const button = new Button(toolbarDiv.children[10]);
|
|
543
|
-
const event = new Event('click');
|
|
544
|
-
button.click(event, {} as HTMLElement);
|
|
545
|
-
expect(spy).toBeCalled();
|
|
546
|
-
expect(button.isVisible).toBeFalsy();
|
|
547
|
-
spy.mockReset();
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it('should call events', () => {
|
|
552
|
-
let beforeSaveCalled = false;
|
|
553
|
-
let afterSaveCalled = false;
|
|
554
|
-
const instance = new TekGrid({
|
|
555
|
-
name: 'grid_saveChanges2',
|
|
556
|
-
component: 'TekGrid',
|
|
557
|
-
events: {
|
|
558
|
-
beforeSave: () => { beforeSaveCalled = true; },
|
|
559
|
-
afterSave: () => { afterSaveCalled = true; },
|
|
560
|
-
},
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
instance.onCreated();
|
|
564
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
565
|
-
if (toolbarDiv.children) {
|
|
566
|
-
const button = new Button(toolbarDiv.children[10]);
|
|
567
|
-
const event = new Event('click');
|
|
568
|
-
button.click(event, {} as HTMLElement);
|
|
569
|
-
expect(beforeSaveCalled).toBeTruthy();
|
|
570
|
-
expect(afterSaveCalled).toBeTruthy();
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
it('should not call saveEditedRows if beforeSave call preventDefault', () => {
|
|
575
|
-
let beforeSaveCalled = false;
|
|
576
|
-
let afterSaveCalled = false;
|
|
577
|
-
const instance = new TekGrid({
|
|
578
|
-
name: 'grid_saveChanges3',
|
|
579
|
-
component: 'TekGrid',
|
|
580
|
-
events: {
|
|
581
|
-
beforeSave: () => { beforeSaveCalled = true; },
|
|
582
|
-
afterSave: () => { afterSaveCalled = true; },
|
|
583
|
-
},
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
const spy = jest.spyOn(instance, 'saveEditedRows');
|
|
587
|
-
instance.onCreated();
|
|
588
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
589
|
-
if (toolbarDiv.children) {
|
|
590
|
-
const button = new Button(toolbarDiv.children[10]);
|
|
591
|
-
button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
592
|
-
expect(beforeSaveCalled).toBeTruthy();
|
|
593
|
-
expect(afterSaveCalled).toBeFalsy();
|
|
594
|
-
expect(spy).not.toBeCalled();
|
|
595
|
-
spy.mockReset();
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
describe('cancelChanges()', () => {
|
|
601
|
-
it('should call cancelEditedRows', () => {
|
|
602
|
-
const instance = new TekGrid({
|
|
603
|
-
name: 'grid_cancelChanges1',
|
|
604
|
-
component: 'TekGrid',
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
608
|
-
instance.onCreated();
|
|
609
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
610
|
-
if (toolbarDiv.children) {
|
|
611
|
-
const button = new Button(toolbarDiv.children[11]);
|
|
612
|
-
const event = new Event('click');
|
|
613
|
-
button.click(event, {} as HTMLElement);
|
|
614
|
-
expect(spy).toBeCalled();
|
|
615
|
-
expect(button.isVisible).toBeFalsy();
|
|
616
|
-
spy.mockReset();
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
it('should call events', () => {
|
|
621
|
-
let beforeCancelCalled = false;
|
|
622
|
-
let afterCancelCalled = false;
|
|
623
|
-
const instance = new TekGrid({
|
|
624
|
-
name: 'grid_cancelChanges2',
|
|
625
|
-
component: 'TekGrid',
|
|
626
|
-
events: {
|
|
627
|
-
beforeCancel: () => { beforeCancelCalled = true; },
|
|
628
|
-
afterCancel: () => { afterCancelCalled = true; },
|
|
629
|
-
},
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
instance.onCreated();
|
|
633
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
634
|
-
if (toolbarDiv.children) {
|
|
635
|
-
const button = new Button(toolbarDiv.children[11]);
|
|
636
|
-
const event = new Event('click');
|
|
637
|
-
button.click(event, {} as HTMLElement);
|
|
638
|
-
expect(beforeCancelCalled).toBeTruthy();
|
|
639
|
-
expect(afterCancelCalled).toBeTruthy();
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
it('should not call cancelEditedRows if beforeSave call preventDefault', () => {
|
|
644
|
-
let beforeCancelCalled = false;
|
|
645
|
-
let afterCancelCalled = false;
|
|
646
|
-
const instance = new TekGrid({
|
|
647
|
-
name: 'grid_cancelChanges3',
|
|
648
|
-
component: 'TekGrid',
|
|
649
|
-
events: {
|
|
650
|
-
beforeCancel: () => { beforeCancelCalled = true; },
|
|
651
|
-
afterCancel: () => { afterCancelCalled = true; },
|
|
652
|
-
},
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
656
|
-
instance.onCreated();
|
|
657
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
658
|
-
if (toolbarDiv.children) {
|
|
659
|
-
const button = new Button(toolbarDiv.children[11]);
|
|
660
|
-
button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
661
|
-
expect(beforeCancelCalled).toBeTruthy();
|
|
662
|
-
expect(afterCancelCalled).toBeFalsy();
|
|
663
|
-
expect(spy).not.toBeCalled();
|
|
664
|
-
spy.mockReset();
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
describe('addButtonClick()', () => {
|
|
670
|
-
it('should call event', () => {
|
|
671
|
-
let addClickCalled = false;
|
|
672
|
-
const instance = new TekGrid({
|
|
673
|
-
name: 'grid_addClick1',
|
|
674
|
-
component: 'TekGrid',
|
|
675
|
-
addButton: true,
|
|
676
|
-
editNewRowsOnly: true,
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
instance.onCreated();
|
|
680
|
-
const toolbarDiv = instance.toolbarSlot[2];
|
|
681
|
-
if (toolbarDiv.children) {
|
|
682
|
-
const notEditingSpan = toolbarDiv.children[0];
|
|
683
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 0) {
|
|
684
|
-
const addTooltip = notEditingSpan.children[0];
|
|
685
|
-
if (addTooltip && addTooltip.children && addTooltip.children.length > 0) {
|
|
686
|
-
const addButton = addTooltip.children[0];
|
|
687
|
-
const button = new Button(addButton);
|
|
688
|
-
const event = new Event('click');
|
|
689
|
-
button.click(event, {} as HTMLElement);
|
|
690
|
-
expect(addClickCalled).toBeFalsy();
|
|
691
|
-
instance.events = {
|
|
692
|
-
addClick: () => { addClickCalled = true; },
|
|
693
|
-
};
|
|
694
|
-
expect(instance.editingNewRows).toBeTruthy();
|
|
695
|
-
button.click(event, {} as HTMLElement);
|
|
696
|
-
expect(addClickCalled).toBeTruthy();
|
|
697
|
-
expect(button.isVisible).toBeTruthy();
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
describe('hideButtonClick', () => {
|
|
705
|
-
it('deve alternar as classes para o estado "escondido" quando a toolbar está visível', () => {
|
|
706
|
-
const instance = new TekGrid({
|
|
707
|
-
name: 'grid_hide_test',
|
|
708
|
-
component: 'TekGrid',
|
|
709
|
-
});
|
|
710
|
-
instance.onCreated();
|
|
711
|
-
|
|
712
|
-
const mockToolbarDiv = { cssClass: 'toolbar-visible' };
|
|
713
|
-
const mockIcon = { cssClass: '' };
|
|
714
|
-
const mockTooltip = { label: 'TEKGRID_HIDE' };
|
|
715
|
-
|
|
716
|
-
jest.spyOn(Metadata, 'getInstance').mockImplementation((name: string) => {
|
|
717
|
-
if (name.includes('_toolbarDiv')) return mockToolbarDiv;
|
|
718
|
-
if (name.includes('_hideButton')) return mockIcon;
|
|
719
|
-
if (name.includes('_hideTooltip')) return mockTooltip;
|
|
720
|
-
return null;
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
const hideTooltip = instance.toolbarSlot[1];
|
|
724
|
-
const hideButtonDef = hideTooltip.children![0];
|
|
725
|
-
const button = new Button(hideButtonDef);
|
|
726
|
-
const event = new Event('click');
|
|
727
|
-
|
|
728
|
-
button.click(event, {} as HTMLElement);
|
|
729
|
-
|
|
730
|
-
expect(mockToolbarDiv.cssClass).toBe('');
|
|
731
|
-
expect(mockIcon.cssClass).toBe('is-rotated');
|
|
732
|
-
expect(mockTooltip.label).toBe('TEKGRID_SHOW');
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
it('deve alternar as classes de volta para o estado "visível" quando a toolbar está escondida', () => {
|
|
736
|
-
const instance = new TekGrid({
|
|
737
|
-
name: 'grid_show_test',
|
|
738
|
-
component: 'TekGrid',
|
|
739
|
-
});
|
|
740
|
-
instance.onCreated();
|
|
741
|
-
|
|
742
|
-
const mockToolbarDiv = { cssClass: '' };
|
|
743
|
-
const mockIcon = { cssClass: 'is-rotated' };
|
|
744
|
-
const mockTooltip = { label: 'TEKGRID_SHOW' };
|
|
745
|
-
|
|
746
|
-
jest.spyOn(Metadata, 'getInstance').mockImplementation((name: string) => {
|
|
747
|
-
if (name.includes('_toolbarDiv')) return mockToolbarDiv;
|
|
748
|
-
if (name.includes('_hideButton')) return mockIcon;
|
|
749
|
-
if (name.includes('_hideTooltip')) return mockTooltip;
|
|
750
|
-
return null;
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
const hideTooltip = instance.toolbarSlot[1];
|
|
754
|
-
const hideButtonDef = hideTooltip.children![0];
|
|
755
|
-
const button = new Button(hideButtonDef);
|
|
756
|
-
const event = new Event('click');
|
|
757
|
-
|
|
758
|
-
button.click(event, {} as HTMLElement);
|
|
759
|
-
|
|
760
|
-
expect(mockToolbarDiv.cssClass).toBe('toolbar-visible');
|
|
761
|
-
expect(mockIcon.cssClass).toBe('');
|
|
762
|
-
expect(mockTooltip.label).toBe('TEKGRID_HIDE');
|
|
763
|
-
});
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
describe('deleteButtonClick()', () => {
|
|
767
|
-
it('should call deleteRows', () => {
|
|
768
|
-
const instance = new TekGrid({
|
|
769
|
-
name: 'grid_deleteButtonClick1',
|
|
770
|
-
component: 'TekGrid',
|
|
771
|
-
deleteButton: 'currentRow',
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
const spy = jest.spyOn(instance, 'deleteRows');
|
|
775
|
-
instance.onCreated();
|
|
776
|
-
const notEditingTag = instance.toolbarSlot[2];
|
|
777
|
-
if (notEditingTag.children) {
|
|
778
|
-
const notEditingSpan = notEditingTag.children[0];
|
|
779
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
780
|
-
const deleteTooltip = notEditingSpan.children[1];
|
|
781
|
-
if (deleteTooltip && deleteTooltip.children && deleteTooltip.children.length > 0) {
|
|
782
|
-
const deleteButton = deleteTooltip.children[0];
|
|
783
|
-
const button = new Button(deleteButton);
|
|
784
|
-
const event = new Event('click');
|
|
785
|
-
button.click(event, {} as HTMLElement);
|
|
786
|
-
expect(spy).toBeCalled();
|
|
787
|
-
expect(button.isVisible).toBeTruthy();
|
|
788
|
-
expect(button.disabled).toBeTruthy();
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
spy.mockReset();
|
|
793
|
-
});
|
|
794
|
-
|
|
795
|
-
it('should call events', () => {
|
|
796
|
-
let beforeDeleteCalled = false;
|
|
797
|
-
let afterDeleteCalled = false;
|
|
798
|
-
const instance = new TekGrid({
|
|
799
|
-
name: 'grid_deleteClick2',
|
|
800
|
-
component: 'TekGrid',
|
|
801
|
-
events: {
|
|
802
|
-
beforeDelete: () => { beforeDeleteCalled = true; },
|
|
803
|
-
afterDelete: () => { afterDeleteCalled = true; },
|
|
804
|
-
},
|
|
805
|
-
});
|
|
806
|
-
|
|
807
|
-
instance.onCreated();
|
|
808
|
-
const notEditingSpan = instance.toolbarSlot[2];
|
|
809
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
810
|
-
const deleteTooltip = notEditingSpan.children[1];
|
|
811
|
-
if (deleteTooltip && deleteTooltip.children && deleteTooltip.children.length > 0) {
|
|
812
|
-
const deleteButton = deleteTooltip.children[0];
|
|
813
|
-
const button = new Button(deleteButton);
|
|
814
|
-
const event = new Event('click');
|
|
815
|
-
button.click(event, {} as HTMLElement);
|
|
816
|
-
expect(beforeDeleteCalled).toBeTruthy();
|
|
817
|
-
expect(afterDeleteCalled).toBeTruthy();
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
it('should not call cancelEditedRows if beforeSave call preventDefault', () => {
|
|
823
|
-
let beforeDeleteCalled = false;
|
|
824
|
-
let afterDeleteCalled = false;
|
|
825
|
-
const instance = new TekGrid({
|
|
826
|
-
name: 'grid_deleteClick3',
|
|
827
|
-
component: 'TekGrid',
|
|
828
|
-
events: {
|
|
829
|
-
beforeDelete: () => { beforeDeleteCalled = true; },
|
|
830
|
-
afterDelete: () => { afterDeleteCalled = true; },
|
|
831
|
-
},
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
835
|
-
instance.onCreated();
|
|
836
|
-
const notEditingSpan = instance.toolbarSlot[2];
|
|
837
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
838
|
-
const deleteTooltip = notEditingSpan.children[0];
|
|
839
|
-
if (deleteTooltip.children) {
|
|
840
|
-
const teste = deleteTooltip.children[1];
|
|
841
|
-
if (teste && teste.children && teste.children.length > 0) {
|
|
842
|
-
const deleteButton = teste.children[0];
|
|
843
|
-
const button = new Button(deleteButton);
|
|
844
|
-
button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
845
|
-
expect(beforeDeleteCalled).toBeTruthy();
|
|
846
|
-
expect(afterDeleteCalled).toBeFalsy();
|
|
847
|
-
expect(spy).not.toBeCalled();
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
spy.mockReset();
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
it('when deleteButton is clicked with selectAllPages, should throw', () => {
|
|
855
|
-
const instance = new TekGrid({
|
|
856
|
-
name: 'grid_deleteButtonClick1',
|
|
857
|
-
component: 'TekGrid',
|
|
858
|
-
deleteButton: 'selection',
|
|
859
|
-
selectAllPages: true,
|
|
860
|
-
datasource: {
|
|
861
|
-
data: [{ id: '1' }],
|
|
862
|
-
},
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
instance.onCreated();
|
|
866
|
-
const notEditingSpan = instance.toolbarSlot[2];
|
|
867
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
868
|
-
const deleteTooltip = notEditingSpan.children[0];
|
|
869
|
-
if (deleteTooltip.children) {
|
|
870
|
-
const teste = deleteTooltip.children[1];
|
|
871
|
-
if (teste && teste.children && teste.children.length > 0) {
|
|
872
|
-
const deleteButton = teste.children[0];
|
|
873
|
-
const button = new Button(deleteButton);
|
|
874
|
-
const event = new Event('click');
|
|
875
|
-
expect(button.isVisible).toBeTruthy();
|
|
876
|
-
expect(button.disabled).toBeTruthy();
|
|
877
|
-
instance.selectAll(true);
|
|
878
|
-
expect(button.disabled).toBeFalsy();
|
|
879
|
-
expect(() => button.click(event, {} as HTMLElement)).toThrow();
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
});
|
|
885
|
-
|
|
886
|
-
describe('disableDeleteButton', () => {
|
|
887
|
-
it('should not disable deleteButton when deleteButton equals none', () => {
|
|
888
|
-
const instance = new TekGrid({
|
|
889
|
-
name: 'grid_deleteButtonClick1',
|
|
890
|
-
component: 'TekGrid',
|
|
891
|
-
deleteButton: 'none',
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
instance.onCreated();
|
|
895
|
-
const notEditingSpan = instance.toolbarSlot[2];
|
|
896
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 1) {
|
|
897
|
-
const deleteTooltip = notEditingSpan.children[0];
|
|
898
|
-
if (deleteTooltip.children) {
|
|
899
|
-
const test = deleteTooltip.children[1];
|
|
900
|
-
if (test && test.children && test.children.length > 0) {
|
|
901
|
-
const deleteButton = test.children[0];
|
|
902
|
-
const button = new Button(deleteButton);
|
|
903
|
-
expect(button.isVisible).toBeFalsy();
|
|
904
|
-
expect(button.disabled).toBeFalsy();
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
describe('navigation', () => {
|
|
912
|
-
const dispatchEvent = (key: string, modifiers: any) => {
|
|
913
|
-
const event = new KeyboardEvent('keydown', modifiers);
|
|
914
|
-
delete (event as any).key;
|
|
915
|
-
Object.defineProperty(event, 'key', { value: key });
|
|
916
|
-
delete (event as any).code;
|
|
917
|
-
Object.defineProperty(event, 'code', { value: key });
|
|
918
|
-
document.dispatchEvent(event);
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
it('should navigate through grid lines using keys', async () => {
|
|
922
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
923
|
-
data: {
|
|
924
|
-
data: [],
|
|
925
|
-
pagination: {
|
|
926
|
-
page: 1,
|
|
927
|
-
total: 0,
|
|
928
|
-
limit: 10,
|
|
929
|
-
},
|
|
930
|
-
},
|
|
931
|
-
}));
|
|
932
|
-
const instance = new TekGrid({
|
|
933
|
-
name: 'grid_navigation_1',
|
|
934
|
-
component: 'TekGrid',
|
|
935
|
-
columns: [
|
|
936
|
-
{
|
|
937
|
-
name: 'id',
|
|
938
|
-
label: 'id',
|
|
939
|
-
},
|
|
940
|
-
{
|
|
941
|
-
name: 'name',
|
|
942
|
-
label: 'name',
|
|
943
|
-
},
|
|
944
|
-
{
|
|
945
|
-
name: 'department',
|
|
946
|
-
label: 'department',
|
|
947
|
-
},
|
|
948
|
-
],
|
|
949
|
-
datasource: {
|
|
950
|
-
uniqueKey: 'id',
|
|
951
|
-
order: ['name.asc'],
|
|
952
|
-
data: [
|
|
953
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
954
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
955
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
956
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
957
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
958
|
-
],
|
|
959
|
-
},
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
await flushPromises();
|
|
963
|
-
|
|
964
|
-
const elem = document.createElement('DIV');
|
|
965
|
-
(KeyMap as any).isElementActive = () => true;
|
|
966
|
-
instance.onCreated();
|
|
967
|
-
instance.onMounted(elem);
|
|
968
|
-
instance.navigateDatasource(false);
|
|
969
|
-
expect(instance.datasource.currentRow).toEqual(instance.datasource.data[0]);
|
|
970
|
-
|
|
971
|
-
instance.navigateDatasource(false);
|
|
972
|
-
expect(instance.datasource.currentRow).toEqual(instance.datasource.data[1]);
|
|
973
|
-
|
|
974
|
-
instance.navigateDatasource(true);
|
|
975
|
-
expect(instance.datasource.currentRow).toEqual(instance.datasource.data[0]);
|
|
976
|
-
|
|
977
|
-
dispatchEvent('arrowright', {}); // arrow right
|
|
978
|
-
expect(instance.datasource.currentRow).toEqual(instance.datasource.data[0]);
|
|
979
|
-
|
|
980
|
-
dispatchEvent('arrowleft', {}); // arrow left
|
|
981
|
-
expect(instance.datasource.currentRow).toEqual(instance.datasource.data[0]);
|
|
982
|
-
|
|
983
|
-
httpSpy.mockReset();
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
it('should navigate through grid lines using keys when grouped', async () => {
|
|
987
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
988
|
-
data: {
|
|
989
|
-
data: [],
|
|
990
|
-
pagination: {
|
|
991
|
-
page: 1,
|
|
992
|
-
total: 0,
|
|
993
|
-
limit: 10,
|
|
994
|
-
},
|
|
995
|
-
},
|
|
996
|
-
}));
|
|
997
|
-
const instance = new TekGrid({
|
|
998
|
-
name: 'grid_navigation_2',
|
|
999
|
-
component: 'TekGrid',
|
|
1000
|
-
columns: [
|
|
1001
|
-
{
|
|
1002
|
-
name: 'id',
|
|
1003
|
-
label: 'id',
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: 'name',
|
|
1007
|
-
label: 'name',
|
|
1008
|
-
},
|
|
1009
|
-
{
|
|
1010
|
-
name: 'department',
|
|
1011
|
-
label: 'department',
|
|
1012
|
-
grouped: true,
|
|
1013
|
-
},
|
|
1014
|
-
],
|
|
1015
|
-
datasource: {
|
|
1016
|
-
uniqueKey: 'id',
|
|
1017
|
-
order: ['name.asc'],
|
|
1018
|
-
data: [
|
|
1019
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1020
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1021
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1022
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1023
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1024
|
-
],
|
|
1025
|
-
},
|
|
1026
|
-
});
|
|
1027
|
-
|
|
1028
|
-
const elem = document.createElement('DIV');
|
|
1029
|
-
(KeyMap as any).isElementActive = () => true;
|
|
1030
|
-
instance.onCreated();
|
|
1031
|
-
instance.onMounted(elem);
|
|
1032
|
-
|
|
1033
|
-
await flushPromises();
|
|
1034
|
-
|
|
1035
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1036
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
|
|
1037
|
-
|
|
1038
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1039
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
|
|
1040
|
-
|
|
1041
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1042
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
|
|
1043
|
-
|
|
1044
|
-
dispatchEvent('arrowup', {}); // arrow up
|
|
1045
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
|
|
1046
|
-
|
|
1047
|
-
dispatchEvent('arrowup', {}); // arrow up
|
|
1048
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
|
|
1049
|
-
|
|
1050
|
-
instance.datasource.currentRow = {};
|
|
1051
|
-
dispatchEvent('arrowup', {}); // arrow up
|
|
1052
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
|
|
1053
|
-
|
|
1054
|
-
[instance.datasource.currentRow] = instance.groupedData;
|
|
1055
|
-
expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
|
|
1056
|
-
dispatchEvent('arrowright', {}); // arrow right
|
|
1057
|
-
expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
|
|
1058
|
-
|
|
1059
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1060
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
|
|
1061
|
-
|
|
1062
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1063
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[2]);
|
|
1064
|
-
|
|
1065
|
-
dispatchEvent('arrowup', {}); // arrow up
|
|
1066
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
|
|
1067
|
-
|
|
1068
|
-
dispatchEvent('arrowleft', {}); // arrow left
|
|
1069
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
|
|
1070
|
-
|
|
1071
|
-
expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
|
|
1072
|
-
dispatchEvent('arrowleft', {}); // arrow left
|
|
1073
|
-
expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
|
|
1074
|
-
|
|
1075
|
-
[, , , , instance.datasource.currentRow] = instance.groupedData;
|
|
1076
|
-
expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
|
|
1077
|
-
dispatchEvent('arrowright', {}); // arrow right
|
|
1078
|
-
expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
|
|
1079
|
-
|
|
1080
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1081
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[5]);
|
|
1082
|
-
|
|
1083
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1084
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
|
|
1085
|
-
|
|
1086
|
-
dispatchEvent('arrowdown', {}); // arrow down
|
|
1087
|
-
expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
|
|
1088
|
-
|
|
1089
|
-
httpSpy.mockReset();
|
|
1090
|
-
});
|
|
1091
|
-
|
|
1092
|
-
it('should open filter modal input with keymap', async () => {
|
|
1093
|
-
const instance = new TekGrid({
|
|
1094
|
-
name: 'grid_navigation_2',
|
|
1095
|
-
component: 'TekGrid',
|
|
1096
|
-
filterButton: true,
|
|
1097
|
-
});
|
|
1098
|
-
const elem = document.createElement('DIV');
|
|
1099
|
-
|
|
1100
|
-
(KeyMap as any).isElementActive = () => true;
|
|
1101
|
-
|
|
1102
|
-
instance.onMounted(elem);
|
|
1103
|
-
await flushPromises();
|
|
1104
|
-
|
|
1105
|
-
const method = jest.fn();
|
|
1106
|
-
|
|
1107
|
-
const filterButton = new TekGridFilterButton({
|
|
1108
|
-
name: 'grid_navigation_2_filterButton',
|
|
1109
|
-
component: 'TekGridFilterButton',
|
|
1110
|
-
grid: instance,
|
|
1111
|
-
events: {
|
|
1112
|
-
click: method,
|
|
1113
|
-
},
|
|
1114
|
-
});
|
|
1115
|
-
|
|
1116
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => filterButton);
|
|
1117
|
-
filterButton.onCreated();
|
|
1118
|
-
|
|
1119
|
-
dispatchEvent('l', { ctrlKey: true }); // ctrl+l keydown
|
|
1120
|
-
await flushPromises();
|
|
1121
|
-
|
|
1122
|
-
instance.onBeforeDestroy();
|
|
1123
|
-
await flushPromises();
|
|
1124
|
-
|
|
1125
|
-
expect(method).toHaveBeenCalled();
|
|
1126
|
-
(KeyMap as any).isElementActive = () => false;
|
|
1127
|
-
spyMetadata.mockReset();
|
|
1128
|
-
});
|
|
1129
|
-
|
|
1130
|
-
it('should open action dropdown with keymap', async () => {
|
|
1131
|
-
const instance = new TekGrid({
|
|
1132
|
-
name: 'grid_navigation_2',
|
|
1133
|
-
component: 'TekGrid',
|
|
1134
|
-
});
|
|
1135
|
-
const elem = document.createElement('DIV');
|
|
1136
|
-
|
|
1137
|
-
(KeyMap as any).isElementActive = () => true;
|
|
1138
|
-
|
|
1139
|
-
instance.onMounted(elem);
|
|
1140
|
-
await flushPromises();
|
|
1141
|
-
|
|
1142
|
-
const instanceDropDown = new Dropdown({
|
|
1143
|
-
name: 'grid_navigation_2_actions_dropdown',
|
|
1144
|
-
component: 'ZdDropdown',
|
|
1145
|
-
activator: {
|
|
1146
|
-
name: 'grid_navigation_2_actionsButton',
|
|
1147
|
-
component: 'ZdButton',
|
|
1148
|
-
},
|
|
1149
|
-
children: [],
|
|
1150
|
-
});
|
|
1151
|
-
const instanceDropDownSpy = jest.spyOn(instanceDropDown, 'setFocus').mockImplementation(() => true);
|
|
1152
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => instanceDropDown);
|
|
1153
|
-
|
|
1154
|
-
dispatchEvent('enter', { ctrlKey: true, enterKey: true }); // ctrl + enter keydown
|
|
1155
|
-
await flushPromises();
|
|
1156
|
-
|
|
1157
|
-
expect(spyMetadata).toHaveBeenCalled();
|
|
1158
|
-
expect(instanceDropDownSpy).toHaveBeenCalled();
|
|
1159
|
-
|
|
1160
|
-
instance.onBeforeDestroy();
|
|
1161
|
-
await flushPromises();
|
|
1162
|
-
|
|
1163
|
-
(KeyMap as any).isElementActive = () => false;
|
|
1164
|
-
spyMetadata.mockReset();
|
|
1165
|
-
instanceDropDownSpy.mockReset();
|
|
1166
|
-
});
|
|
1167
|
-
|
|
1168
|
-
it('should focus in searchInput with keymap', async () => {
|
|
1169
|
-
const instance = new TekGrid({
|
|
1170
|
-
name: 'grid_navigation_3',
|
|
1171
|
-
component: 'TekGrid',
|
|
1172
|
-
});
|
|
1173
|
-
const elem = document.createElement('DIV');
|
|
1174
|
-
|
|
1175
|
-
(KeyMap as any).isElementActive = () => true;
|
|
1176
|
-
instance.onMounted(elem);
|
|
1177
|
-
await flushPromises();
|
|
1178
|
-
|
|
1179
|
-
const searchInput = new Search({
|
|
1180
|
-
name: 'grid_navigation_3_gridSearch',
|
|
1181
|
-
component: 'ZdSearch',
|
|
1182
|
-
parent: instance,
|
|
1183
|
-
});
|
|
1184
|
-
|
|
1185
|
-
const spySetFocus = jest.spyOn(searchInput, 'setFocus').mockImplementation(() => true);
|
|
1186
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => searchInput);
|
|
1187
|
-
|
|
1188
|
-
dispatchEvent('f', { ctrlKey: true }); // ctrl+f keydown
|
|
1189
|
-
await flushPromises();
|
|
1190
|
-
|
|
1191
|
-
expect(spySetFocus).toHaveBeenCalled();
|
|
1192
|
-
|
|
1193
|
-
instance.onBeforeDestroy();
|
|
1194
|
-
await flushPromises();
|
|
1195
|
-
|
|
1196
|
-
(KeyMap as any).isElementActive = () => false;
|
|
1197
|
-
spySetFocus.mockReset();
|
|
1198
|
-
spyMetadata.mockReset();
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
it('when using cellSelection, should use viewNavigate', async () => {
|
|
1202
|
-
const instance = new TekGrid({
|
|
1203
|
-
name: 'grid_navigation_1',
|
|
1204
|
-
component: 'TekGrid',
|
|
1205
|
-
cellSelection: true,
|
|
1206
|
-
columns: [
|
|
1207
|
-
{
|
|
1208
|
-
name: 'name',
|
|
1209
|
-
grouped: true,
|
|
1210
|
-
},
|
|
1211
|
-
],
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
const elem = document.createElement('DIV');
|
|
1215
|
-
(KeyMap as any).isElementActive = () => true;
|
|
1216
|
-
instance.onCreated();
|
|
1217
|
-
instance.onMounted(elem);
|
|
1218
|
-
|
|
1219
|
-
await flushPromises();
|
|
1220
|
-
const spy = jest.fn();
|
|
1221
|
-
instance.setViewNavigate(spy);
|
|
1222
|
-
|
|
1223
|
-
instance.navigateUp();
|
|
1224
|
-
|
|
1225
|
-
expect(spy).toHaveBeenLastCalledWith('up');
|
|
1226
|
-
|
|
1227
|
-
instance.navigateDown();
|
|
1228
|
-
|
|
1229
|
-
expect(spy).toHaveBeenLastCalledWith('down');
|
|
1230
|
-
});
|
|
1231
|
-
});
|
|
1232
|
-
|
|
1233
|
-
describe('reloadClick()', () => {
|
|
1234
|
-
it('should call event', () => {
|
|
1235
|
-
const instance = new TekGrid({
|
|
1236
|
-
name: 'grid_reloadClick1',
|
|
1237
|
-
component: 'TekGrid',
|
|
1238
|
-
});
|
|
1239
|
-
|
|
1240
|
-
const spy = jest.spyOn(instance, 'reload');
|
|
1241
|
-
instance.onCreated();
|
|
1242
|
-
const notEditingTag = instance.toolbarSlot[2];
|
|
1243
|
-
if (notEditingTag.children) {
|
|
1244
|
-
const notEditingSpan = notEditingTag.children[0];
|
|
1245
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 3) {
|
|
1246
|
-
const reloadTooltip = notEditingSpan.children[3];
|
|
1247
|
-
if (reloadTooltip && reloadTooltip.children && reloadTooltip.children.length > 0) {
|
|
1248
|
-
const reloadButton = reloadTooltip.children[0];
|
|
1249
|
-
const button = new Button(reloadButton);
|
|
1250
|
-
const event = new Event('click');
|
|
1251
|
-
button.click(event, {} as HTMLElement);
|
|
1252
|
-
expect(spy).toBeCalled();
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
spy.mockReset();
|
|
1257
|
-
});
|
|
1258
|
-
|
|
1259
|
-
it('should call beforeReload event', () => {
|
|
1260
|
-
const beforeSpy = jest.fn();
|
|
1261
|
-
const instance = new TekGrid({
|
|
1262
|
-
name: 'grid_reloadClick2',
|
|
1263
|
-
component: 'TekGrid',
|
|
1264
|
-
events: {
|
|
1265
|
-
beforeReload: beforeSpy,
|
|
1266
|
-
},
|
|
1267
|
-
});
|
|
1268
|
-
|
|
1269
|
-
const spy = jest.spyOn(instance, 'reload');
|
|
1270
|
-
instance.onCreated();
|
|
1271
|
-
const notEditingTag = instance.toolbarSlot[2];
|
|
1272
|
-
if (notEditingTag.children) {
|
|
1273
|
-
const notEditingSpan = notEditingTag.children[0];
|
|
1274
|
-
if (notEditingSpan && notEditingSpan.children && notEditingSpan.children.length > 3) {
|
|
1275
|
-
const reloadTooltip = notEditingSpan.children[3];
|
|
1276
|
-
if (reloadTooltip && reloadTooltip.children && reloadTooltip.children.length > 0) {
|
|
1277
|
-
const reloadButton = reloadTooltip.children[0];
|
|
1278
|
-
const button = new Button(reloadButton);
|
|
1279
|
-
setClick(button, { defaultPrevented: true });
|
|
1280
|
-
expect(beforeSpy).toBeCalled();
|
|
1281
|
-
expect(spy).not.toBeCalled();
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
spy.mockReset();
|
|
1286
|
-
});
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
describe('grouping', () => {
|
|
1290
|
-
it('should group data based on columns that have grouped property', async () => {
|
|
1291
|
-
const instance = createAndMount({
|
|
1292
|
-
name: 'grid_grouping_1',
|
|
1293
|
-
component: 'TekGrid',
|
|
1294
|
-
columns: [
|
|
1295
|
-
{
|
|
1296
|
-
name: 'id',
|
|
1297
|
-
label: 'id',
|
|
1298
|
-
},
|
|
1299
|
-
{
|
|
1300
|
-
name: 'name',
|
|
1301
|
-
label: 'name',
|
|
1302
|
-
},
|
|
1303
|
-
{
|
|
1304
|
-
name: 'department',
|
|
1305
|
-
label: 'department',
|
|
1306
|
-
grouped: true,
|
|
1307
|
-
},
|
|
1308
|
-
],
|
|
1309
|
-
datasource: {
|
|
1310
|
-
uniqueKey: 'id',
|
|
1311
|
-
order: ['name.asc'],
|
|
1312
|
-
data: [
|
|
1313
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1314
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1315
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1316
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1317
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1318
|
-
],
|
|
1319
|
-
},
|
|
1320
|
-
});
|
|
1321
|
-
|
|
1322
|
-
await flushPromises();
|
|
1323
|
-
|
|
1324
|
-
instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
|
|
1325
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1326
|
-
expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
|
|
1327
|
-
expect(instance.groupedData.length).toBe(7);
|
|
1328
|
-
expect(instance.groupedData[0].group).toBeTruthy();
|
|
1329
|
-
expect(instance.groupedData[0].groupLabel).toBe('department');
|
|
1330
|
-
expect(instance.groupedData[0].groupValue).toBe(1);
|
|
1331
|
-
expect(instance.groupedData[1].groupHeaders.length).toBe(1);
|
|
1332
|
-
expect(instance.groupedData[1].name).toBe('employee 1');
|
|
1333
|
-
});
|
|
1334
|
-
|
|
1335
|
-
it('should call debounced updateGroupData', () => {
|
|
1336
|
-
const spy = jest.spyOn(TekGrid.prototype, 'updateGroupedData');
|
|
1337
|
-
const instance = createAndMount({
|
|
1338
|
-
name: 'grid_grouping_1',
|
|
1339
|
-
component: 'TekGrid',
|
|
1340
|
-
columns: [
|
|
1341
|
-
{
|
|
1342
|
-
name: 'id',
|
|
1343
|
-
label: 'id',
|
|
1344
|
-
},
|
|
1345
|
-
{
|
|
1346
|
-
name: 'name',
|
|
1347
|
-
label: 'name',
|
|
1348
|
-
},
|
|
1349
|
-
{
|
|
1350
|
-
name: 'department',
|
|
1351
|
-
label: 'department',
|
|
1352
|
-
},
|
|
1353
|
-
],
|
|
1354
|
-
datasource: {
|
|
1355
|
-
uniqueKey: 'id',
|
|
1356
|
-
order: ['name.asc'],
|
|
1357
|
-
data: [
|
|
1358
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1359
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1360
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1361
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1362
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1363
|
-
],
|
|
1364
|
-
},
|
|
1365
|
-
});
|
|
1366
|
-
|
|
1367
|
-
jest.runAllTimers();
|
|
1368
|
-
|
|
1369
|
-
instance.columns[2].grouped = true;
|
|
1370
|
-
|
|
1371
|
-
expect(spy).toHaveBeenCalled();
|
|
1372
|
-
|
|
1373
|
-
spy.mockClear();
|
|
1374
|
-
});
|
|
1375
|
-
|
|
1376
|
-
it('should group data with aggregations', async () => {
|
|
1377
|
-
const instance = createAndMount({
|
|
1378
|
-
name: 'grid_aggregate_1',
|
|
1379
|
-
component: 'TekGrid',
|
|
1380
|
-
columns: [
|
|
1381
|
-
{
|
|
1382
|
-
name: 'id',
|
|
1383
|
-
label: 'id',
|
|
1384
|
-
aggregation: 'COUNT',
|
|
1385
|
-
},
|
|
1386
|
-
{
|
|
1387
|
-
name: 'name',
|
|
1388
|
-
label: 'name',
|
|
1389
|
-
},
|
|
1390
|
-
{
|
|
1391
|
-
name: 'department',
|
|
1392
|
-
label: 'department',
|
|
1393
|
-
grouped: true,
|
|
1394
|
-
},
|
|
1395
|
-
],
|
|
1396
|
-
datasource: {
|
|
1397
|
-
uniqueKey: 'id',
|
|
1398
|
-
order: ['name.asc'],
|
|
1399
|
-
data: [
|
|
1400
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1401
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1402
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1403
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1404
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1405
|
-
],
|
|
1406
|
-
},
|
|
1407
|
-
});
|
|
1408
|
-
|
|
1409
|
-
await flushPromises();
|
|
1410
|
-
|
|
1411
|
-
instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
|
|
1412
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1413
|
-
expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
|
|
1414
|
-
expect(instance.groupedData.length).toBe(10);
|
|
1415
|
-
expect(instance.groupedData[0].group).toBeTruthy();
|
|
1416
|
-
expect(instance.groupedData[0].groupLabel).toBe('department');
|
|
1417
|
-
expect(instance.groupedData[0].groupValue).toBe(1);
|
|
1418
|
-
expect(instance.groupedData[1].groupHeaders.length).toBe(1);
|
|
1419
|
-
expect(instance.groupedData[1].name).toBe('employee 1');
|
|
1420
|
-
expect(instance.groupedData[4].groupFooter).toBeTruthy();
|
|
1421
|
-
expect(instance.groupedData[4].id).toBe(3);
|
|
1422
|
-
expect(instance.groupedData[9].groupSummary).toBeTruthy();
|
|
1423
|
-
expect(instance.groupedData[9].id).toBe(5);
|
|
1424
|
-
});
|
|
1425
|
-
|
|
1426
|
-
it('should group data with multiple groups', async () => {
|
|
1427
|
-
let viewUpdateScrollDataCalled = false;
|
|
1428
|
-
|
|
1429
|
-
const instance = createAndMount({
|
|
1430
|
-
name: 'grid_grouping_2',
|
|
1431
|
-
component: 'TekGrid',
|
|
1432
|
-
virtualScroll: true,
|
|
1433
|
-
columns: [
|
|
1434
|
-
{
|
|
1435
|
-
name: 'id',
|
|
1436
|
-
label: 'id',
|
|
1437
|
-
},
|
|
1438
|
-
{
|
|
1439
|
-
name: 'name',
|
|
1440
|
-
label: 'name',
|
|
1441
|
-
},
|
|
1442
|
-
{
|
|
1443
|
-
name: 'department',
|
|
1444
|
-
label: 'department',
|
|
1445
|
-
grouped: true,
|
|
1446
|
-
},
|
|
1447
|
-
{
|
|
1448
|
-
name: 'boss',
|
|
1449
|
-
label: 'boss',
|
|
1450
|
-
groupLabelForEmptyValue: 'boss',
|
|
1451
|
-
grouped: true,
|
|
1452
|
-
},
|
|
1453
|
-
],
|
|
1454
|
-
datasource: {
|
|
1455
|
-
uniqueKey: 'id',
|
|
1456
|
-
order: ['name.asc'],
|
|
1457
|
-
data: [
|
|
1458
|
-
{
|
|
1459
|
-
id: 2, name: 'employee 2', department: 1, boss: 1,
|
|
1460
|
-
},
|
|
1461
|
-
{
|
|
1462
|
-
id: 5, name: 'employee 5', department: 2, boss: 4,
|
|
1463
|
-
},
|
|
1464
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1465
|
-
{
|
|
1466
|
-
id: 3, name: 'employee 3', department: 1, boss: 1,
|
|
1467
|
-
},
|
|
1468
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1469
|
-
],
|
|
1470
|
-
},
|
|
1471
|
-
});
|
|
1472
|
-
|
|
1473
|
-
await flushPromises();
|
|
1474
|
-
|
|
1475
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1476
|
-
expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
|
|
1477
|
-
expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
|
|
1478
|
-
expect(instance.groupedData.length).toBe(11);
|
|
1479
|
-
expect(instance.groupedData[0].group).toBeTruthy();
|
|
1480
|
-
expect(instance.groupedData[0].groupLabel).toBe('department');
|
|
1481
|
-
expect(instance.groupedData[0].groupValue).toBe(1);
|
|
1482
|
-
expect(instance.groupedData[1].group).toBeTruthy();
|
|
1483
|
-
expect(instance.groupedData[1].groupLabel).toBe('boss');
|
|
1484
|
-
expect(instance.groupedData[1].groupValue).toBe('boss');
|
|
1485
|
-
expect(instance.groupedData[2].groupHeaders.length).toBe(2);
|
|
1486
|
-
expect(instance.groupedData[2].name).toBe('employee 1');
|
|
1487
|
-
expect(instance.groupedData[3].group).toBeTruthy();
|
|
1488
|
-
expect(instance.groupedData[3].groupLabel).toBe('boss');
|
|
1489
|
-
expect(instance.groupedData[3].groupValue).toBe(1);
|
|
1490
|
-
|
|
1491
|
-
expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
|
|
1492
|
-
instance.openGroup(instance.groupedData[0]);
|
|
1493
|
-
expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
|
|
1494
|
-
expect(viewUpdateScrollDataCalled).toBeFalsy();
|
|
1495
|
-
|
|
1496
|
-
instance.viewUpdateScrollData = () => { viewUpdateScrollDataCalled = true; };
|
|
1497
|
-
instance.openGroup(instance.groupedData[1]);
|
|
1498
|
-
expect(instance.isItemVisible(instance.groupedData[2])).toBeTruthy();
|
|
1499
|
-
expect(viewUpdateScrollDataCalled).toBeTruthy();
|
|
1500
|
-
});
|
|
1501
|
-
|
|
1502
|
-
it('should group data with multiple groups and aggregation', async () => {
|
|
1503
|
-
const instance = createAndMount({
|
|
1504
|
-
name: 'grid_aggredate_2',
|
|
1505
|
-
component: 'TekGrid',
|
|
1506
|
-
showSummaryTotal: false,
|
|
1507
|
-
columns: [
|
|
1508
|
-
{
|
|
1509
|
-
name: 'id',
|
|
1510
|
-
label: 'id',
|
|
1511
|
-
aggregation: 'COUNT',
|
|
1512
|
-
},
|
|
1513
|
-
{
|
|
1514
|
-
name: 'name',
|
|
1515
|
-
label: 'name',
|
|
1516
|
-
},
|
|
1517
|
-
{
|
|
1518
|
-
name: 'salary',
|
|
1519
|
-
label: 'salary',
|
|
1520
|
-
aggregation: 'SUM',
|
|
1521
|
-
},
|
|
1522
|
-
{
|
|
1523
|
-
name: 'department',
|
|
1524
|
-
label: 'department',
|
|
1525
|
-
grouped: true,
|
|
1526
|
-
},
|
|
1527
|
-
{
|
|
1528
|
-
name: 'boss',
|
|
1529
|
-
label: 'boss',
|
|
1530
|
-
groupLabelForEmptyValue: 'boss',
|
|
1531
|
-
grouped: true,
|
|
1532
|
-
},
|
|
1533
|
-
],
|
|
1534
|
-
datasource: {
|
|
1535
|
-
uniqueKey: 'id',
|
|
1536
|
-
order: ['name.asc'],
|
|
1537
|
-
data: [
|
|
1538
|
-
{
|
|
1539
|
-
id: 2, name: 'employee 2', salary: 10, department: 1, boss: 1,
|
|
1540
|
-
},
|
|
1541
|
-
{
|
|
1542
|
-
id: 5, name: 'employee 5', salary: 10, department: 2, boss: 4,
|
|
1543
|
-
},
|
|
1544
|
-
{
|
|
1545
|
-
id: 4, name: 'employee 4', salary: 10, department: 2,
|
|
1546
|
-
},
|
|
1547
|
-
{
|
|
1548
|
-
id: 3, name: 'employee 3', salary: 10, department: 1, boss: 1,
|
|
1549
|
-
},
|
|
1550
|
-
{
|
|
1551
|
-
id: 1, name: 'employee 1', salary: 10, department: 1,
|
|
1552
|
-
},
|
|
1553
|
-
],
|
|
1554
|
-
},
|
|
1555
|
-
});
|
|
1556
|
-
|
|
1557
|
-
await flushPromises();
|
|
1558
|
-
|
|
1559
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1560
|
-
expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
|
|
1561
|
-
expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
|
|
1562
|
-
expect(instance.groupedData.length).toBe(17);
|
|
1563
|
-
expect(instance.groupedData[0].group).toBeTruthy();
|
|
1564
|
-
expect(instance.groupedData[0].groupLabel).toBe('department');
|
|
1565
|
-
expect(instance.groupedData[0].groupValue).toBe(1);
|
|
1566
|
-
expect(instance.groupedData[1].group).toBeTruthy();
|
|
1567
|
-
expect(instance.groupedData[1].groupLabel).toBe('boss');
|
|
1568
|
-
expect(instance.groupedData[1].groupValue).toBe('boss');
|
|
1569
|
-
expect(instance.groupedData[2].groupHeaders.length).toBe(2);
|
|
1570
|
-
expect(instance.groupedData[2].name).toBe('employee 1');
|
|
1571
|
-
expect(instance.groupedData[3].groupFooter).toBeTruthy();
|
|
1572
|
-
expect(instance.groupedData[3].id).toBe(1);
|
|
1573
|
-
expect(instance.groupedData[3].salary).toBe(10);
|
|
1574
|
-
expect(instance.groupedData[4].group).toBeTruthy();
|
|
1575
|
-
expect(instance.groupedData[4].groupLabel).toBe('boss');
|
|
1576
|
-
expect(instance.groupedData[4].groupValue).toBe(1);
|
|
1577
|
-
expect(instance.groupedData[7].groupFooter).toBeTruthy();
|
|
1578
|
-
expect(instance.groupedData[7].id).toBe(2);
|
|
1579
|
-
expect(instance.groupedData[7].salary).toBe(20);
|
|
1580
|
-
expect(instance.groupedData[8].groupFooter).toBeTruthy();
|
|
1581
|
-
expect(instance.groupedData[8].id).toBe(3);
|
|
1582
|
-
expect(instance.groupedData[8].salary).toBe(30);
|
|
1583
|
-
});
|
|
1584
|
-
|
|
1585
|
-
it('should aggregate even without groups', async () => {
|
|
1586
|
-
const instance = createAndMount({
|
|
1587
|
-
name: 'grid_aggredate_3',
|
|
1588
|
-
component: 'TekGrid',
|
|
1589
|
-
showSummaryTotal: true,
|
|
1590
|
-
columns: [
|
|
1591
|
-
{
|
|
1592
|
-
name: 'id',
|
|
1593
|
-
label: 'id',
|
|
1594
|
-
aggregation: 'COUNT',
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
name: 'name',
|
|
1598
|
-
label: 'name',
|
|
1599
|
-
},
|
|
1600
|
-
{
|
|
1601
|
-
name: 'salary',
|
|
1602
|
-
label: 'salary',
|
|
1603
|
-
aggregation: 'SUM',
|
|
1604
|
-
},
|
|
1605
|
-
{
|
|
1606
|
-
name: 'department',
|
|
1607
|
-
label: 'department',
|
|
1608
|
-
},
|
|
1609
|
-
{
|
|
1610
|
-
name: 'boss',
|
|
1611
|
-
label: 'boss',
|
|
1612
|
-
groupLabelForEmptyValue: 'boss',
|
|
1613
|
-
},
|
|
1614
|
-
],
|
|
1615
|
-
datasource: {
|
|
1616
|
-
uniqueKey: 'id',
|
|
1617
|
-
order: ['name.asc'],
|
|
1618
|
-
data: [
|
|
1619
|
-
{
|
|
1620
|
-
id: 2, name: 'employee 2', salary: 10, department: 1, boss: 1,
|
|
1621
|
-
},
|
|
1622
|
-
{
|
|
1623
|
-
id: 5, name: 'employee 5', salary: 10, department: 2, boss: 4,
|
|
1624
|
-
},
|
|
1625
|
-
{
|
|
1626
|
-
id: 4, name: 'employee 4', salary: 10, department: 2,
|
|
1627
|
-
},
|
|
1628
|
-
{
|
|
1629
|
-
id: 3, name: 'employee 3', salary: 10, department: 1, boss: 1,
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
id: 1, name: 'employee 1', salary: 10, department: 1,
|
|
1633
|
-
},
|
|
1634
|
-
],
|
|
1635
|
-
},
|
|
1636
|
-
});
|
|
1637
|
-
|
|
1638
|
-
await flushPromises();
|
|
1639
|
-
|
|
1640
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1641
|
-
expect(instance.groupedData.length).toBe(6);
|
|
1642
|
-
expect(instance.groupedData[5].groupSummary).toBeTruthy();
|
|
1643
|
-
expect(instance.groupedData[5].salary).toBe(50);
|
|
1644
|
-
});
|
|
1645
|
-
|
|
1646
|
-
it('should aggregate with different functions', async () => {
|
|
1647
|
-
const instance = createAndMount({
|
|
1648
|
-
name: 'grid_aggregate_4',
|
|
1649
|
-
component: 'TekGrid',
|
|
1650
|
-
showSummaryTotal: true,
|
|
1651
|
-
columns: [
|
|
1652
|
-
{
|
|
1653
|
-
name: 'id',
|
|
1654
|
-
label: 'id',
|
|
1655
|
-
},
|
|
1656
|
-
{
|
|
1657
|
-
name: 'column_sum',
|
|
1658
|
-
label: 'sum',
|
|
1659
|
-
aggregation: 'SUM',
|
|
1660
|
-
},
|
|
1661
|
-
{
|
|
1662
|
-
name: 'column_min',
|
|
1663
|
-
label: 'min',
|
|
1664
|
-
aggregation: 'MIN',
|
|
1665
|
-
},
|
|
1666
|
-
{
|
|
1667
|
-
name: 'column_max',
|
|
1668
|
-
label: 'max',
|
|
1669
|
-
aggregation: 'MAX',
|
|
1670
|
-
},
|
|
1671
|
-
{
|
|
1672
|
-
name: 'column_avg',
|
|
1673
|
-
label: 'avg',
|
|
1674
|
-
aggregation: 'AVG',
|
|
1675
|
-
},
|
|
1676
|
-
{
|
|
1677
|
-
name: 'column_count',
|
|
1678
|
-
label: 'count',
|
|
1679
|
-
aggregation: 'COUNT',
|
|
1680
|
-
},
|
|
1681
|
-
{
|
|
1682
|
-
name: 'department',
|
|
1683
|
-
label: 'department',
|
|
1684
|
-
grouped: true,
|
|
1685
|
-
},
|
|
1686
|
-
],
|
|
1687
|
-
datasource: {
|
|
1688
|
-
uniqueKey: 'id',
|
|
1689
|
-
data: [
|
|
1690
|
-
{
|
|
1691
|
-
id: 1, department: 1, column_sum: 10, column_min: 10, column_max: '10', column_avg: 10, column_count: 10,
|
|
1692
|
-
},
|
|
1693
|
-
{
|
|
1694
|
-
id: 2, department: 1, column_sum: 20, column_min: 20, column_max: '20', column_avg: 20, column_count: 20,
|
|
1695
|
-
},
|
|
1696
|
-
{
|
|
1697
|
-
id: 3, department: 1, column_sum: 100, column_min: 100, column_max: '100', column_avg: 100, column_count: 100,
|
|
1698
|
-
},
|
|
1699
|
-
{
|
|
1700
|
-
id: 4, department: 1, column_min: 5, column_max: '5', column_avg: 5,
|
|
1701
|
-
},
|
|
1702
|
-
],
|
|
1703
|
-
},
|
|
1704
|
-
});
|
|
1705
|
-
|
|
1706
|
-
await flushPromises();
|
|
1707
|
-
|
|
1708
|
-
expect(instance.datasource.data.length).toBe(4);
|
|
1709
|
-
expect(instance.groupedData.length).toBe(7);
|
|
1710
|
-
expect(instance.groupedData[6].groupSummary).toBeTruthy();
|
|
1711
|
-
expect(instance.groupedData[6].column_sum).toBe(130);
|
|
1712
|
-
expect(instance.groupedData[6].column_min).toBe(5);
|
|
1713
|
-
expect(instance.groupedData[6].column_max).toBe('5');
|
|
1714
|
-
expect(instance.groupedData[6].column_avg).toBe(33.75);
|
|
1715
|
-
expect(instance.groupedData[6].column_count).toBe(3);
|
|
1716
|
-
});
|
|
1717
|
-
|
|
1718
|
-
it('should aggregate using calcSummary event', async () => {
|
|
1719
|
-
const doCalcSummary = ({ summary, rowValue }: IEventParam<any>) => {
|
|
1720
|
-
summary.sum = `${(summary.sum || '')}${rowValue}`;
|
|
1721
|
-
summary.avg = `${summary.sum}/${summary.count}`;
|
|
1722
|
-
summary.max = summary.max === undefined || summary.max < rowValue ? rowValue : summary.max;
|
|
1723
|
-
summary.min = summary.min === undefined || summary.min > rowValue ? rowValue : summary.min;
|
|
1724
|
-
};
|
|
1725
|
-
|
|
1726
|
-
const instance = createAndMount({
|
|
1727
|
-
name: 'grid_aggregate_5',
|
|
1728
|
-
component: 'TekGrid',
|
|
1729
|
-
showSummaryTotal: true,
|
|
1730
|
-
events: {
|
|
1731
|
-
calcSummary: doCalcSummary,
|
|
1732
|
-
},
|
|
1733
|
-
columns: [
|
|
1734
|
-
{
|
|
1735
|
-
name: 'id',
|
|
1736
|
-
label: 'id',
|
|
1737
|
-
},
|
|
1738
|
-
{
|
|
1739
|
-
name: 'column_sum',
|
|
1740
|
-
label: 'sum',
|
|
1741
|
-
aggregation: 'SUM',
|
|
1742
|
-
},
|
|
1743
|
-
{
|
|
1744
|
-
name: 'column_min',
|
|
1745
|
-
label: 'min',
|
|
1746
|
-
aggregation: 'MIN',
|
|
1747
|
-
},
|
|
1748
|
-
{
|
|
1749
|
-
name: 'column_max',
|
|
1750
|
-
label: 'max',
|
|
1751
|
-
aggregation: 'MAX',
|
|
1752
|
-
},
|
|
1753
|
-
{
|
|
1754
|
-
name: 'column_avg',
|
|
1755
|
-
label: 'avg',
|
|
1756
|
-
aggregation: 'AVG',
|
|
1757
|
-
},
|
|
1758
|
-
{
|
|
1759
|
-
name: 'column_count',
|
|
1760
|
-
label: 'count',
|
|
1761
|
-
aggregation: 'COUNT',
|
|
1762
|
-
},
|
|
1763
|
-
{
|
|
1764
|
-
name: 'department',
|
|
1765
|
-
label: 'department',
|
|
1766
|
-
grouped: true,
|
|
1767
|
-
},
|
|
1768
|
-
],
|
|
1769
|
-
datasource: {
|
|
1770
|
-
uniqueKey: 'id',
|
|
1771
|
-
data: [
|
|
1772
|
-
{
|
|
1773
|
-
id: 1, department: 1, column_sum: 'd', column_min: 'd', column_max: 'd', column_avg: 'd', column_count: 'd',
|
|
1774
|
-
},
|
|
1775
|
-
{
|
|
1776
|
-
id: 2, department: 1, column_sum: 'b', column_min: 'b', column_max: 'b', column_avg: 'b', column_count: 'b',
|
|
1777
|
-
},
|
|
1778
|
-
{
|
|
1779
|
-
id: 3, department: 1, column_sum: 'a', column_min: 'a', column_max: 'a', column_avg: 'a', column_count: 'a',
|
|
1780
|
-
},
|
|
1781
|
-
{
|
|
1782
|
-
id: 4, department: 1, column_sum: 'c', column_min: 'c', column_max: 'c', column_avg: 'c', column_count: 'c',
|
|
1783
|
-
},
|
|
1784
|
-
],
|
|
1785
|
-
},
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
|
-
await flushPromises();
|
|
1789
|
-
|
|
1790
|
-
expect(instance.datasource.data.length).toBe(4);
|
|
1791
|
-
expect(instance.groupedData.length).toBe(7);
|
|
1792
|
-
expect(instance.groupedData[6].groupSummary).toBeTruthy();
|
|
1793
|
-
expect(instance.groupedData[6].column_sum).toBe('dbac');
|
|
1794
|
-
expect(instance.groupedData[6].column_min).toBe('a');
|
|
1795
|
-
expect(instance.groupedData[6].column_max).toBe('d');
|
|
1796
|
-
expect(instance.groupedData[6].column_avg).toBe('dbac/4');
|
|
1797
|
-
expect(instance.groupedData[6].column_count).toBe(4);
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
it('should group data on rest datasource with lazyLoad', async () => {
|
|
1801
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
1802
|
-
data: {
|
|
1803
|
-
data: [
|
|
1804
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1805
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1806
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1807
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1808
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1809
|
-
],
|
|
1810
|
-
pagination: {
|
|
1811
|
-
page: 1,
|
|
1812
|
-
total: 5,
|
|
1813
|
-
limit: 15,
|
|
1814
|
-
},
|
|
1815
|
-
},
|
|
1816
|
-
}));
|
|
1817
|
-
|
|
1818
|
-
const instance = createAndMount({
|
|
1819
|
-
name: 'grid_grouping_3',
|
|
1820
|
-
component: 'TekGrid',
|
|
1821
|
-
columns: [
|
|
1822
|
-
{
|
|
1823
|
-
name: 'id',
|
|
1824
|
-
label: 'id',
|
|
1825
|
-
},
|
|
1826
|
-
{
|
|
1827
|
-
name: 'name',
|
|
1828
|
-
label: 'name',
|
|
1829
|
-
},
|
|
1830
|
-
{
|
|
1831
|
-
name: 'department',
|
|
1832
|
-
label: 'department',
|
|
1833
|
-
grouped: true,
|
|
1834
|
-
},
|
|
1835
|
-
],
|
|
1836
|
-
datasource: {
|
|
1837
|
-
uniqueKey: 'id',
|
|
1838
|
-
order: ['name.asc'],
|
|
1839
|
-
type: 'rest',
|
|
1840
|
-
route: '/zeedhi',
|
|
1841
|
-
lazyLoad: true,
|
|
1842
|
-
},
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
await flushPromises();
|
|
1846
|
-
|
|
1847
|
-
expect(instance.datasource.data.length).toBe(0);
|
|
1848
|
-
|
|
1849
|
-
await instance.datasource.get();
|
|
1850
|
-
|
|
1851
|
-
expect(instance.datasource.data.length).toBe(5);
|
|
1852
|
-
expect(instance.groupedData.length).toBe(7);
|
|
1853
|
-
|
|
1854
|
-
httpSpy.mockReset();
|
|
1855
|
-
});
|
|
1856
|
-
|
|
1857
|
-
it('editedRows should return cleaned rows', async () => {
|
|
1858
|
-
const instance = new TekGrid({
|
|
1859
|
-
name: 'grid_grouping_4',
|
|
1860
|
-
component: 'TekGrid',
|
|
1861
|
-
columns: [
|
|
1862
|
-
{
|
|
1863
|
-
name: 'id',
|
|
1864
|
-
label: 'id',
|
|
1865
|
-
},
|
|
1866
|
-
{
|
|
1867
|
-
name: 'name',
|
|
1868
|
-
label: 'name',
|
|
1869
|
-
editable: true,
|
|
1870
|
-
},
|
|
1871
|
-
{
|
|
1872
|
-
name: 'department',
|
|
1873
|
-
label: 'department',
|
|
1874
|
-
grouped: true,
|
|
1875
|
-
},
|
|
1876
|
-
],
|
|
1877
|
-
datasource: {
|
|
1878
|
-
uniqueKey: 'id',
|
|
1879
|
-
order: ['name.asc'],
|
|
1880
|
-
data: [
|
|
1881
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1882
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1883
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1884
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1885
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1886
|
-
],
|
|
1887
|
-
},
|
|
1888
|
-
});
|
|
1889
|
-
|
|
1890
|
-
await flushPromises();
|
|
1891
|
-
|
|
1892
|
-
instance.editing = true;
|
|
1893
|
-
instance.updateRow({ id: 1, name: 'employee 111', department: 1 });
|
|
1894
|
-
const editedRows = instance.getEditedRows();
|
|
1895
|
-
expect(editedRows.length).toBe(1);
|
|
1896
|
-
expect(editedRows[0].groupHeaders).toBeUndefined();
|
|
1897
|
-
});
|
|
1898
|
-
|
|
1899
|
-
it('should do nothing if datasource is empty', async () => {
|
|
1900
|
-
const instance = new TekGrid({
|
|
1901
|
-
name: 'grid_grouping_5',
|
|
1902
|
-
component: 'TekGrid',
|
|
1903
|
-
columns: [
|
|
1904
|
-
{
|
|
1905
|
-
name: 'id',
|
|
1906
|
-
label: 'id',
|
|
1907
|
-
},
|
|
1908
|
-
{
|
|
1909
|
-
name: 'name',
|
|
1910
|
-
label: 'name',
|
|
1911
|
-
editable: true,
|
|
1912
|
-
},
|
|
1913
|
-
{
|
|
1914
|
-
name: 'department',
|
|
1915
|
-
label: 'department',
|
|
1916
|
-
grouped: true,
|
|
1917
|
-
},
|
|
1918
|
-
],
|
|
1919
|
-
datasource: {
|
|
1920
|
-
uniqueKey: 'id',
|
|
1921
|
-
data: [],
|
|
1922
|
-
},
|
|
1923
|
-
});
|
|
1924
|
-
|
|
1925
|
-
await flushPromises();
|
|
1926
|
-
|
|
1927
|
-
expect(instance.datasource.data.length).toBe(0);
|
|
1928
|
-
expect(instance.groupedData.length).toBe(0);
|
|
1929
|
-
});
|
|
1930
|
-
|
|
1931
|
-
it('should call view update methods', async () => {
|
|
1932
|
-
let viewUpdateScrollDataCalled = false;
|
|
1933
|
-
let viewUpdateFixedColumnsCalled = false;
|
|
1934
|
-
|
|
1935
|
-
const instance = createAndMount({
|
|
1936
|
-
name: 'grid_grouping_6',
|
|
1937
|
-
component: 'TekGrid',
|
|
1938
|
-
virtualScroll: true,
|
|
1939
|
-
columns: [
|
|
1940
|
-
{
|
|
1941
|
-
name: 'id',
|
|
1942
|
-
label: 'id',
|
|
1943
|
-
},
|
|
1944
|
-
{
|
|
1945
|
-
name: 'name',
|
|
1946
|
-
label: 'name',
|
|
1947
|
-
},
|
|
1948
|
-
{
|
|
1949
|
-
name: 'department',
|
|
1950
|
-
label: 'department',
|
|
1951
|
-
grouped: true,
|
|
1952
|
-
},
|
|
1953
|
-
],
|
|
1954
|
-
datasource: {
|
|
1955
|
-
uniqueKey: 'id',
|
|
1956
|
-
order: ['name.asc'],
|
|
1957
|
-
data: [
|
|
1958
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
1959
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
1960
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
1961
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
1962
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
1963
|
-
],
|
|
1964
|
-
},
|
|
1965
|
-
});
|
|
1966
|
-
instance.viewUpdateScrollData = () => { viewUpdateScrollDataCalled = true; };
|
|
1967
|
-
instance.viewUpdateFixedColumns = () => { viewUpdateFixedColumnsCalled = true; };
|
|
1968
|
-
|
|
1969
|
-
await flushPromises();
|
|
1970
|
-
|
|
1971
|
-
expect(viewUpdateScrollDataCalled).toBeTruthy();
|
|
1972
|
-
expect(viewUpdateFixedColumnsCalled).toBeTruthy();
|
|
1973
|
-
});
|
|
1974
|
-
|
|
1975
|
-
it('should call debounced updateGroupData', () => {
|
|
1976
|
-
const spy = jest.spyOn(TekGrid.prototype, 'updateGroupedData');
|
|
1977
|
-
const instance = new TekGrid({
|
|
1978
|
-
name: 'grid_grouping_1',
|
|
1979
|
-
component: 'TekGrid',
|
|
1980
|
-
columns: [
|
|
1981
|
-
{
|
|
1982
|
-
name: 'id',
|
|
1983
|
-
label: 'id',
|
|
1984
|
-
},
|
|
1985
|
-
{
|
|
1986
|
-
name: 'name',
|
|
1987
|
-
label: 'name',
|
|
1988
|
-
},
|
|
1989
|
-
{
|
|
1990
|
-
name: 'department',
|
|
1991
|
-
label: 'department',
|
|
1992
|
-
grouped: true,
|
|
1993
|
-
},
|
|
1994
|
-
],
|
|
1995
|
-
datasource: {
|
|
1996
|
-
uniqueKey: 'id',
|
|
1997
|
-
order: ['name.asc'],
|
|
1998
|
-
data: [
|
|
1999
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
2000
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
2001
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
2002
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
2003
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
2004
|
-
],
|
|
2005
|
-
},
|
|
2006
|
-
});
|
|
2007
|
-
|
|
2008
|
-
jest.runAllTimers();
|
|
2009
|
-
|
|
2010
|
-
instance.columns[2].groupOpened = true;
|
|
2011
|
-
|
|
2012
|
-
expect(spy).toHaveBeenCalled();
|
|
2013
|
-
|
|
2014
|
-
spy.mockClear();
|
|
2015
|
-
});
|
|
2016
|
-
});
|
|
2017
|
-
|
|
2018
|
-
describe('updateSummary()', () => {
|
|
2019
|
-
it('should update aggregation data always using the visible cell value', async () => {
|
|
2020
|
-
const instance = await createGroupedGrid({
|
|
2021
|
-
columns: [
|
|
2022
|
-
{ name: 'id' },
|
|
2023
|
-
{ name: 'name' },
|
|
2024
|
-
{ name: 'department', grouped: true },
|
|
2025
|
-
{ name: 'salary', aggregation: 'SUM' },
|
|
2026
|
-
],
|
|
2027
|
-
});
|
|
2028
|
-
|
|
2029
|
-
await flushPromises();
|
|
2030
|
-
instance.buildGroupedData();
|
|
2031
|
-
|
|
2032
|
-
let firstFooter = getNthFooter(instance, 0);
|
|
2033
|
-
let secondFooter = getNthFooter(instance, 1);
|
|
2034
|
-
let thirdFooter = getNthFooter(instance, 2);
|
|
2035
|
-
expect(firstFooter.salary).toBe(30);
|
|
2036
|
-
expect(secondFooter.salary).toBe(20);
|
|
2037
|
-
expect(thirdFooter.salary).toBe(50);
|
|
2038
|
-
|
|
2039
|
-
instance.editing = true;
|
|
2040
|
-
instance.updateCell('1', 'salary', 20);
|
|
2041
|
-
|
|
2042
|
-
instance.updateSummary();
|
|
2043
|
-
|
|
2044
|
-
firstFooter = getNthFooter(instance, 0);
|
|
2045
|
-
secondFooter = getNthFooter(instance, 1);
|
|
2046
|
-
thirdFooter = getNthFooter(instance, 2);
|
|
2047
|
-
expect(firstFooter.salary).toBe(40);
|
|
2048
|
-
expect(secondFooter.salary).toBe(20);
|
|
2049
|
-
expect(thirdFooter.salary).toBe(60);
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
it('should update aggregation data with many groups', async () => {
|
|
2053
|
-
const instance = await createGroupedGrid({
|
|
2054
|
-
columns: [
|
|
2055
|
-
{ name: 'id' },
|
|
2056
|
-
{ name: 'name' },
|
|
2057
|
-
{ name: 'month', grouped: true },
|
|
2058
|
-
{ name: 'department', grouped: true },
|
|
2059
|
-
{ name: 'salary', aggregation: 'SUM' },
|
|
2060
|
-
],
|
|
2061
|
-
});
|
|
2062
|
-
|
|
2063
|
-
await flushPromises();
|
|
2064
|
-
instance.buildGroupedData();
|
|
2065
|
-
|
|
2066
|
-
let firstFooter = getNthFooter(instance, 0);
|
|
2067
|
-
let secondFooter = getNthFooter(instance, 1);
|
|
2068
|
-
let thirdFooter = getNthFooter(instance, 2);
|
|
2069
|
-
let lastFooter = getLastFooter(instance);
|
|
2070
|
-
expect(firstFooter.salary).toBe(20);
|
|
2071
|
-
expect(secondFooter.salary).toBe(10);
|
|
2072
|
-
expect(thirdFooter.salary).toBe(30);
|
|
2073
|
-
expect(lastFooter.salary).toBe(50);
|
|
2074
|
-
|
|
2075
|
-
instance.editing = true;
|
|
2076
|
-
instance.updateCell('1', 'salary', 20);
|
|
2077
|
-
|
|
2078
|
-
instance.updateSummary();
|
|
2079
|
-
|
|
2080
|
-
firstFooter = getNthFooter(instance, 0);
|
|
2081
|
-
secondFooter = getNthFooter(instance, 1);
|
|
2082
|
-
thirdFooter = getNthFooter(instance, 2);
|
|
2083
|
-
lastFooter = getLastFooter(instance);
|
|
2084
|
-
expect(firstFooter.salary).toBe(30);
|
|
2085
|
-
expect(secondFooter.salary).toBe(10);
|
|
2086
|
-
expect(thirdFooter.salary).toBe(40);
|
|
2087
|
-
expect(lastFooter.salary).toBe(60);
|
|
2088
|
-
});
|
|
2089
|
-
});
|
|
2090
|
-
|
|
2091
|
-
describe('setSearch()', () => {
|
|
2092
|
-
let baseProps: ITekGrid;
|
|
2093
|
-
let httpSpy: jest.SpyInstance;
|
|
2094
|
-
|
|
2095
|
-
beforeEach(() => {
|
|
2096
|
-
httpSpy = jest.spyOn(Http, 'get').mockImplementation((url: string) => {
|
|
2097
|
-
if (url === '/zeedhi') {
|
|
2098
|
-
return Promise.resolve({
|
|
2099
|
-
data: {
|
|
2100
|
-
data: [
|
|
2101
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
2102
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
2103
|
-
{ id: 3, name: 'employee 3', department: 3 },
|
|
2104
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
2105
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
2106
|
-
{ id: 15, name: 'employee 15', department: 2 },
|
|
2107
|
-
],
|
|
2108
|
-
pagination: {
|
|
2109
|
-
page: 1,
|
|
2110
|
-
total: 5,
|
|
2111
|
-
limit: 15,
|
|
2112
|
-
},
|
|
2113
|
-
},
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
if (url === '/departments') {
|
|
2118
|
-
return Promise.resolve({
|
|
2119
|
-
data: {
|
|
2120
|
-
data: [
|
|
2121
|
-
{ id: 1, name: 'department 1' },
|
|
2122
|
-
{ id: 2, name: 'department 2' },
|
|
2123
|
-
{ id: 3, name: 'department 13' },
|
|
2124
|
-
],
|
|
2125
|
-
pagination: {
|
|
2126
|
-
page: 1,
|
|
2127
|
-
total: 3,
|
|
2128
|
-
limit: 15,
|
|
2129
|
-
},
|
|
2130
|
-
},
|
|
2131
|
-
});
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
if (url === '/grid') {
|
|
2135
|
-
return Promise.resolve({
|
|
2136
|
-
data: {
|
|
2137
|
-
data: [
|
|
2138
|
-
{ id: 1, employee_id: 1, department: 1 },
|
|
2139
|
-
{ id: 2, employee_id: 2, department: 1 },
|
|
2140
|
-
{ id: 3, employee_id: 3, department: 3 },
|
|
2141
|
-
],
|
|
2142
|
-
pagination: {
|
|
2143
|
-
page: 1,
|
|
2144
|
-
total: 5,
|
|
2145
|
-
limit: 15,
|
|
2146
|
-
},
|
|
2147
|
-
},
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
return Promise.reject();
|
|
2152
|
-
});
|
|
2153
|
-
|
|
2154
|
-
baseProps = {
|
|
2155
|
-
name: 'grid_search',
|
|
2156
|
-
component: 'TekGrid',
|
|
2157
|
-
columns: [
|
|
2158
|
-
{
|
|
2159
|
-
name: 'id',
|
|
2160
|
-
},
|
|
2161
|
-
{
|
|
2162
|
-
name: 'employee_id',
|
|
2163
|
-
componentProps: {
|
|
2164
|
-
name: 'ZdSelect',
|
|
2165
|
-
dataText: [
|
|
2166
|
-
'name',
|
|
2167
|
-
],
|
|
2168
|
-
datasource: {
|
|
2169
|
-
type: 'tek-rest',
|
|
2170
|
-
uniqueKey: 'id',
|
|
2171
|
-
route: '/zeedhi',
|
|
2172
|
-
lazyLoad: false,
|
|
2173
|
-
},
|
|
2174
|
-
},
|
|
2175
|
-
},
|
|
2176
|
-
],
|
|
2177
|
-
datasource: {
|
|
2178
|
-
type: 'tek-rest',
|
|
2179
|
-
lazyLoad: true,
|
|
2180
|
-
route: '/grid',
|
|
2181
|
-
},
|
|
2182
|
-
};
|
|
2183
|
-
});
|
|
2184
|
-
|
|
2185
|
-
afterEach(() => {
|
|
2186
|
-
httpSpy.mockReset();
|
|
2187
|
-
});
|
|
2188
|
-
|
|
2189
|
-
it('should set datasource search_join based on columns that have datasource', async () => {
|
|
2190
|
-
const instance = new TekGrid(baseProps);
|
|
2191
|
-
|
|
2192
|
-
instance.setSearch('1');
|
|
2193
|
-
await flushPromises();
|
|
2194
|
-
|
|
2195
|
-
expect(instance.datasource).toBeInstanceOf(TekRestDatasource);
|
|
2196
|
-
expect((instance.datasource as TekRestDatasource).searchJoin).toEqual({ employee_id: [1, 15] });
|
|
2197
|
-
expect(httpSpy).toHaveBeenCalledTimes(2);
|
|
2198
|
-
});
|
|
2199
|
-
|
|
2200
|
-
it('should set datasource search_join as empty when search is an empty string', async () => {
|
|
2201
|
-
const instance = new TekGrid(baseProps);
|
|
2202
|
-
|
|
2203
|
-
await instance.setSearch('');
|
|
2204
|
-
expect(instance.datasource).toBeInstanceOf(TekRestDatasource);
|
|
2205
|
-
expect((instance.datasource as TekRestDatasource).searchJoin).toEqual({});
|
|
2206
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
2207
|
-
});
|
|
2208
|
-
|
|
2209
|
-
it('should search in multiple columns', async () => {
|
|
2210
|
-
const instance = new TekGrid({
|
|
2211
|
-
name: 'grid_search',
|
|
2212
|
-
component: 'TekGrid',
|
|
2213
|
-
columns: [
|
|
2214
|
-
{
|
|
2215
|
-
name: 'id',
|
|
2216
|
-
},
|
|
2217
|
-
{
|
|
2218
|
-
name: 'employee_id',
|
|
2219
|
-
componentProps: {
|
|
2220
|
-
name: 'ZdSelect',
|
|
2221
|
-
dataText: ['name'],
|
|
2222
|
-
datasource: {
|
|
2223
|
-
type: 'tek-rest',
|
|
2224
|
-
uniqueKey: 'id',
|
|
2225
|
-
route: '/zeedhi',
|
|
2226
|
-
lazyLoad: false,
|
|
2227
|
-
},
|
|
2228
|
-
},
|
|
2229
|
-
},
|
|
2230
|
-
{
|
|
2231
|
-
name: 'department_id',
|
|
2232
|
-
componentProps: {
|
|
2233
|
-
name: 'ZdSelect',
|
|
2234
|
-
dataText: ['name'],
|
|
2235
|
-
datasource: {
|
|
2236
|
-
type: 'tek-rest',
|
|
2237
|
-
uniqueKey: 'id',
|
|
2238
|
-
route: '/departments',
|
|
2239
|
-
lazyLoad: false,
|
|
2240
|
-
},
|
|
2241
|
-
},
|
|
2242
|
-
},
|
|
2243
|
-
],
|
|
2244
|
-
datasource: {
|
|
2245
|
-
type: 'tek-rest',
|
|
2246
|
-
lazyLoad: true,
|
|
2247
|
-
route: '/grid',
|
|
2248
|
-
},
|
|
2249
|
-
});
|
|
2250
|
-
|
|
2251
|
-
await instance.setSearch('1');
|
|
2252
|
-
expect(instance.datasource).toBeInstanceOf(TekRestDatasource);
|
|
2253
|
-
expect((instance.datasource as TekRestDatasource).searchJoin).toEqual({ employee_id: [1, 15], department_id: [1, 3] });
|
|
2254
|
-
expect(httpSpy).toHaveBeenCalledTimes(3);
|
|
2255
|
-
});
|
|
2256
|
-
|
|
2257
|
-
it('should not make column search when datasource is not TekRestDatasource', async () => {
|
|
2258
|
-
baseProps.datasource!.type = 'rest';
|
|
2259
|
-
const instance = new TekGrid(baseProps);
|
|
2260
|
-
|
|
2261
|
-
await instance.setSearch('1');
|
|
2262
|
-
expect(instance.datasource).not.toBeInstanceOf(TekRestDatasource);
|
|
2263
|
-
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
2264
|
-
});
|
|
2265
|
-
|
|
2266
|
-
it('when called, should change datasource page to 1 before searching', async () => {
|
|
2267
|
-
const instance = new TekGrid({
|
|
2268
|
-
name: 'iterable',
|
|
2269
|
-
component: 'Iterable',
|
|
2270
|
-
});
|
|
2271
|
-
instance.datasource.page = 5;
|
|
2272
|
-
await instance.setSearch('search value');
|
|
2273
|
-
|
|
2274
|
-
expect(instance.datasource.page).toBe(1);
|
|
2275
|
-
});
|
|
2276
|
-
|
|
2277
|
-
it('deve retornar true se a coluna tiver filtro simples com dados (datasource comum)', () => {
|
|
2278
|
-
const column = { name: 'categoria' } as TekGridColumn;
|
|
2279
|
-
const grid = new TekGrid({ name: 'grid2', component: 'TekGrid' }) as any;
|
|
2280
|
-
|
|
2281
|
-
grid.datasource = {
|
|
2282
|
-
filter: {
|
|
2283
|
-
categoria: ['A'],
|
|
2284
|
-
},
|
|
2285
|
-
};
|
|
2286
|
-
|
|
2287
|
-
expect(grid.columnHasFilterData(column)).toBe(true);
|
|
2288
|
-
});
|
|
2289
|
-
});
|
|
2290
|
-
|
|
2291
|
-
describe('rowClick', () => {
|
|
2292
|
-
it('rowClick method should call events.rowClick', () => {
|
|
2293
|
-
const rowClick = jest.fn();
|
|
2294
|
-
|
|
2295
|
-
const data = [
|
|
2296
|
-
{ id: '1', name: 'First' },
|
|
2297
|
-
{ id: '2', name: 'Second' },
|
|
2298
|
-
{ id: '3', name: 'Third' },
|
|
2299
|
-
];
|
|
2300
|
-
const grid = new TekGrid({
|
|
2301
|
-
name: 'grid',
|
|
2302
|
-
component: 'TekGrid',
|
|
2303
|
-
columns: [
|
|
2304
|
-
{ name: 'id' },
|
|
2305
|
-
{ name: 'name' },
|
|
2306
|
-
],
|
|
2307
|
-
datasource: {
|
|
2308
|
-
data,
|
|
2309
|
-
},
|
|
2310
|
-
events: {
|
|
2311
|
-
rowClick,
|
|
2312
|
-
},
|
|
2313
|
-
});
|
|
2314
|
-
|
|
2315
|
-
const event = new Event('click');
|
|
2316
|
-
const element = document.createElement('div');
|
|
2317
|
-
grid.rowClick(data[0], event, element);
|
|
2318
|
-
|
|
2319
|
-
expect(rowClick).toHaveBeenCalledWith({
|
|
2320
|
-
event,
|
|
2321
|
-
element,
|
|
2322
|
-
row: data[0],
|
|
2323
|
-
component: grid,
|
|
2324
|
-
});
|
|
2325
|
-
expect(grid.datasource.currentRow).toEqual(data[0]);
|
|
2326
|
-
});
|
|
2327
|
-
|
|
2328
|
-
it('should not call events.rowClick if cellClick prevents it', async () => {
|
|
2329
|
-
const rowClick = jest.fn();
|
|
2330
|
-
|
|
2331
|
-
const data = [
|
|
2332
|
-
{ id: '1', name: 'First' },
|
|
2333
|
-
{ id: '2', name: 'Second' },
|
|
2334
|
-
{ id: '3', name: 'Third' },
|
|
2335
|
-
];
|
|
2336
|
-
const grid = new TekGrid({
|
|
2337
|
-
name: 'grid',
|
|
2338
|
-
component: 'TekGrid',
|
|
2339
|
-
columns: [
|
|
2340
|
-
{ name: 'id' },
|
|
2341
|
-
{ name: 'name' },
|
|
2342
|
-
],
|
|
2343
|
-
datasource: {
|
|
2344
|
-
data,
|
|
2345
|
-
},
|
|
2346
|
-
events: {
|
|
2347
|
-
rowClick,
|
|
2348
|
-
cellClick: () => true,
|
|
2349
|
-
},
|
|
2350
|
-
});
|
|
2351
|
-
await flushPromises();
|
|
2352
|
-
|
|
2353
|
-
const event = new Event('click');
|
|
2354
|
-
const element = document.createElement('div');
|
|
2355
|
-
grid.cellClick(data[0], grid.getColumn('id') as any, event, element);
|
|
2356
|
-
grid.rowClick(data[0], event, element);
|
|
2357
|
-
|
|
2358
|
-
expect(rowClick).not.toHaveBeenCalled();
|
|
2359
|
-
expect(grid.datasource.currentRow).toEqual({});
|
|
2360
|
-
});
|
|
2361
|
-
});
|
|
2362
|
-
|
|
2363
|
-
describe('rowDoubleClick', () => {
|
|
2364
|
-
it('rowDoubleClick method should call events.rowDoubleClick', () => {
|
|
2365
|
-
const rowDoubleClick = jest.fn();
|
|
2366
|
-
|
|
2367
|
-
const data = [
|
|
2368
|
-
{ id: '1', name: 'First' },
|
|
2369
|
-
{ id: '2', name: 'Second' },
|
|
2370
|
-
{ id: '3', name: 'Third' },
|
|
2371
|
-
];
|
|
2372
|
-
const grid = new TekGrid({
|
|
2373
|
-
name: 'grid',
|
|
2374
|
-
component: 'TekGrid',
|
|
2375
|
-
columns: [
|
|
2376
|
-
{ name: 'id' },
|
|
2377
|
-
{ name: 'name' },
|
|
2378
|
-
],
|
|
2379
|
-
datasource: {
|
|
2380
|
-
data,
|
|
2381
|
-
},
|
|
2382
|
-
events: {
|
|
2383
|
-
rowDoubleClick,
|
|
2384
|
-
},
|
|
2385
|
-
});
|
|
2386
|
-
|
|
2387
|
-
const event = new Event('dblclick');
|
|
2388
|
-
const element = document.createElement('div');
|
|
2389
|
-
grid.rowDoubleClick(data[0], event, element);
|
|
2390
|
-
|
|
2391
|
-
expect(rowDoubleClick).toHaveBeenCalledWith({
|
|
2392
|
-
event,
|
|
2393
|
-
element,
|
|
2394
|
-
row: data[0],
|
|
2395
|
-
component: grid,
|
|
2396
|
-
});
|
|
2397
|
-
expect(grid.datasource.currentRow).toEqual(data[0]);
|
|
2398
|
-
});
|
|
2399
|
-
|
|
2400
|
-
it('should not call events.rowDoubleClick if preventRowDoubleClick is true', () => {
|
|
2401
|
-
const rowDoubleClick = jest.fn();
|
|
2402
|
-
const cellDoubleClickHandler = jest.fn(() => true);
|
|
2403
|
-
|
|
2404
|
-
const data = [
|
|
2405
|
-
{ id: '1', name: 'First' },
|
|
2406
|
-
{ id: '2', name: 'Second' },
|
|
2407
|
-
{ id: '3', name: 'Third' },
|
|
2408
|
-
];
|
|
2409
|
-
const grid = new TekGrid({
|
|
2410
|
-
name: 'grid',
|
|
2411
|
-
component: 'TekGrid',
|
|
2412
|
-
columns: [
|
|
2413
|
-
{ name: 'id' },
|
|
2414
|
-
{ name: 'name' },
|
|
2415
|
-
],
|
|
2416
|
-
datasource: {
|
|
2417
|
-
data,
|
|
2418
|
-
},
|
|
2419
|
-
events: {
|
|
2420
|
-
rowDoubleClick,
|
|
2421
|
-
cellDoubleClick: cellDoubleClickHandler,
|
|
2422
|
-
},
|
|
2423
|
-
});
|
|
2424
|
-
|
|
2425
|
-
const event = new Event('dblclick');
|
|
2426
|
-
const element = document.createElement('div');
|
|
2427
|
-
|
|
2428
|
-
grid.cellDoubleClick(grid.groupedData[0], grid.getColumn('id') as any, event, element);
|
|
2429
|
-
grid.rowDoubleClick(data[0], event, element);
|
|
2430
|
-
|
|
2431
|
-
expect(rowDoubleClick).not.toHaveBeenCalled();
|
|
2432
|
-
expect(grid.datasource.currentRow).toEqual({});
|
|
2433
|
-
});
|
|
2434
|
-
});
|
|
2435
|
-
|
|
2436
|
-
describe('groupRowClick', () => {
|
|
2437
|
-
it('groupRowClick method should call events.groupRowClick', async () => {
|
|
2438
|
-
const groupRowClick = jest.fn();
|
|
2439
|
-
|
|
2440
|
-
const data = [
|
|
2441
|
-
{ id: '1', name: 'First', department: 1 },
|
|
2442
|
-
{ id: '2', name: 'Second', department: 1 },
|
|
2443
|
-
{ id: '3', name: 'Third', department: 1 },
|
|
2444
|
-
];
|
|
2445
|
-
const grid = new TekGrid({
|
|
2446
|
-
name: 'grid',
|
|
2447
|
-
component: 'TekGrid',
|
|
2448
|
-
columns: [
|
|
2449
|
-
{ name: 'id' },
|
|
2450
|
-
{ name: 'name' },
|
|
2451
|
-
{ name: 'department', grouped: true },
|
|
2452
|
-
],
|
|
2453
|
-
datasource: {
|
|
2454
|
-
data,
|
|
2455
|
-
},
|
|
2456
|
-
events: {
|
|
2457
|
-
groupRowClick,
|
|
2458
|
-
},
|
|
2459
|
-
});
|
|
2460
|
-
|
|
2461
|
-
await flushPromises();
|
|
2462
|
-
|
|
2463
|
-
const event = new Event('click');
|
|
2464
|
-
const element = document.createElement('div');
|
|
2465
|
-
grid.groupRowClick(grid.groupedData[0], event, element);
|
|
2466
|
-
|
|
2467
|
-
expect(groupRowClick).toHaveBeenCalledWith({
|
|
2468
|
-
event,
|
|
2469
|
-
element,
|
|
2470
|
-
row: grid.groupedData[0],
|
|
2471
|
-
component: grid,
|
|
2472
|
-
});
|
|
2473
|
-
});
|
|
2474
|
-
|
|
2475
|
-
it('should not call events.groupRowClick if cellClick prevents it', async () => {
|
|
2476
|
-
const groupRowClick = jest.fn();
|
|
2477
|
-
|
|
2478
|
-
const data = [
|
|
2479
|
-
{ id: '1', name: 'First', department: 1 },
|
|
2480
|
-
{ id: '2', name: 'Second', department: 1 },
|
|
2481
|
-
{ id: '3', name: 'Third', department: 1 },
|
|
2482
|
-
];
|
|
2483
|
-
const grid = new TekGrid({
|
|
2484
|
-
name: 'grid',
|
|
2485
|
-
component: 'TekGrid',
|
|
2486
|
-
columns: [
|
|
2487
|
-
{ name: 'id' },
|
|
2488
|
-
{ name: 'name' },
|
|
2489
|
-
{ name: 'department', grouped: true },
|
|
2490
|
-
],
|
|
2491
|
-
datasource: {
|
|
2492
|
-
data,
|
|
2493
|
-
},
|
|
2494
|
-
events: {
|
|
2495
|
-
groupRowClick,
|
|
2496
|
-
cellClick: () => true,
|
|
2497
|
-
},
|
|
2498
|
-
});
|
|
2499
|
-
await flushPromises();
|
|
2500
|
-
|
|
2501
|
-
const event = new Event('click');
|
|
2502
|
-
const element = document.createElement('div');
|
|
2503
|
-
grid.cellClick(grid.groupedData[0], grid.getColumn('id') as any, event, element);
|
|
2504
|
-
grid.groupRowClick(grid.groupedData[0], event, element);
|
|
2505
|
-
|
|
2506
|
-
expect(groupRowClick).not.toHaveBeenCalled();
|
|
2507
|
-
});
|
|
2508
|
-
});
|
|
2509
|
-
|
|
2510
|
-
describe('groupRowDoubleClick', () => {
|
|
2511
|
-
it('groupRowDoubleClick method should call events.groupRowDoubleClick', async () => {
|
|
2512
|
-
const groupRowDoubleClick = jest.fn();
|
|
2513
|
-
|
|
2514
|
-
const data = [
|
|
2515
|
-
{ id: '1', name: 'First', department: 1 },
|
|
2516
|
-
{ id: '2', name: 'Second', department: 1 },
|
|
2517
|
-
{ id: '3', name: 'Third', department: 1 },
|
|
2518
|
-
];
|
|
2519
|
-
const grid = new TekGrid({
|
|
2520
|
-
name: 'grid',
|
|
2521
|
-
component: 'TekGrid',
|
|
2522
|
-
columns: [
|
|
2523
|
-
{ name: 'id' },
|
|
2524
|
-
{ name: 'name' },
|
|
2525
|
-
{ name: 'department', grouped: true },
|
|
2526
|
-
],
|
|
2527
|
-
datasource: {
|
|
2528
|
-
data,
|
|
2529
|
-
},
|
|
2530
|
-
events: {
|
|
2531
|
-
groupRowDoubleClick,
|
|
2532
|
-
},
|
|
2533
|
-
});
|
|
2534
|
-
|
|
2535
|
-
await flushPromises();
|
|
2536
|
-
|
|
2537
|
-
const event = new Event('dblclick');
|
|
2538
|
-
const element = document.createElement('div');
|
|
2539
|
-
grid.groupRowDoubleClick(grid.groupedData[0], event, element);
|
|
2540
|
-
|
|
2541
|
-
expect(groupRowDoubleClick).toHaveBeenCalledWith({
|
|
2542
|
-
event,
|
|
2543
|
-
element,
|
|
2544
|
-
row: grid.groupedData[0],
|
|
2545
|
-
component: grid,
|
|
2546
|
-
});
|
|
2547
|
-
});
|
|
2548
|
-
|
|
2549
|
-
it('should not call events.groupRowDoubleClick if cellDoubleClick prevents it', async () => {
|
|
2550
|
-
const groupRowDoubleClick = jest.fn();
|
|
2551
|
-
const cellDoubleClickHandler = jest.fn(() => true);
|
|
2552
|
-
|
|
2553
|
-
const data = [
|
|
2554
|
-
{ id: '1', name: 'First', department: 1 },
|
|
2555
|
-
{ id: '2', name: 'Second', department: 1 },
|
|
2556
|
-
{ id: '3', name: 'Third', department: 1 },
|
|
2557
|
-
];
|
|
2558
|
-
const grid = new TekGrid({
|
|
2559
|
-
name: 'grid',
|
|
2560
|
-
component: 'TekGrid',
|
|
2561
|
-
columns: [
|
|
2562
|
-
{ name: 'id' },
|
|
2563
|
-
{ name: 'name' },
|
|
2564
|
-
{ name: 'department', grouped: true },
|
|
2565
|
-
],
|
|
2566
|
-
datasource: {
|
|
2567
|
-
data,
|
|
2568
|
-
},
|
|
2569
|
-
events: {
|
|
2570
|
-
groupRowDoubleClick,
|
|
2571
|
-
cellDoubleClick: cellDoubleClickHandler,
|
|
2572
|
-
},
|
|
2573
|
-
});
|
|
2574
|
-
|
|
2575
|
-
await flushPromises();
|
|
2576
|
-
|
|
2577
|
-
const event = new Event('dblclick');
|
|
2578
|
-
const element = document.createElement('div');
|
|
2579
|
-
|
|
2580
|
-
grid.cellDoubleClick(grid.groupedData[0], grid.getColumn('id') as any, event, element);
|
|
2581
|
-
grid.groupRowDoubleClick(grid.groupedData[0], event, element);
|
|
2582
|
-
|
|
2583
|
-
expect(groupRowDoubleClick).not.toHaveBeenCalled();
|
|
2584
|
-
});
|
|
2585
|
-
});
|
|
2586
|
-
|
|
2587
|
-
describe('selectGroupClick', () => {
|
|
2588
|
-
it('should trigger events', async () => {
|
|
2589
|
-
const groupSelected = jest.fn();
|
|
2590
|
-
const groupUnselected = jest.fn();
|
|
2591
|
-
|
|
2592
|
-
const data = [
|
|
2593
|
-
{ id: '1', name: 'First', department: 1 },
|
|
2594
|
-
{ id: '2', name: 'Second', department: 1 },
|
|
2595
|
-
{ id: '3', name: 'Third', department: 1 },
|
|
2596
|
-
];
|
|
2597
|
-
const grid = new TekGrid({
|
|
2598
|
-
name: 'grid',
|
|
2599
|
-
component: 'TekGrid',
|
|
2600
|
-
columns: [
|
|
2601
|
-
{ name: 'id' },
|
|
2602
|
-
{ name: 'name' },
|
|
2603
|
-
{ name: 'department', grouped: true },
|
|
2604
|
-
],
|
|
2605
|
-
datasource: {
|
|
2606
|
-
data,
|
|
2607
|
-
},
|
|
2608
|
-
events: {
|
|
2609
|
-
groupSelected,
|
|
2610
|
-
groupUnselected,
|
|
2611
|
-
},
|
|
2612
|
-
});
|
|
2613
|
-
|
|
2614
|
-
await flushPromises();
|
|
2615
|
-
|
|
2616
|
-
const event = new Event('click');
|
|
2617
|
-
const element = document.createElement('div');
|
|
2618
|
-
|
|
2619
|
-
grid.selectGroupClick(grid.groupedData[0], true, event, element);
|
|
2620
|
-
expect(groupSelected).toHaveBeenCalled();
|
|
2621
|
-
|
|
2622
|
-
grid.selectGroupClick(grid.groupedData[0], false, event, element);
|
|
2623
|
-
expect(groupUnselected).toHaveBeenCalled();
|
|
2624
|
-
});
|
|
2625
|
-
});
|
|
2626
|
-
|
|
2627
|
-
describe('layoutOptions', () => {
|
|
2628
|
-
it('should return layout options instance', async () => {
|
|
2629
|
-
const grid = new TekGrid({
|
|
2630
|
-
name: 'grid',
|
|
2631
|
-
component: 'TekGrid',
|
|
2632
|
-
showLayoutOptions: false,
|
|
2633
|
-
});
|
|
2634
|
-
|
|
2635
|
-
expect(grid.layoutOptions).toBeUndefined();
|
|
2636
|
-
|
|
2637
|
-
grid.showLayoutOptions = true;
|
|
2638
|
-
const layoutOptionsComp = { name: 'grid_layout_options' };
|
|
2639
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => layoutOptionsComp);
|
|
2640
|
-
expect(grid.layoutOptions).toEqual(layoutOptionsComp);
|
|
2641
|
-
spyMetadata.mockReset();
|
|
2642
|
-
});
|
|
2643
|
-
});
|
|
2644
|
-
|
|
2645
|
-
describe('getAtomInstance', () => {
|
|
2646
|
-
const createAtom = (name: string) => new Text({
|
|
2647
|
-
name: `${name}_gridTitle`,
|
|
2648
|
-
component: 'ZdText',
|
|
2649
|
-
text: 'Employees',
|
|
2650
|
-
});
|
|
2651
|
-
|
|
2652
|
-
it('when called, should return the instance of an atom component', () => {
|
|
2653
|
-
const instance = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
2654
|
-
const atom = createAtom(instance.name);
|
|
2655
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => atom);
|
|
2656
|
-
|
|
2657
|
-
const gridAtom = instance.getAtomInstance<Text>('TITLE');
|
|
2658
|
-
|
|
2659
|
-
expect(gridAtom).toEqual(atom);
|
|
2660
|
-
spyMetadata.mockReset();
|
|
2661
|
-
});
|
|
2662
|
-
});
|
|
2663
|
-
|
|
2664
|
-
describe('getFilterInputs', () => {
|
|
2665
|
-
const mockMetadata = (instance: TekGrid) => {
|
|
2666
|
-
const inputs: IDictionary = {};
|
|
2667
|
-
instance.columns.forEach((col) => {
|
|
2668
|
-
if (!col.filterable || !col.filterProps) return;
|
|
2669
|
-
|
|
2670
|
-
col.filterProps.forEach((filter: any, index: number) => {
|
|
2671
|
-
const relation = filter.relation || 'AND';
|
|
2672
|
-
const operation = filter.operation || 'CONTAINS';
|
|
2673
|
-
|
|
2674
|
-
const name = `${instance.name}-filter-${relation}-${operation}-${col.name}-${index}`;
|
|
2675
|
-
inputs[name] = new TextInput({
|
|
2676
|
-
name,
|
|
2677
|
-
...filter.filterProps,
|
|
2678
|
-
});
|
|
2679
|
-
});
|
|
2680
|
-
});
|
|
2681
|
-
return jest.spyOn(Metadata, 'getInstance').mockImplementation((name: string) => inputs[name]);
|
|
2682
|
-
};
|
|
2683
|
-
|
|
2684
|
-
it('when called with null parameter, should return all the filter inputs', () => {
|
|
2685
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => (new Modal(modal)));
|
|
2686
|
-
const instance = new TekGrid({
|
|
2687
|
-
name: 'grid',
|
|
2688
|
-
component: 'TekGrid',
|
|
2689
|
-
datasource: {
|
|
2690
|
-
type: 'tek-rest',
|
|
2691
|
-
uniqueKey: 'id',
|
|
2692
|
-
route: '/zeedhi',
|
|
2693
|
-
lazyLoad: false,
|
|
2694
|
-
},
|
|
2695
|
-
columns: [
|
|
2696
|
-
{ name: 'id' },
|
|
2697
|
-
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
2698
|
-
{
|
|
2699
|
-
name: 'salary',
|
|
2700
|
-
filterable: true,
|
|
2701
|
-
filterProps: [
|
|
2702
|
-
{
|
|
2703
|
-
name: 'salary_edit',
|
|
2704
|
-
component: 'ZdCurrency',
|
|
2705
|
-
operation: 'GREATER_THAN_EQUALS',
|
|
2706
|
-
label: 'Salary (min)',
|
|
2707
|
-
},
|
|
2708
|
-
{
|
|
2709
|
-
name: 'salary_edit',
|
|
2710
|
-
component: 'ZdCurrency',
|
|
2711
|
-
operation: 'LESS_THAN_EQUALS',
|
|
2712
|
-
label: 'Salary (max)',
|
|
2713
|
-
},
|
|
2714
|
-
],
|
|
2715
|
-
},
|
|
2716
|
-
],
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2719
|
-
const spy = mockMetadata(instance);
|
|
2720
|
-
instance.onCreated();
|
|
2721
|
-
|
|
2722
|
-
const filterButton = clickOnFilterButton(instance);
|
|
2723
|
-
filterButton.onCreated();
|
|
2724
|
-
|
|
2725
|
-
const inputs = instance.getFilterInputs();
|
|
2726
|
-
expect(inputs[0].name).toBe('grid-filter-AND-CONTAINS-name-0');
|
|
2727
|
-
expect(inputs[1].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
|
|
2728
|
-
expect(inputs[2].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
|
|
2729
|
-
spy.mockReset();
|
|
2730
|
-
spyModalService.mockReset();
|
|
2731
|
-
});
|
|
2732
|
-
|
|
2733
|
-
it('when called, should return the instances of filters with multiple inputs', () => {
|
|
2734
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => (new Modal(modal)));
|
|
2735
|
-
const instance = new TekGrid({
|
|
2736
|
-
name: 'grid',
|
|
2737
|
-
component: 'TekGrid',
|
|
2738
|
-
datasource: {
|
|
2739
|
-
type: 'tek-rest',
|
|
2740
|
-
uniqueKey: 'id',
|
|
2741
|
-
route: '/zeedhi',
|
|
2742
|
-
lazyLoad: false,
|
|
2743
|
-
},
|
|
2744
|
-
columns: [
|
|
2745
|
-
{ name: 'id' },
|
|
2746
|
-
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
2747
|
-
{
|
|
2748
|
-
name: 'salary',
|
|
2749
|
-
filterable: true,
|
|
2750
|
-
filterProps: [
|
|
2751
|
-
{
|
|
2752
|
-
name: 'salary_edit',
|
|
2753
|
-
component: 'ZdCurrency',
|
|
2754
|
-
operation: 'GREATER_THAN_EQUALS',
|
|
2755
|
-
label: 'Salary (min)',
|
|
2756
|
-
},
|
|
2757
|
-
{
|
|
2758
|
-
name: 'salary_edit',
|
|
2759
|
-
component: 'ZdCurrency',
|
|
2760
|
-
operation: 'LESS_THAN_EQUALS',
|
|
2761
|
-
label: 'Salary (max)',
|
|
2762
|
-
},
|
|
2763
|
-
],
|
|
2764
|
-
},
|
|
2765
|
-
],
|
|
2766
|
-
});
|
|
2767
|
-
|
|
2768
|
-
const spy = mockMetadata(instance);
|
|
2769
|
-
instance.onCreated();
|
|
2770
|
-
|
|
2771
|
-
const filterButton = clickOnFilterButton(instance);
|
|
2772
|
-
filterButton.onCreated();
|
|
2773
|
-
|
|
2774
|
-
const inputs = instance.getFilterInputs('salary');
|
|
2775
|
-
expect(inputs[0].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
|
|
2776
|
-
expect(inputs[1].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
|
|
2777
|
-
spy.mockReset();
|
|
2778
|
-
spyModalService.mockReset();
|
|
2779
|
-
});
|
|
2780
|
-
});
|
|
2781
|
-
|
|
2782
|
-
describe('loadAfterTasks', () => {
|
|
2783
|
-
it('should call request even if tasks fail', async () => {
|
|
2784
|
-
const instance = new TekGrid({
|
|
2785
|
-
name: 'grid',
|
|
2786
|
-
component: 'TekGrid',
|
|
2787
|
-
});
|
|
2788
|
-
const spy = jest.spyOn(instance.datasource, 'get');
|
|
2789
|
-
|
|
2790
|
-
const errorFn = async () => {
|
|
2791
|
-
throw new Error();
|
|
2792
|
-
};
|
|
2793
|
-
instance.registerTask(errorFn());
|
|
2794
|
-
|
|
2795
|
-
await instance.loadAfterTasks();
|
|
2796
|
-
|
|
2797
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
2798
|
-
});
|
|
2799
|
-
});
|
|
2800
|
-
|
|
2801
|
-
describe('isColumnSearchable()', () => {
|
|
2802
|
-
let instance!: TekGrid;
|
|
2803
|
-
|
|
2804
|
-
beforeEach(() => {
|
|
2805
|
-
instance = new TekGrid({
|
|
2806
|
-
name: 'TekGrid',
|
|
2807
|
-
component: 'TekGrid',
|
|
2808
|
-
columns: [{ name: 'name' }],
|
|
2809
|
-
});
|
|
2810
|
-
});
|
|
2811
|
-
|
|
2812
|
-
it('should return true if column is visible', () => {
|
|
2813
|
-
const column = instance.getColumn('name') as TekGridColumn;
|
|
2814
|
-
column.isVisible = true;
|
|
2815
|
-
|
|
2816
|
-
expect(instance.isColumnSearchable(column)).toBeTruthy();
|
|
2817
|
-
});
|
|
2818
|
-
|
|
2819
|
-
it('should return true if column is grouped', () => {
|
|
2820
|
-
const column = instance.getColumn('name') as TekGridColumn;
|
|
2821
|
-
column.isVisible = false;
|
|
2822
|
-
column.grouped = true;
|
|
2823
|
-
|
|
2824
|
-
expect(instance.isColumnSearchable(column)).toBeTruthy();
|
|
2825
|
-
});
|
|
2826
|
-
|
|
2827
|
-
it('should return false if column is not visible', () => {
|
|
2828
|
-
const column = instance.getColumn('name') as TekGridColumn;
|
|
2829
|
-
column.isVisible = false;
|
|
2830
|
-
|
|
2831
|
-
expect(instance.isColumnSearchable(column)).toBeFalsy();
|
|
2832
|
-
});
|
|
2833
|
-
|
|
2834
|
-
it('should return true if iterable uses searchVisibleOnly as false', () => {
|
|
2835
|
-
instance.searchVisibleOnly = false;
|
|
2836
|
-
|
|
2837
|
-
const column = instance.getColumn('name') as TekGridColumn;
|
|
2838
|
-
expect(instance.isColumnSearchable(column)).toBeTruthy();
|
|
2839
|
-
column.isVisible = false;
|
|
2840
|
-
expect(instance.isColumnSearchable(column)).toBeTruthy();
|
|
2841
|
-
});
|
|
2842
|
-
});
|
|
2843
|
-
|
|
2844
|
-
describe('cancel column', () => {
|
|
2845
|
-
it('should instantiate grid with a cancel column', () => {
|
|
2846
|
-
const grid = new TekGrid({
|
|
2847
|
-
name: 'grid',
|
|
2848
|
-
component: 'TekGrid',
|
|
2849
|
-
showCancelColumn: true,
|
|
2850
|
-
columns: [
|
|
2851
|
-
{ name: 'name' },
|
|
2852
|
-
],
|
|
2853
|
-
datasource: { data: [{ id: '1' }], uniqueKey: 'id' },
|
|
2854
|
-
});
|
|
2855
|
-
const spy = jest.fn();
|
|
2856
|
-
grid.cancelAddedRow = spy;
|
|
2857
|
-
|
|
2858
|
-
expect(grid.columns.length).toBe(2);
|
|
2859
|
-
expect(grid.columns[1].name).toBe('cancel_action_grid');
|
|
2860
|
-
|
|
2861
|
-
const comp: any = grid.getActionComponent(
|
|
2862
|
-
grid.columns[1].children[0],
|
|
2863
|
-
grid.columns[1],
|
|
2864
|
-
grid.datasource.data[0],
|
|
2865
|
-
);
|
|
2866
|
-
const btn = new Button(comp);
|
|
2867
|
-
btn.click();
|
|
2868
|
-
|
|
2869
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
2870
|
-
});
|
|
2871
|
-
});
|
|
2872
|
-
|
|
2873
|
-
describe('addNewRow', () => {
|
|
2874
|
-
it('when not using groups, should add a new row to the datasource', async () => {
|
|
2875
|
-
const instance = new TekGrid({
|
|
2876
|
-
name: 'Grid',
|
|
2877
|
-
component: 'TekGrid',
|
|
2878
|
-
datasource: {
|
|
2879
|
-
page: 1,
|
|
2880
|
-
data: [
|
|
2881
|
-
{ id: 1 },
|
|
2882
|
-
],
|
|
2883
|
-
},
|
|
2884
|
-
});
|
|
2885
|
-
await instance.datasource.get();
|
|
2886
|
-
const newRow1 = { id: 2 };
|
|
2887
|
-
await instance.addNewRow(newRow1, 'start');
|
|
2888
|
-
expect(instance.datasource.data[0]).toMatchObject({ id: 2, __added_row: true });
|
|
2889
|
-
expect(instance.datasource.data[1]).toMatchObject({ id: 1 });
|
|
2890
|
-
});
|
|
2891
|
-
|
|
2892
|
-
it('should add a new row to the groupedData array', async () => {
|
|
2893
|
-
const grid = await createGroupedGrid();
|
|
2894
|
-
|
|
2895
|
-
expect(grid.groupedData).toMatchObject([
|
|
2896
|
-
{ groupValue: 1 },
|
|
2897
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2898
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2899
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2900
|
-
{ groupValue: 2 },
|
|
2901
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2902
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2903
|
-
]);
|
|
2904
|
-
expect(grid.groupedData[0].children).toMatchObject([
|
|
2905
|
-
{ id: '1' },
|
|
2906
|
-
{ id: '2' },
|
|
2907
|
-
{ id: '4' },
|
|
2908
|
-
]);
|
|
2909
|
-
|
|
2910
|
-
await grid.addNewRow({ id: '999', name: 'new', department: 1 });
|
|
2911
|
-
|
|
2912
|
-
expect(grid.groupedData).toMatchObject([
|
|
2913
|
-
{ groupValue: 1 },
|
|
2914
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2915
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2916
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2917
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
2918
|
-
{ groupValue: 2 },
|
|
2919
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2920
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2921
|
-
]);
|
|
2922
|
-
expect(grid.groupedData[0].children).toMatchObject([
|
|
2923
|
-
{ id: '1' },
|
|
2924
|
-
{ id: '2' },
|
|
2925
|
-
{ id: '4' },
|
|
2926
|
-
{ id: '999' },
|
|
2927
|
-
]);
|
|
2928
|
-
});
|
|
2929
|
-
|
|
2930
|
-
it('should add a new row to the groupedData array using nested groups', async () => {
|
|
2931
|
-
const grid = await createGroupedGrid({
|
|
2932
|
-
columns: [
|
|
2933
|
-
{ name: 'id' },
|
|
2934
|
-
{ name: 'name' },
|
|
2935
|
-
{ name: 'month', grouped: true },
|
|
2936
|
-
{ name: 'department', grouped: true },
|
|
2937
|
-
],
|
|
2938
|
-
});
|
|
2939
|
-
|
|
2940
|
-
expect(grid.groupedData).toMatchObject([
|
|
2941
|
-
{ groupValue: 11 },
|
|
2942
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
2943
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2944
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2945
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
2946
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
2947
|
-
{ groupValue: 12 },
|
|
2948
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
2949
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2950
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
2951
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
2952
|
-
]);
|
|
2953
|
-
|
|
2954
|
-
await grid.addNewRow({
|
|
2955
|
-
id: '999', name: 'new', month: 12, department: 1,
|
|
2956
|
-
}, 'start');
|
|
2957
|
-
|
|
2958
|
-
expect(grid.groupedData).toMatchObject([
|
|
2959
|
-
{ groupValue: 11 },
|
|
2960
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
2961
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2962
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2963
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
2964
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
2965
|
-
{ groupValue: 12 },
|
|
2966
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
2967
|
-
{ id: '999', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2968
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2969
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
2970
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
2971
|
-
]);
|
|
2972
|
-
|
|
2973
|
-
expect(grid.groupedData[6].children).toMatchObject([
|
|
2974
|
-
{ id: '999' },
|
|
2975
|
-
{ id: '4' },
|
|
2976
|
-
{ id: '5' },
|
|
2977
|
-
]);
|
|
2978
|
-
expect(grid.groupedData[7].children).toMatchObject([
|
|
2979
|
-
{ id: '999' },
|
|
2980
|
-
{ id: '4' },
|
|
2981
|
-
]);
|
|
2982
|
-
});
|
|
2983
|
-
|
|
2984
|
-
it('should add a new row to a group that doesnt exist', async () => {
|
|
2985
|
-
const grid = await createGroupedGrid();
|
|
2986
|
-
|
|
2987
|
-
await grid.addNewRow({ id: '999', name: 'new', department: 999 }, 'end');
|
|
2988
|
-
|
|
2989
|
-
expect(grid.groupedData).toMatchObject([
|
|
2990
|
-
{ groupValue: 1 },
|
|
2991
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2992
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2993
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2994
|
-
{ groupValue: 2 },
|
|
2995
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2996
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2997
|
-
{ groupValue: 999 },
|
|
2998
|
-
{ id: '999', groupHeaders: [{ groupValue: 999 }] },
|
|
2999
|
-
]);
|
|
3000
|
-
});
|
|
3001
|
-
|
|
3002
|
-
it('should add a new row to a group that doesnt exist using nested groups', async () => {
|
|
3003
|
-
const grid = await createGroupedGrid({
|
|
3004
|
-
columns: [
|
|
3005
|
-
{ name: 'id' },
|
|
3006
|
-
{ name: 'name' },
|
|
3007
|
-
{ name: 'month', grouped: true },
|
|
3008
|
-
{ name: 'department', grouped: true },
|
|
3009
|
-
],
|
|
3010
|
-
});
|
|
3011
|
-
|
|
3012
|
-
await grid.addNewRow({
|
|
3013
|
-
id: '999', name: 'new', month: 999, department: 1,
|
|
3014
|
-
}, 'end');
|
|
3015
|
-
|
|
3016
|
-
expect(grid.groupedData).toMatchObject([
|
|
3017
|
-
{ groupValue: 11 },
|
|
3018
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3019
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3020
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3021
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3022
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3023
|
-
{ groupValue: 12 },
|
|
3024
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3025
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3026
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3027
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3028
|
-
// new group
|
|
3029
|
-
{ groupValue: 999 },
|
|
3030
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 999 }] },
|
|
3031
|
-
{ id: '999', groupHeaders: [{ groupValue: 999 }, { groupValue: 1 }] },
|
|
3032
|
-
]);
|
|
3033
|
-
});
|
|
3034
|
-
|
|
3035
|
-
it('should add a new row to a group that doesnt inside a group that exists', async () => {
|
|
3036
|
-
const grid = await createGroupedGrid({
|
|
3037
|
-
columns: [
|
|
3038
|
-
{ name: 'id' },
|
|
3039
|
-
{ name: 'name' },
|
|
3040
|
-
{ name: 'month', grouped: true },
|
|
3041
|
-
{ name: 'department', grouped: true },
|
|
3042
|
-
],
|
|
3043
|
-
});
|
|
3044
|
-
|
|
3045
|
-
await grid.addNewRow({
|
|
3046
|
-
id: '999', name: 'new', month: 11, department: 999,
|
|
3047
|
-
}, 'end');
|
|
3048
|
-
|
|
3049
|
-
expect(grid.groupedData).toMatchObject([
|
|
3050
|
-
{ groupValue: 11 },
|
|
3051
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 11 }] },
|
|
3052
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 999 }] },
|
|
3053
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3054
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3055
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3056
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3057
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3058
|
-
{ groupValue: 12 },
|
|
3059
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3060
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3061
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3062
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3063
|
-
]);
|
|
3064
|
-
});
|
|
3065
|
-
|
|
3066
|
-
it('should add a new row inside nested groups that doesnt exist', async () => {
|
|
3067
|
-
const grid = await createGroupedGrid({
|
|
3068
|
-
columns: [
|
|
3069
|
-
{ name: 'id' },
|
|
3070
|
-
{ name: 'name' },
|
|
3071
|
-
{ name: 'year', grouped: true },
|
|
3072
|
-
{ name: 'month', grouped: true },
|
|
3073
|
-
{ name: 'department', grouped: true },
|
|
3074
|
-
],
|
|
3075
|
-
datasource: {
|
|
3076
|
-
uniqueKey: 'id',
|
|
3077
|
-
data: [
|
|
3078
|
-
{
|
|
3079
|
-
id: '1', name: 'First', year: 2000, month: 11, department: 1,
|
|
3080
|
-
},
|
|
3081
|
-
{
|
|
3082
|
-
id: '2', name: 'Second', year: 2000, month: 11, department: 1,
|
|
3083
|
-
},
|
|
3084
|
-
{
|
|
3085
|
-
id: '3', name: 'Third', year: 2000, month: 11, department: 2,
|
|
3086
|
-
},
|
|
3087
|
-
{
|
|
3088
|
-
id: '4', name: 'Fourth', year: 2010, month: 11, department: 1,
|
|
3089
|
-
},
|
|
3090
|
-
{
|
|
3091
|
-
id: '5', name: 'Fifth', year: 2010, month: 12, department: 2,
|
|
3092
|
-
},
|
|
3093
|
-
],
|
|
3094
|
-
},
|
|
3095
|
-
});
|
|
3096
|
-
|
|
3097
|
-
await grid.addNewRow({
|
|
3098
|
-
id: '999', name: 'new', year: 2010, month: 999, department: 999,
|
|
3099
|
-
}, 'end');
|
|
3100
|
-
await grid.addNewRow({
|
|
3101
|
-
id: '998', name: 'new', year: 2010, month: 999, department: 999,
|
|
3102
|
-
}, 'end');
|
|
3103
|
-
|
|
3104
|
-
expect(grid.groupedData).toMatchObject([
|
|
3105
|
-
{ groupValue: 2000 },
|
|
3106
|
-
{ groupValue: 11, groupHeaders: [{ groupValue: 2000 }] },
|
|
3107
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }] },
|
|
3108
|
-
{ id: '1', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3109
|
-
{ id: '2', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3110
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }] },
|
|
3111
|
-
{ id: '3', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 2 }] },
|
|
3112
|
-
{ groupValue: 2010 },
|
|
3113
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 2010 }] },
|
|
3114
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }] },
|
|
3115
|
-
{ id: '999', groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }, { groupValue: 999 }] },
|
|
3116
|
-
{ id: '998', groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }, { groupValue: 999 }] },
|
|
3117
|
-
{ groupValue: 11, groupHeaders: [{ groupValue: 2010 }] },
|
|
3118
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 2010 }, { groupValue: 11 }] },
|
|
3119
|
-
{ id: '4', groupHeaders: [{ groupValue: 2010 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3120
|
-
{ groupValue: 12, groupHeaders: [{ groupValue: 2010 }] },
|
|
3121
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 2010 }, { groupValue: 12 }] },
|
|
3122
|
-
{ id: '5', groupHeaders: [{ groupValue: 2010 }, { groupValue: 12 }, { groupValue: 2 }] },
|
|
3123
|
-
]);
|
|
3124
|
-
});
|
|
3125
|
-
|
|
3126
|
-
it('should throw an error when row groups are not defined or incomplete', async () => {
|
|
3127
|
-
const grid = await createGroupedGrid({
|
|
3128
|
-
columns: [
|
|
3129
|
-
{ name: 'id' },
|
|
3130
|
-
{ name: 'name' },
|
|
3131
|
-
{ name: 'month', grouped: true },
|
|
3132
|
-
{ name: 'department', grouped: true },
|
|
3133
|
-
],
|
|
3134
|
-
});
|
|
3135
|
-
|
|
3136
|
-
// month group is undefined, should throw
|
|
3137
|
-
expect(async () => grid.addNewRow({ id: '999', name: 'new', department: 1 }, 'end')).rejects.toThrow();
|
|
3138
|
-
});
|
|
3139
|
-
});
|
|
3140
|
-
|
|
3141
|
-
describe('addToSelection', () => {
|
|
3142
|
-
it('should add a row to the selected group', async () => {
|
|
3143
|
-
const grid = await createGroupedGrid();
|
|
3144
|
-
|
|
3145
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3146
|
-
|
|
3147
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3148
|
-
|
|
3149
|
-
expect(grid.groupedData).toMatchObject([
|
|
3150
|
-
{ groupValue: 1 },
|
|
3151
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
3152
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
3153
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
3154
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
3155
|
-
{ groupValue: 2 },
|
|
3156
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
3157
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
3158
|
-
]);
|
|
3159
|
-
});
|
|
3160
|
-
|
|
3161
|
-
it('should add a row to the selected group when using nested groups', async () => {
|
|
3162
|
-
const grid = await createGroupedGrid();
|
|
3163
|
-
|
|
3164
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3165
|
-
|
|
3166
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3167
|
-
|
|
3168
|
-
expect(grid.groupedData).toMatchObject([
|
|
3169
|
-
{ groupValue: 1 },
|
|
3170
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
3171
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
3172
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
3173
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
3174
|
-
{ groupValue: 2 },
|
|
3175
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
3176
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
3177
|
-
]);
|
|
3178
|
-
});
|
|
3179
|
-
|
|
3180
|
-
it('when selected row is not a group, should add a row to the same group as the selected row', async () => {
|
|
3181
|
-
const grid = await createGroupedGrid({
|
|
3182
|
-
columns: [
|
|
3183
|
-
{ name: 'id' },
|
|
3184
|
-
{ name: 'name' },
|
|
3185
|
-
{ name: 'month', grouped: true },
|
|
3186
|
-
{ name: 'department', grouped: true },
|
|
3187
|
-
],
|
|
3188
|
-
});
|
|
3189
|
-
|
|
3190
|
-
grid.datasource.currentRow = grid.groupedData.find((row) => row.id === '3')!;
|
|
3191
|
-
|
|
3192
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3193
|
-
|
|
3194
|
-
expect(grid.groupedData).toMatchObject([
|
|
3195
|
-
{ groupValue: 11 },
|
|
3196
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3197
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3198
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3199
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3200
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3201
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3202
|
-
{ groupValue: 12 },
|
|
3203
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3204
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3205
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3206
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3207
|
-
]);
|
|
3208
|
-
});
|
|
3209
|
-
|
|
3210
|
-
it('when selected row is not the most internal group, should add a row to the first most internal group', async () => {
|
|
3211
|
-
const grid = await createGroupedGrid({
|
|
3212
|
-
columns: [
|
|
3213
|
-
{ name: 'id' },
|
|
3214
|
-
{ name: 'name' },
|
|
3215
|
-
{ name: 'month', grouped: true },
|
|
3216
|
-
{ name: 'department', grouped: true },
|
|
3217
|
-
],
|
|
3218
|
-
});
|
|
3219
|
-
|
|
3220
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3221
|
-
|
|
3222
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3223
|
-
|
|
3224
|
-
expect(grid.groupedData).toMatchObject([
|
|
3225
|
-
{ groupValue: 11 },
|
|
3226
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3227
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3228
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3229
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3230
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3231
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3232
|
-
{ groupValue: 12 },
|
|
3233
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3234
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3235
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3236
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3237
|
-
]);
|
|
3238
|
-
});
|
|
3239
|
-
});
|
|
3240
|
-
|
|
3241
|
-
describe('toolbar creation', () => {
|
|
3242
|
-
it('should render predefined items in toolbarConfig', () => {
|
|
3243
|
-
const grid = new TekGrid({
|
|
3244
|
-
name: 'grid',
|
|
3245
|
-
component: 'TekGrid',
|
|
3246
|
-
toolbarConfig: ['addButton'],
|
|
3247
|
-
});
|
|
3248
|
-
grid.onCreated();
|
|
3249
|
-
|
|
3250
|
-
expect(grid.toolbarSlot.length).toBe(3);
|
|
3251
|
-
const toolbarDiv = grid.toolbarSlot[2];
|
|
3252
|
-
expect(toolbarDiv.children?.length).toBe(1);
|
|
3253
|
-
expect(toolbarDiv.children?.[0].name).toContain('_add_tooltip');
|
|
3254
|
-
});
|
|
3255
|
-
|
|
3256
|
-
it('should render custom components in toolbarConfig', () => {
|
|
3257
|
-
const grid = new TekGrid({
|
|
3258
|
-
name: 'grid',
|
|
3259
|
-
component: 'TekGrid',
|
|
3260
|
-
toolbarConfig: [{ component: 'ZdButton', name: 'customButton' }],
|
|
3261
|
-
});
|
|
3262
|
-
grid.onCreated();
|
|
3263
|
-
|
|
3264
|
-
const toolbarDiv = grid.toolbarSlot[2];
|
|
3265
|
-
expect(toolbarDiv.children?.length).toBe(1);
|
|
3266
|
-
expect(toolbarDiv.children?.[0].name).toBe('customButton');
|
|
3267
|
-
});
|
|
3268
|
-
|
|
3269
|
-
it('should alert about invalid items of string type in toolbarConfig', () => {
|
|
3270
|
-
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
3271
|
-
const grid = new TekGrid({
|
|
3272
|
-
name: 'grid',
|
|
3273
|
-
component: 'TekGrid',
|
|
3274
|
-
toolbarConfig: ['invalidItem'],
|
|
3275
|
-
});
|
|
3276
|
-
grid.onCreated();
|
|
3277
|
-
|
|
3278
|
-
expect(warnSpy).toHaveBeenCalledWith('Predefined toolbar item "invalidItem" not found.');
|
|
3279
|
-
warnSpy.mockRestore();
|
|
3280
|
-
});
|
|
3281
|
-
|
|
3282
|
-
it('should alert about invalid items in toolbarConfig', () => {
|
|
3283
|
-
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
3284
|
-
const grid = new TekGrid({
|
|
3285
|
-
name: 'grid',
|
|
3286
|
-
component: 'TekGrid',
|
|
3287
|
-
toolbarConfig: [123 as any],
|
|
3288
|
-
});
|
|
3289
|
-
grid.onCreated();
|
|
3290
|
-
|
|
3291
|
-
expect(warnSpy).toHaveBeenCalledWith('Invalid item in toolbarConfig:', 123);
|
|
3292
|
-
warnSpy.mockRestore();
|
|
3293
|
-
});
|
|
3294
|
-
});
|
|
3295
|
-
|
|
3296
|
-
describe('addButtonClick', () => {
|
|
3297
|
-
it('should set editingNewRows as true when editNewRowsOnly is enabled', () => {
|
|
3298
|
-
const grid = new TekGrid({
|
|
3299
|
-
name: 'grid',
|
|
3300
|
-
component: 'TekGrid',
|
|
3301
|
-
addButton: true,
|
|
3302
|
-
editNewRowsOnly: true,
|
|
3303
|
-
});
|
|
3304
|
-
|
|
3305
|
-
(grid as any).gridBase.addButtonClick({ event: new Event('click') });
|
|
3306
|
-
|
|
3307
|
-
expect((grid as any).editingNewRows).toBe(true);
|
|
3308
|
-
});
|
|
3309
|
-
});
|
|
3310
|
-
|
|
3311
|
-
describe('deleteButtonClick', () => {
|
|
3312
|
-
it('should throw TekGridDeleteRowsError when selectAllPages is true', () => {
|
|
3313
|
-
const grid = new TekGrid({
|
|
3314
|
-
name: 'grid',
|
|
3315
|
-
component: 'TekGrid',
|
|
3316
|
-
deleteButton: 'selection',
|
|
3317
|
-
selectAllPages: true,
|
|
3318
|
-
});
|
|
3319
|
-
|
|
3320
|
-
const deleteFn = () => {
|
|
3321
|
-
(grid as any).gridBase.deleteButtonClick({ event: new Event('click') });
|
|
3322
|
-
};
|
|
3323
|
-
|
|
3324
|
-
expect(deleteFn).toThrow(TekGridDeleteRowsError);
|
|
3325
|
-
});
|
|
3326
|
-
});
|
|
3327
|
-
|
|
3328
|
-
describe('reloadGrid', () => {
|
|
3329
|
-
it('should call grid.reload() if beforeReload event is not prevented', () => {
|
|
3330
|
-
const grid = new TekGrid({
|
|
3331
|
-
name: 'grid',
|
|
3332
|
-
component: 'TekGrid',
|
|
3333
|
-
});
|
|
3334
|
-
const reloadSpy = jest.spyOn(grid, 'reload');
|
|
3335
|
-
const event = new Event('click');
|
|
3336
|
-
|
|
3337
|
-
(grid as any).gridBase.reloadGrid({ event });
|
|
3338
|
-
|
|
3339
|
-
expect(reloadSpy).toHaveBeenCalledTimes(1);
|
|
3340
|
-
|
|
3341
|
-
reloadSpy.mockRestore();
|
|
3342
|
-
});
|
|
3343
|
-
|
|
3344
|
-
it('should not call grid.reload() if beforeReload event is prevented', () => {
|
|
3345
|
-
const grid = new TekGrid({
|
|
3346
|
-
name: 'grid',
|
|
3347
|
-
component: 'TekGrid',
|
|
3348
|
-
});
|
|
3349
|
-
const reloadSpy = jest.spyOn(grid, 'reload');
|
|
3350
|
-
const mockEvent = { defaultPrevented: true };
|
|
3351
|
-
|
|
3352
|
-
(grid as any).gridBase.reloadGrid({ event: mockEvent });
|
|
3353
|
-
|
|
3354
|
-
expect(reloadSpy).not.toHaveBeenCalled();
|
|
3355
|
-
|
|
3356
|
-
reloadSpy.mockRestore();
|
|
3357
|
-
});
|
|
3358
|
-
});
|
|
3359
|
-
|
|
3360
|
-
describe('toolbar creation', () => {
|
|
3361
|
-
it('should create toolbar with default items', () => {
|
|
3362
|
-
const grid = new TekGrid({
|
|
3363
|
-
name: 'grid',
|
|
3364
|
-
component: 'TekGrid',
|
|
3365
|
-
});
|
|
3366
|
-
const { gridBase } = grid as any;
|
|
3367
|
-
delete (gridBase as any).defaultToolbar.title;
|
|
3368
|
-
delete (gridBase as any).defaultToolbar.hideButton;
|
|
3369
|
-
|
|
3370
|
-
const toolbarSlot = gridBase.createToolbarProps();
|
|
3371
|
-
|
|
3372
|
-
expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_title'))).toBeUndefined();
|
|
3373
|
-
expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_hideTooltip'))).toBeUndefined();
|
|
3374
|
-
expect(toolbarSlot[0].name).toBe('grid_toolbarDiv');
|
|
3375
|
-
});
|
|
3376
|
-
});
|
|
3377
|
-
});
|