@zeedhi/teknisa-components-common 3.0.0 → 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 +4 -1
- package/dist/teknisa-components-common.js +3722 -32
- package/dist/teknisa-components-common.min.js +3722 -32
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
- 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/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- 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/dist/types/components/tek-grid/layout-options.d.ts +39 -0
- package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
- 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/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
- 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/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
- package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
- package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- 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 +1 -0
- package/dist/types/utils/config/config.d.ts +7 -0
- 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/package.json +2 -2
- package/src/components/index.ts +5 -12
- 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 +1 -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/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 +110 -241
- 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} +77 -35
- 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} +48 -6
- 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/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
TekGrid, TekGridColumn,
|
|
6
|
+
ComponentRender,
|
|
7
|
+
ITekGridAtoms,
|
|
8
|
+
TekRestDatasource,
|
|
9
|
+
DynamicFilterDatasourceFactory,
|
|
10
|
+
KeyMapMerger,
|
|
11
|
+
TekMemoryDatasource,
|
|
12
|
+
ITekGridProps,
|
|
13
|
+
} from '../../../../src';
|
|
14
|
+
import {
|
|
15
|
+
Metadata,
|
|
16
|
+
Datasource,
|
|
17
|
+
Loader,
|
|
18
|
+
SimpleControllerBuilder,
|
|
19
|
+
Newable,
|
|
20
|
+
} from '@zeedhi/core';
|
|
21
|
+
import {
|
|
22
|
+
IterableTable,
|
|
23
|
+
GroupedDataSelector,
|
|
24
|
+
TekGridEvents,
|
|
25
|
+
DataNavigator,
|
|
26
|
+
TableActionBuilder,
|
|
27
|
+
ColumnsSearcher,
|
|
28
|
+
GroupedDataManager,
|
|
29
|
+
TekGridToolbarProvider,
|
|
30
|
+
GroupedViewNavigator,
|
|
31
|
+
DataEditorWithAdd,
|
|
32
|
+
} from '../../../../src';
|
|
33
|
+
import { createComponent, findComponent, setClick, spyOnAllMethods } from '../../__helpers__';
|
|
34
|
+
|
|
35
|
+
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
36
|
+
|
|
37
|
+
jest.useFakeTimers();
|
|
38
|
+
|
|
39
|
+
const createAtom = <T extends ComponentRender>(name: keyof ITekGridAtoms, componentClass: Newable<T>, instance: TekGrid): T => {
|
|
40
|
+
const buttonName = instance.getAtomName(name);
|
|
41
|
+
const buttonProps = findComponent(buttonName, instance.toolbarSlot)
|
|
42
|
+
return createComponent(componentClass, buttonProps);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const createAtomAndClick = <T extends ComponentRender>(name: keyof ITekGridAtoms, componentClass: Newable<T>, instance: TekGrid): T => {
|
|
46
|
+
const button = createAtom(name, componentClass, instance);
|
|
47
|
+
const event = {
|
|
48
|
+
defaultPrevented: false,
|
|
49
|
+
preventDefault() {
|
|
50
|
+
this.defaultPrevented = true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
setClick(button, event);
|
|
54
|
+
|
|
55
|
+
return button;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const setupInstance = (props: Partial<ITekGridProps> = {}) => {
|
|
59
|
+
const instance = new TekGrid({
|
|
60
|
+
name: 'Grid',
|
|
61
|
+
component: 'TekGrid',
|
|
62
|
+
columns: [
|
|
63
|
+
{ name: 'first' },
|
|
64
|
+
{ name: 'second' },
|
|
65
|
+
{ name: 'third' },
|
|
66
|
+
],
|
|
67
|
+
datasource: {
|
|
68
|
+
limit: 2,
|
|
69
|
+
page: 1,
|
|
70
|
+
data: [
|
|
71
|
+
{ id: 1 },
|
|
72
|
+
{ id: 2 },
|
|
73
|
+
{ id: 3 },
|
|
74
|
+
{ id: 4 },
|
|
75
|
+
{ id: 5 },
|
|
76
|
+
{ id: 6 },
|
|
77
|
+
{ id: 7 },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
...props,
|
|
81
|
+
});
|
|
82
|
+
const elem = document.createElement('DIV');
|
|
83
|
+
instance.onCreated();
|
|
84
|
+
instance.onMounted(elem);
|
|
85
|
+
|
|
86
|
+
return instance;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
describe('TekGrid', () => {
|
|
90
|
+
beforeAll(() => {
|
|
91
|
+
// mock Loader
|
|
92
|
+
Loader.setBuilder(new SimpleControllerBuilder());
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
// clear all metadata instances before testing
|
|
97
|
+
const { instances } = Metadata as any;
|
|
98
|
+
Object.keys(instances).forEach((key) => {
|
|
99
|
+
Metadata.clearInstance(key, instances[key].componentId);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
jest.clearAllTimers();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('constructor()', () => {
|
|
106
|
+
it('should create new grid with default values', () => {
|
|
107
|
+
const instance = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
108
|
+
expect(instance.title).toBe('');
|
|
109
|
+
expect(instance.addButton).toBeFalsy();
|
|
110
|
+
expect(instance.deleteButton).toBe('none');
|
|
111
|
+
expect(instance.filterButton).toBeFalsy();
|
|
112
|
+
expect(instance.modalFilterProps).toEqual(
|
|
113
|
+
expect.objectContaining({
|
|
114
|
+
height: 'auto',
|
|
115
|
+
persistent: true,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
expect(instance.columnFilterButton).toBeFalsy();
|
|
119
|
+
expect(instance.dragColumns).toBeTruthy();
|
|
120
|
+
expect(instance.resizeColumns).toBeTruthy();
|
|
121
|
+
expect(instance.showLayoutOptions).toBeTruthy();
|
|
122
|
+
expect(instance.showSearch).toBeTruthy();
|
|
123
|
+
expect(instance.showSummaryTotal).toBeTruthy();
|
|
124
|
+
expect(instance.showReload).toBeTruthy();
|
|
125
|
+
expect(instance.columnsButton).toBeFalsy();
|
|
126
|
+
expect(instance.columnsButtonIgnore).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should create new Grid replacing default values', () => {
|
|
130
|
+
const instance = new TekGrid({
|
|
131
|
+
name: 'grid',
|
|
132
|
+
component: 'TekGrid',
|
|
133
|
+
title: 'title',
|
|
134
|
+
addButton: true,
|
|
135
|
+
deleteButton: 'selection',
|
|
136
|
+
filterButton: true,
|
|
137
|
+
modalFilterProps: {
|
|
138
|
+
name: 'teste',
|
|
139
|
+
height: 'auto',
|
|
140
|
+
persistent: false,
|
|
141
|
+
cssClass: 'class-test',
|
|
142
|
+
cssStyle: 'background: red',
|
|
143
|
+
draggable: true,
|
|
144
|
+
fullscreen: true,
|
|
145
|
+
light: false,
|
|
146
|
+
dark: true,
|
|
147
|
+
},
|
|
148
|
+
columnFilterButton: true,
|
|
149
|
+
dragColumns: false,
|
|
150
|
+
resizeColumns: false,
|
|
151
|
+
showLayoutOptions: false,
|
|
152
|
+
showSearch: false,
|
|
153
|
+
showSummaryTotal: false,
|
|
154
|
+
showReload: false,
|
|
155
|
+
columns: [
|
|
156
|
+
{ name: 'id' },
|
|
157
|
+
],
|
|
158
|
+
columnsButton: true,
|
|
159
|
+
columnsButtonIgnore: ['id'],
|
|
160
|
+
});
|
|
161
|
+
expect(instance.title).toBe('title');
|
|
162
|
+
expect(instance.addButton).toBeTruthy();
|
|
163
|
+
expect(instance.deleteButton).toBe('selection');
|
|
164
|
+
expect(instance.filterButton).toBeTruthy();
|
|
165
|
+
expect(instance.modalFilterProps).toEqual(
|
|
166
|
+
expect.objectContaining({
|
|
167
|
+
height: 'auto',
|
|
168
|
+
persistent: false,
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
expect(instance.columnFilterButton).toBeTruthy();
|
|
172
|
+
expect(instance.dragColumns).toBeFalsy();
|
|
173
|
+
expect(instance.resizeColumns).toBeFalsy();
|
|
174
|
+
expect(instance.showLayoutOptions).toBeFalsy();
|
|
175
|
+
expect(instance.showSearch).toBeFalsy();
|
|
176
|
+
expect(instance.showSummaryTotal).toBeFalsy();
|
|
177
|
+
expect(instance.showReload).toBeFalsy();
|
|
178
|
+
expect(instance.columns[0]).toBeInstanceOf(TekGridColumn);
|
|
179
|
+
expect(instance.columnsButton).toBeTruthy();
|
|
180
|
+
expect(instance.columnsButtonIgnore).toEqual(['id']);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should create toolbar and footer', () => {
|
|
184
|
+
const instance = new TekGrid({
|
|
185
|
+
name: 'grid',
|
|
186
|
+
component: 'TekGrid',
|
|
187
|
+
title: 'title',
|
|
188
|
+
addButton: true,
|
|
189
|
+
deleteButton: 'selection',
|
|
190
|
+
filterButton: true,
|
|
191
|
+
columnFilterButton: true,
|
|
192
|
+
dragColumns: false,
|
|
193
|
+
resizeColumns: false,
|
|
194
|
+
showLayoutOptions: false,
|
|
195
|
+
});
|
|
196
|
+
instance.onCreated();
|
|
197
|
+
expect(instance.toolbarSlot.length).toBe(4);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should overwrite toolbar', () => {
|
|
201
|
+
const instance = new TekGrid({
|
|
202
|
+
name: 'grid',
|
|
203
|
+
component: 'TekGrid',
|
|
204
|
+
title: 'title',
|
|
205
|
+
addButton: true,
|
|
206
|
+
deleteButton: 'selection',
|
|
207
|
+
filterButton: true,
|
|
208
|
+
columnFilterButton: true,
|
|
209
|
+
dragColumns: false,
|
|
210
|
+
resizeColumns: false,
|
|
211
|
+
showLayoutOptions: false,
|
|
212
|
+
toolbarSlot: [],
|
|
213
|
+
});
|
|
214
|
+
instance.onCreated();
|
|
215
|
+
expect(instance.toolbarSlot.length).toBe(0);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should create new TekGrid with accessor datasource', () => {
|
|
219
|
+
const spy = jest.spyOn(Loader, 'getInstance').mockImplementation(() => {
|
|
220
|
+
return {
|
|
221
|
+
datasource: {
|
|
222
|
+
uniqueKey: 'id',
|
|
223
|
+
data: [{ id: '1' }],
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
const instance = new TekGrid({
|
|
228
|
+
name: 'grid',
|
|
229
|
+
component: 'TekGrid',
|
|
230
|
+
datasource: '{{AppController.datasource}}' as any,
|
|
231
|
+
});
|
|
232
|
+
instance.onCreated();
|
|
233
|
+
|
|
234
|
+
expect(instance.datasource).toBeInstanceOf(Datasource);
|
|
235
|
+
expect(instance.datasource.data).toEqual([{ id: '1' }]);
|
|
236
|
+
|
|
237
|
+
spy.mockRestore();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should create a new grid with defined values', () => {
|
|
241
|
+
const instance = new TekGrid({
|
|
242
|
+
name: 'grid',
|
|
243
|
+
component: 'TekGrid',
|
|
244
|
+
doubleClickEdit: true,
|
|
245
|
+
backgroundColor: 'blue',
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(instance.name).toBe('grid');
|
|
249
|
+
expect(instance.doubleClickEdit).toBeTruthy();
|
|
250
|
+
expect(instance.backgroundColor).toBe('blue');
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe('saveChanges()', () => {
|
|
255
|
+
it('should call saveEditedRows', () => {
|
|
256
|
+
const instance = new TekGrid({
|
|
257
|
+
name: 'grid_saveChanges1',
|
|
258
|
+
component: 'TekGrid',
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const spy = jest.spyOn(instance, 'saveEditedRows');
|
|
262
|
+
instance.onCreated();
|
|
263
|
+
|
|
264
|
+
const button = createAtomAndClick('SAVE_BUTTON', Button, instance);
|
|
265
|
+
|
|
266
|
+
expect(spy).toHaveBeenCalled();
|
|
267
|
+
expect(button.isVisible).toBeFalsy();
|
|
268
|
+
spy.mockReset();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should call events', () => {
|
|
272
|
+
let beforeSaveCalled = false;
|
|
273
|
+
let afterSaveCalled = false;
|
|
274
|
+
const instance = new TekGrid({
|
|
275
|
+
name: 'grid_saveChanges2',
|
|
276
|
+
component: 'TekGrid',
|
|
277
|
+
events: {
|
|
278
|
+
beforeSave: () => { beforeSaveCalled = true; },
|
|
279
|
+
afterSave: () => { afterSaveCalled = true; },
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
instance.onCreated();
|
|
284
|
+
|
|
285
|
+
createAtomAndClick('SAVE_BUTTON', Button, instance);
|
|
286
|
+
|
|
287
|
+
expect(beforeSaveCalled).toBeTruthy();
|
|
288
|
+
expect(afterSaveCalled).toBeTruthy();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should not call saveEditedRows if beforeSave call preventDefault', () => {
|
|
292
|
+
const beforeSaveMock = jest.fn().mockImplementation(({ event }) => { event.defaultPrevented = true });
|
|
293
|
+
const afterSaveMock = jest.fn();
|
|
294
|
+
|
|
295
|
+
const instance = new TekGrid({
|
|
296
|
+
name: 'grid_saveChanges3',
|
|
297
|
+
component: 'TekGrid',
|
|
298
|
+
events: {
|
|
299
|
+
beforeSave: beforeSaveMock,
|
|
300
|
+
afterSave: afterSaveMock,
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const spy = jest.spyOn(instance, 'saveEditedRows');
|
|
305
|
+
instance.onCreated();
|
|
306
|
+
|
|
307
|
+
createAtomAndClick('SAVE_BUTTON', Button, instance);
|
|
308
|
+
|
|
309
|
+
expect(beforeSaveMock).toHaveBeenCalled();
|
|
310
|
+
expect(afterSaveMock).not.toHaveBeenCalled();
|
|
311
|
+
expect(spy).not.toHaveBeenCalled();
|
|
312
|
+
spy.mockReset();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe('cancelChanges()', () => {
|
|
317
|
+
it('should call cancelEditedRows', () => {
|
|
318
|
+
const instance = new TekGrid({
|
|
319
|
+
name: 'grid_cancelChanges1',
|
|
320
|
+
component: 'TekGrid',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
324
|
+
instance.onCreated();
|
|
325
|
+
|
|
326
|
+
const button = createAtomAndClick('CANCEL_BUTTON', Button, instance);
|
|
327
|
+
|
|
328
|
+
expect(spy).toHaveBeenCalled();
|
|
329
|
+
expect(button.isVisible).toBeFalsy();
|
|
330
|
+
spy.mockReset();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should call events', () => {
|
|
334
|
+
let beforeCancelCalled = false;
|
|
335
|
+
let afterCancelCalled = false;
|
|
336
|
+
const instance = new TekGrid({
|
|
337
|
+
name: 'grid_cancelChanges2',
|
|
338
|
+
component: 'TekGrid',
|
|
339
|
+
events: {
|
|
340
|
+
beforeCancel: () => { beforeCancelCalled = true; },
|
|
341
|
+
afterCancel: () => { afterCancelCalled = true; },
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
instance.onCreated();
|
|
346
|
+
|
|
347
|
+
createAtomAndClick('CANCEL_BUTTON', Button, instance);
|
|
348
|
+
|
|
349
|
+
expect(beforeCancelCalled).toBeTruthy();
|
|
350
|
+
expect(afterCancelCalled).toBeTruthy();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should not call cancelEditedRows if beforeSave call preventDefault', () => {
|
|
354
|
+
const beforeCancelMock = jest.fn().mockImplementation(({ event }) => { event.defaultPrevented = true });
|
|
355
|
+
const afterCancelMock = jest.fn();
|
|
356
|
+
const instance = new TekGrid({
|
|
357
|
+
name: 'grid_cancelChanges3',
|
|
358
|
+
component: 'TekGrid',
|
|
359
|
+
events: {
|
|
360
|
+
beforeCancel: beforeCancelMock,
|
|
361
|
+
afterCancel: afterCancelMock,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
366
|
+
instance.onCreated();
|
|
367
|
+
|
|
368
|
+
createAtomAndClick('CANCEL_BUTTON', Button, instance);
|
|
369
|
+
|
|
370
|
+
expect(beforeCancelMock).toHaveBeenCalled();
|
|
371
|
+
expect(afterCancelMock).not.toHaveBeenCalled();
|
|
372
|
+
expect(spy).not.toHaveBeenCalled();
|
|
373
|
+
spy.mockReset();
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
describe('addButtonClick()', () => {
|
|
378
|
+
it('should call event', () => {
|
|
379
|
+
const instance = new TekGrid({
|
|
380
|
+
name: 'grid_addClick1',
|
|
381
|
+
component: 'TekGrid',
|
|
382
|
+
addButton: true,
|
|
383
|
+
editNewRowsOnly: true,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
instance.onCreated();
|
|
387
|
+
|
|
388
|
+
const button = createAtomAndClick('ADD_BUTTON', Button, instance);
|
|
389
|
+
|
|
390
|
+
const addClickSpy = jest.fn();
|
|
391
|
+
instance.events = {
|
|
392
|
+
addClick: addClickSpy,
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
expect(instance.editingNewRows).toBeTruthy();
|
|
396
|
+
|
|
397
|
+
setClick(button)
|
|
398
|
+
|
|
399
|
+
expect(addClickSpy).toHaveBeenCalled();
|
|
400
|
+
expect(button.isVisible).toBeTruthy();
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
describe('hideButtonClick()', () => {
|
|
405
|
+
it('should hide toolbar', () => {
|
|
406
|
+
const instance = new TekGrid({
|
|
407
|
+
name: 'grid_deleteClick2',
|
|
408
|
+
component: 'TekGrid',
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
instance.onCreated();
|
|
412
|
+
|
|
413
|
+
const toolbarMock = { isVisible: true };
|
|
414
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => toolbarMock);
|
|
415
|
+
|
|
416
|
+
expect(toolbarMock.isVisible).toBeTruthy();
|
|
417
|
+
|
|
418
|
+
createAtomAndClick('HIDE_BUTTON', Button, instance);
|
|
419
|
+
|
|
420
|
+
expect(toolbarMock.isVisible).toBeFalsy();
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('should show toolbar', () => {
|
|
424
|
+
const instance = new TekGrid({
|
|
425
|
+
name: 'grid_deleteClick2',
|
|
426
|
+
component: 'TekGrid',
|
|
427
|
+
toolbarOpened: false,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
instance.onCreated();
|
|
431
|
+
|
|
432
|
+
const toolbarMock = { isVisible: true };
|
|
433
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => toolbarMock);
|
|
434
|
+
|
|
435
|
+
const button = createAtomAndClick('HIDE_BUTTON', Button, instance);
|
|
436
|
+
|
|
437
|
+
expect(toolbarMock.isVisible).toBeFalsy();
|
|
438
|
+
|
|
439
|
+
setClick(button);
|
|
440
|
+
|
|
441
|
+
expect(toolbarMock.isVisible).toBeTruthy();
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe('deleteButtonClick()', () => {
|
|
446
|
+
it('should call deleteRows', () => {
|
|
447
|
+
const instance = new TekGrid({
|
|
448
|
+
name: 'grid_deleteButtonClick1',
|
|
449
|
+
component: 'TekGrid',
|
|
450
|
+
deleteButton: 'currentRow',
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
const spy = jest.spyOn(instance, 'deleteRows');
|
|
454
|
+
instance.onCreated();
|
|
455
|
+
|
|
456
|
+
const button = createAtomAndClick('DELETE_BUTTON', Button, instance);
|
|
457
|
+
expect(spy).toHaveBeenCalled();
|
|
458
|
+
expect(button.isVisible).toBeTruthy();
|
|
459
|
+
expect(button.disabled).toBeTruthy();
|
|
460
|
+
spy.mockReset();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('should call events', () => {
|
|
464
|
+
let beforeDeleteCalled = false;
|
|
465
|
+
let afterDeleteCalled = false;
|
|
466
|
+
const instance = new TekGrid({
|
|
467
|
+
name: 'grid_deleteClick2',
|
|
468
|
+
component: 'TekGrid',
|
|
469
|
+
events: {
|
|
470
|
+
beforeDelete: () => { beforeDeleteCalled = true; },
|
|
471
|
+
afterDelete: () => { afterDeleteCalled = true; },
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
instance.onCreated();
|
|
476
|
+
createAtomAndClick('DELETE_BUTTON', Button, instance);
|
|
477
|
+
expect(beforeDeleteCalled).toBeTruthy();
|
|
478
|
+
expect(afterDeleteCalled).toBeTruthy();
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it('should not call afterDelete if beforeDelete call preventDefault', () => {
|
|
482
|
+
const beforeDeleteMock = jest.fn().mockImplementation(({ event }) => { event.defaultPrevented = true });
|
|
483
|
+
const afterDeleteMock = jest.fn();
|
|
484
|
+
const instance = new TekGrid({
|
|
485
|
+
name: 'grid_deleteClick3',
|
|
486
|
+
component: 'TekGrid',
|
|
487
|
+
events: {
|
|
488
|
+
beforeDelete: beforeDeleteMock,
|
|
489
|
+
afterDelete: afterDeleteMock,
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const spy = jest.spyOn(instance, 'cancelEditedRows');
|
|
494
|
+
instance.onCreated();
|
|
495
|
+
|
|
496
|
+
createAtomAndClick('DELETE_BUTTON', Button, instance);
|
|
497
|
+
|
|
498
|
+
expect(beforeDeleteMock).toHaveBeenCalled();
|
|
499
|
+
expect(afterDeleteMock).not.toHaveBeenCalled();
|
|
500
|
+
expect(spy).not.toHaveBeenCalled();
|
|
501
|
+
spy.mockReset();
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('when deleteButton is clicked with selectAllPages, should throw', () => {
|
|
505
|
+
const instance = new TekGrid({
|
|
506
|
+
name: 'grid_deleteButtonClick1',
|
|
507
|
+
component: 'TekGrid',
|
|
508
|
+
deleteButton: 'selection',
|
|
509
|
+
selectAllPages: true,
|
|
510
|
+
datasource: {
|
|
511
|
+
data: [{ id: '1' }],
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
instance.onCreated();
|
|
516
|
+
|
|
517
|
+
const button = createAtom('DELETE_BUTTON', Button, instance);
|
|
518
|
+
|
|
519
|
+
expect(button.isVisible).toBeTruthy();
|
|
520
|
+
expect(button.disabled).toBeTruthy();
|
|
521
|
+
|
|
522
|
+
instance.selectAll(true);
|
|
523
|
+
|
|
524
|
+
expect(button.disabled).toBeFalsy();
|
|
525
|
+
expect(() => setClick(button)).toThrow();
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
describe('disableDeleteButton', () => {
|
|
530
|
+
it('should not disable deleteButton when deleteButton equals none', () => {
|
|
531
|
+
const instance = new TekGrid({
|
|
532
|
+
name: 'grid_deleteButtonClick1',
|
|
533
|
+
component: 'TekGrid',
|
|
534
|
+
deleteButton: 'none',
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
instance.onCreated();
|
|
538
|
+
const button = createAtom('DELETE_BUTTON', Button, instance);
|
|
539
|
+
expect(button.isVisible).toBeFalsy();
|
|
540
|
+
expect(button.disabled).toBeFalsy();
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
describe('getConditionalProps', () => {
|
|
545
|
+
it('should return an empty object when no conditions are applied', () => {
|
|
546
|
+
const grid = setupInstance();
|
|
547
|
+
const row = grid.datasource.data[0];
|
|
548
|
+
const column = grid.columns[0];
|
|
549
|
+
const result = grid.getConditionalProps({ row, column });
|
|
550
|
+
expect(result).toEqual({});
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it('should merge row style conditions and cell applied conditions', () => {
|
|
554
|
+
const grid = setupInstance();
|
|
555
|
+
grid.getRowStyleConditions = jest.fn().mockReturnValue({ backgroundColor: 'red' });
|
|
556
|
+
grid.getAppliedConditions = jest.fn().mockReturnValue({ fontSize: '12px' });
|
|
557
|
+
const row = grid.datasource.data[0];
|
|
558
|
+
const column = grid.columns[0];
|
|
559
|
+
const result = grid.getConditionalProps({ row, column });
|
|
560
|
+
expect(result).toEqual({ backgroundColor: 'red', fontSize: '12px' });
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
describe('onCreated()', () => {
|
|
565
|
+
it('should call DynamicFilterDatasourceFactory to create dynamic filter datasources', () => {
|
|
566
|
+
const spy = jest.spyOn(DynamicFilterDatasourceFactory.prototype, 'factory');
|
|
567
|
+
setupInstance({ name: 'grid', component: 'TekGrid', datasource: { type: 'tek-memory' } });
|
|
568
|
+
|
|
569
|
+
expect(spy).toHaveBeenCalled();
|
|
570
|
+
spy.mockReset();
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
describe('onMounted()', () => {
|
|
575
|
+
it('should call KeyMapMerger bind', () => {
|
|
576
|
+
const spy = jest.spyOn(KeyMapMerger.prototype, 'bind');
|
|
577
|
+
const instance = setupInstance({ name: 'grid', component: 'TekGrid' });
|
|
578
|
+
instance.onMounted({} as HTMLElement);
|
|
579
|
+
|
|
580
|
+
expect(spy).toHaveBeenCalled();
|
|
581
|
+
spy.mockReset();
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
describe('onBeforeDestroy()', () => {
|
|
586
|
+
it('should call KeyMapMerger unbind', () => {
|
|
587
|
+
const spy = jest.spyOn(KeyMapMerger.prototype, 'unbind');
|
|
588
|
+
const instance = setupInstance({ name: 'grid', component: 'TekGrid' });
|
|
589
|
+
instance.onMounted({} as HTMLElement);
|
|
590
|
+
instance.onBeforeDestroy();
|
|
591
|
+
|
|
592
|
+
expect(spy).toHaveBeenCalled();
|
|
593
|
+
spy.mockReset();
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
describe('columnHasFilter()', () => {
|
|
598
|
+
it('should return true if column has filter', () => {
|
|
599
|
+
const datasourceMock = { hasFilter: jest.fn(() => true) };
|
|
600
|
+
const instance = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
601
|
+
instance.datasource = datasourceMock as any as Datasource;
|
|
602
|
+
|
|
603
|
+
expect(instance.columnHasFilter('test')).toBeTruthy();
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
describe('TekGrid Delegations', () => {
|
|
608
|
+
const mockProps = {
|
|
609
|
+
name: 'test-grid',
|
|
610
|
+
component: 'ZdGrid',
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
it('should call IterableTable delegation methods', () => {
|
|
614
|
+
const spyObj = spyOnAllMethods(IterableTable.prototype);
|
|
615
|
+
const instance = new TekGrid(mockProps);
|
|
616
|
+
|
|
617
|
+
instance.changeOrder([{ key: 'name', order: 'asc' }]);
|
|
618
|
+
expect(spyObj.changeOrder).toHaveBeenCalledWith([{ key: 'name', order: 'asc' }]);
|
|
619
|
+
|
|
620
|
+
instance.selectCell({ id: 1 }, { name: 'test' } as any);
|
|
621
|
+
expect(spyObj.selectCell).toHaveBeenCalledWith({ id: 1 }, { name: 'test' });
|
|
622
|
+
|
|
623
|
+
instance.reapplyRowStyleConditions({ id: 1 });
|
|
624
|
+
expect(spyObj.reapplyRowStyleConditions).toHaveBeenCalledWith({ id: 1 });
|
|
625
|
+
|
|
626
|
+
instance.getRowStyleConditions({ id: 1 });
|
|
627
|
+
expect(spyObj.getRowStyleConditions).toHaveBeenCalledWith({ id: 1 });
|
|
628
|
+
|
|
629
|
+
instance.deleteRows();
|
|
630
|
+
expect(spyObj.deleteRows).toHaveBeenCalled();
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it('should call GroupedDataSelector delegation methods', () => {
|
|
634
|
+
const spyObj = spyOnAllMethods(GroupedDataSelector.prototype);
|
|
635
|
+
const instance = new TekGrid(mockProps);
|
|
636
|
+
|
|
637
|
+
instance.selectAll(true);
|
|
638
|
+
expect(spyObj.selectAll).toHaveBeenCalledWith(true);
|
|
639
|
+
|
|
640
|
+
instance.toggleRow({ id: 1 });
|
|
641
|
+
expect(spyObj.toggleRow).toHaveBeenCalledWith({ id: 1 });
|
|
642
|
+
|
|
643
|
+
instance.selectRow({ id: 1 }, true);
|
|
644
|
+
expect(spyObj.selectRow).toHaveBeenCalledWith({ id: 1 }, true);
|
|
645
|
+
|
|
646
|
+
instance.callDisableSelection({ id: 1 });
|
|
647
|
+
expect(spyObj.callDisableSelection).toHaveBeenCalledWith({ id: 1 });
|
|
648
|
+
|
|
649
|
+
instance.selectClick({ id: 1 }, true, {} as Event);
|
|
650
|
+
expect(spyObj.selectClick).toHaveBeenCalledWith({ id: 1 }, true, {}, undefined);
|
|
651
|
+
|
|
652
|
+
instance.selectAllClick(true, {} as Event);
|
|
653
|
+
expect(spyObj.selectAllClick).toHaveBeenCalledWith(true, {}, undefined);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it('should call TekGridEvents delegation methods', () => {
|
|
657
|
+
const spyObj = spyOnAllMethods(TekGridEvents.prototype);
|
|
658
|
+
const instance = new TekGrid(mockProps);
|
|
659
|
+
|
|
660
|
+
instance.calcSummary({ name: 'test' } as any, {} as any, { id: 1 });
|
|
661
|
+
expect(spyObj.calcSummary).toHaveBeenCalledWith({ name: 'test' }, {}, { id: 1 });
|
|
662
|
+
|
|
663
|
+
instance.rowClick({ id: 1 }, {} as Event);
|
|
664
|
+
expect(spyObj.rowClick).toHaveBeenCalledWith({ id: 1 }, {}, undefined);
|
|
665
|
+
|
|
666
|
+
instance.rowDoubleClick({ id: 1 }, {} as Event);
|
|
667
|
+
expect(spyObj.rowDoubleClick).toHaveBeenCalledWith({ id: 1 }, {}, undefined);
|
|
668
|
+
|
|
669
|
+
instance.cellDoubleClick({ id: 1 }, { name: 'test' } as any, {} as Event);
|
|
670
|
+
expect(spyObj.cellDoubleClick).toHaveBeenCalledWith({ id: 1 }, { name: 'test' }, {}, undefined);
|
|
671
|
+
|
|
672
|
+
instance.inlineEdit({ id: 1 }, { name: 'test' } as any);
|
|
673
|
+
expect(spyObj.inlineEdit).toHaveBeenCalledWith({ id: 1 }, { name: 'test' }, undefined, undefined);
|
|
674
|
+
|
|
675
|
+
instance.cellClick({ id: 1 }, { name: 'test' } as any, {} as Event);
|
|
676
|
+
expect(spyObj.cellClick).toHaveBeenCalledWith({ id: 1 }, { name: 'test' }, {}, undefined);
|
|
677
|
+
|
|
678
|
+
instance.cellClickEvent({ id: 1 }, { name: 'test' } as any, {} as Event);
|
|
679
|
+
expect(spyObj.cellClickEvent).toHaveBeenCalledWith({ id: 1 }, { name: 'test' }, {}, undefined);
|
|
680
|
+
|
|
681
|
+
instance.groupRowClick({ id: 1 }, {} as Event);
|
|
682
|
+
expect(spyObj.groupRowClick).toHaveBeenCalledWith({ id: 1 }, {}, undefined);
|
|
683
|
+
|
|
684
|
+
instance.groupRowDoubleClick({ id: 1 }, {} as Event);
|
|
685
|
+
expect(spyObj.groupRowDoubleClick).toHaveBeenCalledWith({ id: 1 }, {}, undefined);
|
|
686
|
+
|
|
687
|
+
instance.selectGroupClick({ id: 1 }, true, {} as Event);
|
|
688
|
+
expect(spyObj.selectGroupClick).toHaveBeenCalledWith({ id: 1 }, true, {}, undefined);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('should call DataNavigator delegation methods', () => {
|
|
692
|
+
const spyObj = spyOnAllMethods(DataNavigator.prototype);
|
|
693
|
+
const instance = new TekGrid(mockProps);
|
|
694
|
+
|
|
695
|
+
instance.navigatePageUp();
|
|
696
|
+
expect(spyObj.navigatePageUp).toHaveBeenCalled();
|
|
697
|
+
|
|
698
|
+
instance.navigatePageDown();
|
|
699
|
+
expect(spyObj.navigatePageDown).toHaveBeenCalled();
|
|
700
|
+
|
|
701
|
+
instance.navigateDatasource('up');
|
|
702
|
+
expect(spyObj.navigateDatasource).toHaveBeenCalledWith('up');
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('should call GroupedViewNavigator delegation methods', () => {
|
|
706
|
+
const spyObj = spyOnAllMethods(GroupedViewNavigator.prototype);
|
|
707
|
+
const instance = new TekGrid(mockProps);
|
|
708
|
+
|
|
709
|
+
instance.setViewNavigate(() => {});
|
|
710
|
+
expect(spyObj.setViewNavigate).toHaveBeenCalled();
|
|
711
|
+
|
|
712
|
+
instance.navigateLeft({} as any);
|
|
713
|
+
expect(spyObj.navigateLeft).not.toHaveBeenCalledWith({});
|
|
714
|
+
|
|
715
|
+
instance.navigateRight({} as any);
|
|
716
|
+
expect(spyObj.navigateRight).not.toHaveBeenCalledWith({});
|
|
717
|
+
|
|
718
|
+
instance.cellSelection = true;
|
|
719
|
+
|
|
720
|
+
instance.navigateLeft({} as any);
|
|
721
|
+
expect(spyObj.navigateLeft).toHaveBeenCalledWith({});
|
|
722
|
+
|
|
723
|
+
instance.navigateRight({} as any);
|
|
724
|
+
expect(spyObj.navigateRight).toHaveBeenCalledWith({});
|
|
725
|
+
|
|
726
|
+
instance.navigateUp();
|
|
727
|
+
expect(spyObj.navigateUp).toHaveBeenCalled();
|
|
728
|
+
|
|
729
|
+
instance.navigateDown();
|
|
730
|
+
expect(spyObj.navigateDown).toHaveBeenCalled();
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it('should call DataEditorWithAdd delegation methods', () => {
|
|
734
|
+
const spyObj = spyOnAllMethods(DataEditorWithAdd.prototype);
|
|
735
|
+
const instance = new TekGrid(mockProps);
|
|
736
|
+
|
|
737
|
+
instance.addCancelColumn();
|
|
738
|
+
expect(spyObj.addCancelColumn).toHaveBeenCalled();
|
|
739
|
+
|
|
740
|
+
instance.getCancelColumnProps();
|
|
741
|
+
expect(spyObj.getCancelColumnProps).toHaveBeenCalled();
|
|
742
|
+
|
|
743
|
+
instance.isAdded({ id: 1 });
|
|
744
|
+
expect(spyObj.isAdded).toHaveBeenCalledWith({ id: 1 });
|
|
745
|
+
|
|
746
|
+
instance.cancelAddedRow('1');
|
|
747
|
+
expect(spyObj.cancelAddedRow).toHaveBeenCalledWith('1');
|
|
748
|
+
|
|
749
|
+
instance.cancelAddedRows();
|
|
750
|
+
expect(spyObj.cancelAddedRows).toHaveBeenCalled();
|
|
751
|
+
|
|
752
|
+
instance.getAddedRows();
|
|
753
|
+
expect(spyObj.getAddedRows).toHaveBeenCalled();
|
|
754
|
+
|
|
755
|
+
instance.addNewRow({ id: 1 });
|
|
756
|
+
expect(spyObj.addNewRow).toHaveBeenCalledWith({ id: 1 }, undefined);
|
|
757
|
+
|
|
758
|
+
instance.getVisibleValue({ id: 1 }, { name: 'test' } as any);
|
|
759
|
+
expect(spyObj.getVisibleValue).toHaveBeenCalledWith({ id: 1 }, { name: 'test' });
|
|
760
|
+
|
|
761
|
+
instance.getEditableComponent({ name: 'test' } as any, { id: 1 });
|
|
762
|
+
expect(spyObj.getEditableComponent).toHaveBeenCalledWith({ name: 'test' }, { id: 1 });
|
|
763
|
+
|
|
764
|
+
instance.isEdited({ name: 'test' } as any, { id: 1 });
|
|
765
|
+
expect(spyObj.isEdited).toHaveBeenCalledWith({ name: 'test' }, { id: 1 });
|
|
766
|
+
|
|
767
|
+
instance.isValid({ name: 'test' } as any, { id: 1 });
|
|
768
|
+
expect(spyObj.isValid).toHaveBeenCalledWith({ name: 'test' }, { id: 1 }, undefined);
|
|
769
|
+
|
|
770
|
+
instance.isGridValid();
|
|
771
|
+
expect(spyObj.isGridValid).toHaveBeenCalled();
|
|
772
|
+
|
|
773
|
+
instance.getComponent('1', 'name');
|
|
774
|
+
expect(spyObj.getComponent).toHaveBeenCalledWith('1', 'name');
|
|
775
|
+
|
|
776
|
+
instance.updateRow({ id: 1 });
|
|
777
|
+
expect(spyObj.updateRow).toHaveBeenCalledWith({ id: 1 });
|
|
778
|
+
|
|
779
|
+
instance.updateCell('1', 'name', 'value');
|
|
780
|
+
expect(spyObj.updateCell).toHaveBeenCalledWith('1', 'name', 'value');
|
|
781
|
+
|
|
782
|
+
instance.setViewEnterEdit(() => {});
|
|
783
|
+
expect(spyObj.setViewEnterEdit).toHaveBeenCalled();
|
|
784
|
+
|
|
785
|
+
instance.enterEdit('1', 'name');
|
|
786
|
+
expect(spyObj.enterEdit).toHaveBeenCalledWith('1', 'name');
|
|
787
|
+
|
|
788
|
+
instance.cancelEditedRows();
|
|
789
|
+
expect(spyObj.cancelEditedRows).toHaveBeenCalled();
|
|
790
|
+
|
|
791
|
+
instance.saveEditedRows();
|
|
792
|
+
expect(spyObj.saveEditedRows).toHaveBeenCalled();
|
|
793
|
+
|
|
794
|
+
instance.reapplyCanEditRow({ id: 1 });
|
|
795
|
+
expect(spyObj.reapplyCanEditRow).toHaveBeenCalledWith({ id: 1 });
|
|
796
|
+
|
|
797
|
+
instance.getCanEditRow({ id: 1 });
|
|
798
|
+
expect(spyObj.getCanEditRow).toHaveBeenCalledWith({ id: 1 });
|
|
799
|
+
|
|
800
|
+
instance.getEditedRows();
|
|
801
|
+
expect(spyObj.getEditedRows).toHaveBeenCalled();
|
|
802
|
+
|
|
803
|
+
instance.checkValid({ name: 'test' } as any, { id: 1 });
|
|
804
|
+
expect(spyObj.checkValid).toHaveBeenCalledWith({ name: 'test' }, { id: 1 });
|
|
805
|
+
|
|
806
|
+
instance.getEditedRow({ id: 1 });
|
|
807
|
+
expect(spyObj.getEditedRow).toHaveBeenCalledWith({ id: 1 });
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
it('should call TableActionBuilder delegation methods', () => {
|
|
811
|
+
const spyObj = spyOnAllMethods(TableActionBuilder.prototype);
|
|
812
|
+
const instance = new TekGrid(mockProps);
|
|
813
|
+
|
|
814
|
+
instance.getActionComponent({} as any, { name: 'test' } as any, { id: 1 });
|
|
815
|
+
expect(spyObj.getActionComponent).toHaveBeenCalledWith({}, { name: 'test' }, { id: 1 }, undefined);
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
it('should call GroupedDataManager delegation methods', () => {
|
|
819
|
+
const spyObj = spyOnAllMethods(GroupedDataManager.prototype);
|
|
820
|
+
const instance = new TekGrid(mockProps);
|
|
821
|
+
|
|
822
|
+
instance.registerTask(Promise.resolve());
|
|
823
|
+
expect(spyObj.registerTask).toHaveBeenCalled();
|
|
824
|
+
|
|
825
|
+
instance.loadAfterTasks();
|
|
826
|
+
expect(spyObj.loadAfterTasks).toHaveBeenCalled();
|
|
827
|
+
|
|
828
|
+
instance.initializeGrouping(true);
|
|
829
|
+
expect(spyObj.initializeGrouping).toHaveBeenCalledWith(true);
|
|
830
|
+
|
|
831
|
+
instance.updateGrouping();
|
|
832
|
+
expect(spyObj.updateGrouping).toHaveBeenCalled();
|
|
833
|
+
|
|
834
|
+
instance.updateGroupedData(true);
|
|
835
|
+
expect(spyObj.updateGroupedData).toHaveBeenCalledWith(true);
|
|
836
|
+
|
|
837
|
+
instance.buildGroupedData();
|
|
838
|
+
expect(spyObj.buildGroupedData).toHaveBeenCalled();
|
|
839
|
+
|
|
840
|
+
instance.openGroup({ group: true });
|
|
841
|
+
expect(spyObj.openGroup).toHaveBeenCalledWith({ group: true });
|
|
842
|
+
|
|
843
|
+
instance.isItemVisible({ id: 1 });
|
|
844
|
+
expect(spyObj.isItemVisible).toHaveBeenCalledWith({ id: 1 });
|
|
845
|
+
|
|
846
|
+
instance.isGrouped();
|
|
847
|
+
expect(spyObj.isGrouped).toHaveBeenCalled();
|
|
848
|
+
|
|
849
|
+
instance.isColumnSearchable({ name: 'test' } as any);
|
|
850
|
+
expect(spyObj.isColumnSearchable).toHaveBeenCalledWith({ name: 'test' });
|
|
851
|
+
|
|
852
|
+
instance.getGroupedData();
|
|
853
|
+
expect(spyObj.getGroupedData).toHaveBeenCalled();
|
|
854
|
+
|
|
855
|
+
instance.directionalLeft({} as any);
|
|
856
|
+
expect(spyObj.directionalLeft).toHaveBeenCalledWith({});
|
|
857
|
+
|
|
858
|
+
instance.directionalRight({} as any);
|
|
859
|
+
expect(spyObj.directionalRight).toHaveBeenCalledWith({});
|
|
860
|
+
|
|
861
|
+
instance.setViewUpdateFixedColumns(() => {});
|
|
862
|
+
expect(spyObj.setViewUpdateFixedColumns).toHaveBeenCalled();
|
|
863
|
+
|
|
864
|
+
instance.setViewUpdateScrollData(() => {});
|
|
865
|
+
expect(spyObj.setViewUpdateScrollData).toHaveBeenCalled();
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
it('should call TekGridToolbarProvider delegation methods', () => {
|
|
869
|
+
const spyObj = spyOnAllMethods(TekGridToolbarProvider.prototype);
|
|
870
|
+
const instance = new TekGrid(mockProps);
|
|
871
|
+
|
|
872
|
+
instance.getAtomInstance('TITLE');
|
|
873
|
+
expect(spyObj.getAtomInstance).toHaveBeenCalledWith('TITLE');
|
|
874
|
+
|
|
875
|
+
instance.getAtomName('TITLE');
|
|
876
|
+
expect(spyObj.getAtomName).toHaveBeenCalledWith('TITLE');
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
it('should call ColumnsSearcher delegation methods', () => {
|
|
880
|
+
const spyObj = spyOnAllMethods(ColumnsSearcher.prototype);
|
|
881
|
+
const instance = new TekGrid(mockProps);
|
|
882
|
+
instance.datasource = new TekRestDatasource({ lazyLoad: false });
|
|
883
|
+
|
|
884
|
+
instance.setSearch('test');
|
|
885
|
+
expect(spyObj.searchColumn).toHaveBeenCalled();
|
|
886
|
+
|
|
887
|
+
spyObj.searchColumn.mockClear();
|
|
888
|
+
|
|
889
|
+
instance.datasource = new TekMemoryDatasource({ lazyLoad: false });
|
|
890
|
+
|
|
891
|
+
instance.setSearch('test');
|
|
892
|
+
expect(spyObj.searchColumn).toHaveBeenCalled();
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
});
|