@zeedhi/teknisa-components-common 1.117.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.package.json +43 -0
- package/dist/teknisa-components-common.js +3802 -0
- package/dist/teknisa-components-common.min.js +3802 -0
- package/dist/types/components/index.d.ts +7 -0
- package/{types → dist/types}/components/tek-breadcrumb-header/breadcrumb-header.d.ts +12 -12
- package/{types → dist/types}/components/tek-breadcrumb-header/interfaces.d.ts +6 -6
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/{types → dist/types}/components/tek-datasource/interfaces.d.ts +16 -16
- package/{types/components/tek-datasource/memory-datasource.d.ts → dist/types/components/tek-datasource/tek-memory-datasource.d.ts} +93 -100
- package/{types/components/tek-datasource/rest-datasource.d.ts → dist/types/components/tek-datasource/tek-rest-datasource.d.ts} +95 -103
- package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
- package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
- package/{types → dist/types}/components/tek-grid/filter-helper.d.ts +7 -7
- package/{types → dist/types}/components/tek-grid/grid-filter-button.d.ts +29 -31
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
- package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
- package/dist/types/components/tek-grid/index.d.ts +18 -0
- package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
- package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
- package/{types → dist/types}/components/tek-grid/layout-options.d.ts +39 -31
- package/{types/components/tek-grid/grid-column.d.ts → dist/types/components/tek-grid/tek-grid-column.d.ts} +42 -45
- package/{types/components/tek-grid/grid-columns-button-controller.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts} +8 -8
- package/{types/components/tek-grid/grid-columns-button.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts} +13 -12
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/button-option.d.ts +17 -16
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/index.d.ts +3 -3
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/multi-option.d.ts +12 -12
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
- package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
- package/{types → dist/types}/components/tek-user-info/TekUserInfoController.d.ts +22 -21
- package/{types → dist/types}/components/tek-user-info/interfaces.d.ts +27 -28
- package/{types → dist/types}/components/tek-user-info/tek-user-info-list.d.ts +32 -31
- package/{types → dist/types}/components/tek-user-info/tek-user-info.d.ts +37 -38
- package/{types → dist/types}/error/delete-rows-error.d.ts +6 -6
- package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
- package/dist/types/error/teknisa-common-error.d.ts +6 -0
- package/dist/types/index.d.ts +2 -0
- package/{types → dist/types}/utils/config/config.d.ts +7 -7
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
- package/dist/types/utils/is-nil.d.ts +1 -0
- package/environments.json +14 -0
- package/package.json +26 -18
- package/src/components/index.ts +101 -0
- package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +29 -0
- package/src/components/tek-breadcrumb-header/interfaces.ts +7 -0
- package/src/components/tek-datasource/index.ts +3 -0
- package/src/components/tek-datasource/interfaces.ts +36 -0
- package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
- package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
- package/src/components/tek-grid/columns-searcher.ts +22 -0
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
- package/src/components/tek-grid/filter-helper.ts +20 -0
- package/src/components/tek-grid/grid-filter-button.ts +419 -0
- package/src/components/tek-grid/grouped-data-manager.ts +448 -0
- package/src/components/tek-grid/grouped-data-selector.ts +40 -0
- package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
- package/src/components/tek-grid/index.ts +18 -0
- package/src/components/tek-grid/interfaces.ts +329 -0
- package/src/components/tek-grid/keymap-grouped.ts +20 -0
- package/src/components/tek-grid/layout-options.ts +248 -0
- package/src/components/tek-grid/tek-grid-column.ts +193 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
- package/src/components/tek-grid/tek-grid-controller.ts +140 -0
- package/src/components/tek-grid/tek-grid-events.ts +105 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
- package/src/components/tek-grid/tek-grid.ts +1118 -0
- package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
- package/src/components/tek-user-info/interfaces.ts +21 -0
- package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
- package/src/components/tek-user-info/tek-user-info.ts +337 -0
- package/src/error/tek-grid-delete-rows-error.ts +15 -0
- package/src/error/teknisa-common-error.ts +8 -0
- package/src/index.ts +2 -0
- package/src/utils/config/config.ts +8 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/is-filled-object/is-filled-object.ts +5 -0
- package/src/utils/is-nil.ts +3 -0
- package/tests/__helpers__/component-event-helper.ts +1 -1
- package/tests/__helpers__/get-child-helper.ts +1 -1
- package/tests/__helpers__/mock-created-helper.ts +1 -1
- package/tests/unit/components/crud/crud-button.spec.ts +1 -1
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +1 -11
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +5 -7
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +1 -1
- package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +114 -239
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
- package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +70 -30
- package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
- package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +44 -2
- package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +1 -1
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +10 -14
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +4 -28
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +2 -2
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +17 -152
- package/tsconfig.build.json +7 -0
- package/coverage/clover.xml +0 -2007
- package/coverage/coverage-final.json +0 -48
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -431
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +0 -100
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +0 -166
- package/coverage/lcov-report/tests/__helpers__/index.html +0 -176
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +0 -121
- package/coverage/lcov.info +0 -3885
- package/dist/tek-components-common.esm.js +0 -4833
- package/dist/tek-components-common.umd.js +0 -4870
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -3377
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +0 -24
- package/types/components/crud/crud-add-button.d.ts +0 -38
- package/types/components/crud/crud-button.d.ts +0 -27
- package/types/components/crud/crud-cancel-button.d.ts +0 -28
- package/types/components/crud/crud-delete-button.d.ts +0 -42
- package/types/components/crud/crud-form.d.ts +0 -46
- package/types/components/crud/crud-save-button.d.ts +0 -24
- package/types/components/crud/interfaces.d.ts +0 -15
- package/types/components/index.d.ts +0 -41
- package/types/components/tek-card-title/card-title.d.ts +0 -14
- package/types/components/tek-card-title/interfaces.d.ts +0 -9
- package/types/components/tek-drag-grid/interfaces.d.ts +0 -7
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +0 -36
- package/types/components/tek-grid/grid.d.ts +0 -267
- package/types/components/tek-grid/interfaces.d.ts +0 -203
- package/types/components/tek-image/image.d.ts +0 -55
- package/types/components/tek-image/interfaces.d.ts +0 -12
- package/types/components/tek-iterable-carousel/interfaces.d.ts +0 -5
- package/types/components/tek-iterable-carousel/iterable-carousel.d.ts +0 -13
- package/types/components/tek-iterable-component-render/interfaces.d.ts +0 -3
- package/types/components/tek-iterable-component-render/iterable-component-render.d.ts +0 -10
- package/types/components/tek-loading/interfaces.d.ts +0 -6
- package/types/components/tek-loading/loading.d.ts +0 -24
- package/types/components/tek-notifications/interfaces.d.ts +0 -22
- package/types/components/tek-notifications/notifications.d.ts +0 -35
- package/types/components/tek-product-card/interfaces.d.ts +0 -19
- package/types/components/tek-product-card/product-card.d.ts +0 -66
- package/types/components/tek-tree-grid/interfaces.d.ts +0 -30
- package/types/components/tek-tree-grid/tree-grid.d.ts +0 -102
- package/types/error/incomplete-groups-error.d.ts +0 -8
- package/types/index.d.ts +0 -2
- package/types/utils/extract-properties.d.ts +0 -7
- package/types/utils/grid-base/export-options/interfaces.d.ts +0 -5
- package/types/utils/grid-base/grid-base.d.ts +0 -59
- package/types/utils/grid-base/grid-controller.d.ts +0 -27
- package/types/utils/index.d.ts +0 -6
- package/types/utils/report-filter/report-filter.d.ts +0 -12
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
2
|
+
import {
|
|
3
|
+
ITekGridProps,
|
|
4
|
+
TekGrid, TekGridController,
|
|
5
|
+
} from '../../../../src';
|
|
6
|
+
|
|
7
|
+
const setupInstance = (props: Partial<ITekGridProps> = {}) => {
|
|
8
|
+
const instance = new TekGrid({
|
|
9
|
+
name: 'Grid',
|
|
10
|
+
component: 'TekGrid',
|
|
11
|
+
columns: [
|
|
12
|
+
{ name: 'first' },
|
|
13
|
+
{ name: 'second' },
|
|
14
|
+
{ name: 'third' },
|
|
15
|
+
],
|
|
16
|
+
datasource: {
|
|
17
|
+
limit: 2,
|
|
18
|
+
page: 1,
|
|
19
|
+
data: [
|
|
20
|
+
{ id: 1 },
|
|
21
|
+
{ id: 2 },
|
|
22
|
+
{ id: 3 },
|
|
23
|
+
{ id: 4 },
|
|
24
|
+
{ id: 5 },
|
|
25
|
+
{ id: 6 },
|
|
26
|
+
{ id: 7 },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
...props,
|
|
30
|
+
});
|
|
31
|
+
const elem = document.createElement('DIV');
|
|
32
|
+
instance.onCreated();
|
|
33
|
+
instance.onMounted(elem);
|
|
34
|
+
|
|
35
|
+
return instance;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe('GridController', () => {
|
|
39
|
+
beforeAll(() => {
|
|
40
|
+
Loader.setBuilder(new SimpleControllerBuilder());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('constructor()', () => {
|
|
44
|
+
it('should create controller and get info from grid', () => {
|
|
45
|
+
const grid = setupInstance({
|
|
46
|
+
name: 'Grid',
|
|
47
|
+
component: 'TekGrid',
|
|
48
|
+
title: 'title',
|
|
49
|
+
addButton: false,
|
|
50
|
+
deleteButton: 'currentRow',
|
|
51
|
+
filterButton: true,
|
|
52
|
+
columnsButton: true,
|
|
53
|
+
editing: true,
|
|
54
|
+
showEditButtons: false,
|
|
55
|
+
modalFilterProps: {
|
|
56
|
+
name: 'name',
|
|
57
|
+
height: 'auto',
|
|
58
|
+
persistent: true,
|
|
59
|
+
},
|
|
60
|
+
showExport: true,
|
|
61
|
+
showLayoutOptionsButton: true,
|
|
62
|
+
showReloadButton: true,
|
|
63
|
+
actions: [{ name: 'button', component: 'ZdButton' }],
|
|
64
|
+
});
|
|
65
|
+
grid.editing = true;
|
|
66
|
+
const instance = new TekGridController(grid);
|
|
67
|
+
expect(instance.gridTitle).toBe('title');
|
|
68
|
+
expect(instance.showAddButton).toBeFalsy();
|
|
69
|
+
expect(instance.showDeleteButton).toBeTruthy();
|
|
70
|
+
expect(instance.showFilterButton).toBeTruthy();
|
|
71
|
+
expect(instance.showActionsButton).toBeTruthy();
|
|
72
|
+
expect(instance.showExportButton).toBeTruthy();
|
|
73
|
+
expect(instance.showActionAndExportButton).toBeTruthy();
|
|
74
|
+
expect(instance.showSearchInput).toBeTruthy();
|
|
75
|
+
expect(instance.showToolbar).toBeTruthy();
|
|
76
|
+
expect(instance.toolbarClass).toBe('');
|
|
77
|
+
expect(instance.tooltipName).toBe('TEKGRID_HIDE');
|
|
78
|
+
expect(instance.showDivider2).toBeTruthy();
|
|
79
|
+
expect(instance.showDivider3).toBeTruthy();
|
|
80
|
+
expect(instance.showColumnsButton).toBeTruthy();
|
|
81
|
+
expect(instance.columnsButtonIgnore).toEqual([]);
|
|
82
|
+
expect(instance.showLayoutOptionsButton).toBeTruthy();
|
|
83
|
+
expect(instance.showReloadButton).toBeTruthy();
|
|
84
|
+
expect(instance.showDivider1).toBeTruthy();
|
|
85
|
+
expect(instance.isEditing).toBeTruthy();
|
|
86
|
+
expect(instance.isNotEditing).toBeFalsy();
|
|
87
|
+
expect(instance.showEditButtons).toBeFalsy();
|
|
88
|
+
expect(instance.disableDeleteButton).toBeTruthy();
|
|
89
|
+
expect(instance.showModalFilterProps).toEqual(
|
|
90
|
+
expect.objectContaining({
|
|
91
|
+
height: 'auto',
|
|
92
|
+
persistent: true,
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
grid.datasource.currentRow = { id: '1' };
|
|
97
|
+
expect(instance.disableDeleteButton).toBeFalsy();
|
|
98
|
+
grid.showExport = false;
|
|
99
|
+
grid.showLayoutOptions = false;
|
|
100
|
+
grid.showReload = false;
|
|
101
|
+
grid.columnsButton = false;
|
|
102
|
+
grid.actions = [];
|
|
103
|
+
grid.deleteButton = 'selection';
|
|
104
|
+
grid.selectedRows = [{ id: '1' }];
|
|
105
|
+
expect(instance.disableDeleteButton).toBeFalsy();
|
|
106
|
+
expect(instance.showExportButton).toBeFalsy();
|
|
107
|
+
expect(instance.showActionAndExportButton).toBeFalsy();
|
|
108
|
+
expect(instance.showLayoutOptionsButton).toBeFalsy();
|
|
109
|
+
|
|
110
|
+
instance.showToolbar = false;
|
|
111
|
+
expect(instance.toolbarClass).toBe('is-rotated');
|
|
112
|
+
expect(instance.tooltipName).toBe('TEKGRID_SHOW');
|
|
113
|
+
expect(instance.showToolbar).toBeFalsy();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should verify if showDivider3 is visibility', () => {
|
|
117
|
+
const grid = setupInstance({
|
|
118
|
+
name: 'Grid',
|
|
119
|
+
component: 'TekGrid',
|
|
120
|
+
addButton: false,
|
|
121
|
+
deleteButton: 'none',
|
|
122
|
+
filterButton: false,
|
|
123
|
+
columnsButton: false,
|
|
124
|
+
showReload: false,
|
|
125
|
+
showLayoutOptions: false,
|
|
126
|
+
showReloadButton: true,
|
|
127
|
+
showSearch: false,
|
|
128
|
+
showExport: false,
|
|
129
|
+
actions: [],
|
|
130
|
+
});
|
|
131
|
+
const instance = new TekGridController(grid);
|
|
132
|
+
|
|
133
|
+
expect(instance.showDivider3).toBeFalsy();
|
|
134
|
+
expect(instance.showActionsButton).toBeFalsy();
|
|
135
|
+
expect(instance.showExportButton).toBeFalsy();
|
|
136
|
+
expect(instance.showSearchInput).toBeFalsy();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should verify if showActionAndExportButton is visibility', () => {
|
|
140
|
+
const grid = setupInstance({
|
|
141
|
+
name: 'Grid',
|
|
142
|
+
component: 'TekGrid',
|
|
143
|
+
addButton: false,
|
|
144
|
+
deleteButton: 'none',
|
|
145
|
+
filterButton: false,
|
|
146
|
+
columnsButton: true,
|
|
147
|
+
showReload: false,
|
|
148
|
+
showLayoutOptions: true,
|
|
149
|
+
showReloadButton: true,
|
|
150
|
+
showSearch: false,
|
|
151
|
+
showExport: false,
|
|
152
|
+
actions: [],
|
|
153
|
+
});
|
|
154
|
+
const instance = new TekGridController(grid);
|
|
155
|
+
|
|
156
|
+
expect(instance.showActionAndExportButton).toBeFalsy();
|
|
157
|
+
expect(instance.showActionsButton).toBeFalsy();
|
|
158
|
+
expect(instance.showSearchInput).toBeFalsy();
|
|
159
|
+
expect(instance.showExportButton).toBeFalsy();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should verify if showDivider2 is visibility', () => {
|
|
163
|
+
const grid = setupInstance({
|
|
164
|
+
name: 'Grid',
|
|
165
|
+
component: 'TekGrid',
|
|
166
|
+
addButton: false,
|
|
167
|
+
deleteButton: 'none',
|
|
168
|
+
filterButton: false,
|
|
169
|
+
columnsButton: false,
|
|
170
|
+
showReload: true,
|
|
171
|
+
showLayoutOptions: false,
|
|
172
|
+
showSearch: false,
|
|
173
|
+
showExport: false,
|
|
174
|
+
actions: [],
|
|
175
|
+
});
|
|
176
|
+
const instance = new TekGridController(grid);
|
|
177
|
+
|
|
178
|
+
expect(instance.showDivider2).toBeFalsy();
|
|
179
|
+
expect(instance.showActionsButton).toBeFalsy();
|
|
180
|
+
expect(instance.showSearchInput).toBeFalsy();
|
|
181
|
+
expect(instance.showColumnsButton).toBeFalsy();
|
|
182
|
+
expect(instance.showExportButton).toBeFalsy();
|
|
183
|
+
expect(instance.showReloadButton).toBeTruthy();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should verify if showDivider1 is visibility', () => {
|
|
187
|
+
const grid = setupInstance({
|
|
188
|
+
name: 'Grid',
|
|
189
|
+
component: 'TekGrid',
|
|
190
|
+
addButton: true,
|
|
191
|
+
deleteButton: 'selection',
|
|
192
|
+
filterButton: false,
|
|
193
|
+
columnsButton: false,
|
|
194
|
+
showReload: false,
|
|
195
|
+
showLayoutOptions: false,
|
|
196
|
+
showSearch: false,
|
|
197
|
+
showExport: false,
|
|
198
|
+
actions: [],
|
|
199
|
+
});
|
|
200
|
+
const instance = new TekGridController(grid);
|
|
201
|
+
|
|
202
|
+
expect(instance.showDivider1).toBeFalsy();
|
|
203
|
+
expect(instance.showActionsButton).toBeFalsy();
|
|
204
|
+
expect(instance.showSearchInput).toBeFalsy();
|
|
205
|
+
expect(instance.showColumnsButton).toBeFalsy();
|
|
206
|
+
expect(instance.showExportButton).toBeFalsy();
|
|
207
|
+
expect(instance.showReloadButton).toBeFalsy();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('disableDeleteButton', () => {
|
|
212
|
+
it('should return true when using selectAllPages and nothing is selected with except equal to 0', () => {
|
|
213
|
+
const grid = {
|
|
214
|
+
selectAllPages: true,
|
|
215
|
+
deleteButton: 'selection',
|
|
216
|
+
selectionState: { allSelected: false, except: [] },
|
|
217
|
+
datasource: {
|
|
218
|
+
total: 1,
|
|
219
|
+
},
|
|
220
|
+
} as any as TekGrid;
|
|
221
|
+
|
|
222
|
+
const controller = new TekGridController(grid);
|
|
223
|
+
|
|
224
|
+
expect(controller.disableDeleteButton).toBeTruthy();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('should return true when using selectAllPages and nothing is selected', () => {
|
|
228
|
+
const data = [{ id: '1' }];
|
|
229
|
+
const grid = {
|
|
230
|
+
selectAllPages: true,
|
|
231
|
+
deleteButton: 'selection',
|
|
232
|
+
selectionState: { allSelected: true, except: data },
|
|
233
|
+
datasource: {
|
|
234
|
+
total: 1,
|
|
235
|
+
},
|
|
236
|
+
} as any as TekGrid;
|
|
237
|
+
|
|
238
|
+
const controller = new TekGridController(grid);
|
|
239
|
+
|
|
240
|
+
expect(controller.disableDeleteButton).toBeTruthy();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should return false when deleteButton mode is none', () => {
|
|
244
|
+
const grid = {
|
|
245
|
+
deleteButton: 'none',
|
|
246
|
+
} as any as TekGrid;
|
|
247
|
+
|
|
248
|
+
const controller = new TekGridController(grid);
|
|
249
|
+
|
|
250
|
+
expect(controller.disableDeleteButton).toBeFalsy();
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { ITekGrid, ITekGridSummary, TekGridColumn, TekGridEvents } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('TekGridEvents', () => {
|
|
4
|
+
let tekGridEvents: TekGridEvents;
|
|
5
|
+
let mockTekGrid: jest.Mocked<ITekGrid>;
|
|
6
|
+
const mockEvent = {} as Event;
|
|
7
|
+
const mockElement = {} as HTMLElement;
|
|
8
|
+
const mockRow = { id: 1, name: 'Test Row' };
|
|
9
|
+
const mockGroupRow = { group: true, groupValue: 'Test Group' };
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
mockTekGrid = {
|
|
13
|
+
datasource: { currentRow: null },
|
|
14
|
+
callEvent: jest.fn(),
|
|
15
|
+
} as unknown as jest.Mocked<ITekGrid>;
|
|
16
|
+
|
|
17
|
+
tekGridEvents = new TekGridEvents(mockTekGrid);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('constructor', () => {
|
|
21
|
+
it('should initialize with the provided tekGrid', () => {
|
|
22
|
+
expect(tekGridEvents).toBeInstanceOf(TekGridEvents);
|
|
23
|
+
// @ts-ignore - access protected property for testing
|
|
24
|
+
expect(tekGridEvents.tekGrid).toBe(mockTekGrid);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('calcSummary', () => {
|
|
29
|
+
it('should call calcSummary event with correct parameters', () => {
|
|
30
|
+
const mockColumn = { name: 'testColumn' } as TekGridColumn;
|
|
31
|
+
const mockSummary: ITekGridSummary = { sum: 0, count: 0, avg: 0, min: 0, max: 0 };
|
|
32
|
+
const mockRowWithValue = { testColumn: 100 };
|
|
33
|
+
|
|
34
|
+
tekGridEvents.calcSummary(mockColumn, mockSummary, mockRowWithValue);
|
|
35
|
+
|
|
36
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('calcSummary', {
|
|
37
|
+
component: mockTekGrid,
|
|
38
|
+
column: mockColumn,
|
|
39
|
+
columnName: 'testColumn',
|
|
40
|
+
summary: mockSummary,
|
|
41
|
+
row: mockRowWithValue,
|
|
42
|
+
rowValue: 100,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('rowDoubleClick', () => {
|
|
48
|
+
it('should set currentRow and dispatch event when not prevented', () => {
|
|
49
|
+
tekGridEvents.rowDoubleClick(mockRow, mockEvent, mockElement);
|
|
50
|
+
|
|
51
|
+
expect(mockTekGrid.datasource.currentRow).toBe(mockRow);
|
|
52
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('rowDoubleClick', {
|
|
53
|
+
event: mockEvent,
|
|
54
|
+
element: mockElement,
|
|
55
|
+
row: mockRow,
|
|
56
|
+
component: mockTekGrid,
|
|
57
|
+
column: undefined,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should not dispatch event when prevented', () => {
|
|
62
|
+
// @ts-ignore - access protected property for testing
|
|
63
|
+
tekGridEvents.preventRowDoubleClick = true;
|
|
64
|
+
tekGridEvents.rowDoubleClick(mockRow, mockEvent, mockElement);
|
|
65
|
+
|
|
66
|
+
expect(mockTekGrid.callEvent).not.toHaveBeenCalled();
|
|
67
|
+
// Should still reset the flag
|
|
68
|
+
// @ts-ignore - access protected property for testing
|
|
69
|
+
expect(tekGridEvents.preventRowDoubleClick).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('groupRowClick', () => {
|
|
74
|
+
it('should dispatch groupRowClick event when not prevented', () => {
|
|
75
|
+
tekGridEvents.groupRowClick(mockGroupRow, mockEvent, mockElement);
|
|
76
|
+
|
|
77
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('groupRowClick', {
|
|
78
|
+
event: mockEvent,
|
|
79
|
+
element: mockElement,
|
|
80
|
+
row: mockGroupRow,
|
|
81
|
+
component: mockTekGrid,
|
|
82
|
+
column: undefined,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should not dispatch event when prevented', () => {
|
|
87
|
+
// @ts-ignore - access protected property for testing
|
|
88
|
+
tekGridEvents.preventRowClick = true;
|
|
89
|
+
tekGridEvents.groupRowClick(mockGroupRow, mockEvent, mockElement);
|
|
90
|
+
|
|
91
|
+
expect(mockTekGrid.callEvent).not.toHaveBeenCalled();
|
|
92
|
+
// Should still reset the flag
|
|
93
|
+
// @ts-ignore - access protected property for testing
|
|
94
|
+
expect(tekGridEvents.preventRowClick).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('groupRowDoubleClick', () => {
|
|
99
|
+
it('should dispatch groupRowDoubleClick event when not prevented', () => {
|
|
100
|
+
tekGridEvents.groupRowDoubleClick(mockGroupRow, mockEvent, mockElement);
|
|
101
|
+
|
|
102
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('groupRowDoubleClick', {
|
|
103
|
+
event: mockEvent,
|
|
104
|
+
element: mockElement,
|
|
105
|
+
row: mockGroupRow,
|
|
106
|
+
component: mockTekGrid,
|
|
107
|
+
column: undefined,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should not dispatch event when prevented', () => {
|
|
112
|
+
// @ts-ignore - access protected property for testing
|
|
113
|
+
tekGridEvents.preventRowDoubleClick = true;
|
|
114
|
+
tekGridEvents.groupRowDoubleClick(mockGroupRow, mockEvent, mockElement);
|
|
115
|
+
|
|
116
|
+
expect(mockTekGrid.callEvent).not.toHaveBeenCalled();
|
|
117
|
+
// Should still reset the flag
|
|
118
|
+
// @ts-ignore - access protected property for testing
|
|
119
|
+
expect(tekGridEvents.preventRowDoubleClick).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('selectGroupClick', () => {
|
|
124
|
+
it('should dispatch groupSelected event when isSelected is true', () => {
|
|
125
|
+
tekGridEvents.selectGroupClick(mockGroupRow, true, mockEvent, mockElement);
|
|
126
|
+
|
|
127
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('groupSelected', {
|
|
128
|
+
event: mockEvent,
|
|
129
|
+
element: mockElement,
|
|
130
|
+
row: mockGroupRow,
|
|
131
|
+
component: mockTekGrid,
|
|
132
|
+
column: undefined,
|
|
133
|
+
});
|
|
134
|
+
expect(mockTekGrid.callEvent).not.toHaveBeenCalledWith('groupUnselected', expect.anything());
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should dispatch groupUnselected event when isSelected is false', () => {
|
|
138
|
+
tekGridEvents.selectGroupClick(mockGroupRow, false, mockEvent, mockElement);
|
|
139
|
+
|
|
140
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('groupUnselected', {
|
|
141
|
+
event: mockEvent,
|
|
142
|
+
element: mockElement,
|
|
143
|
+
row: mockGroupRow,
|
|
144
|
+
component: mockTekGrid,
|
|
145
|
+
column: undefined,
|
|
146
|
+
});
|
|
147
|
+
expect(mockTekGrid.callEvent).not.toHaveBeenCalledWith('groupSelected', expect.anything());
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should pass through all parameters correctly', () => {
|
|
151
|
+
const customEvent = { type: 'click' } as Event;
|
|
152
|
+
const customElement = { tagName: 'DIV' } as HTMLElement;
|
|
153
|
+
const customRow = { group: true, groupValue: 'Custom Group' };
|
|
154
|
+
|
|
155
|
+
tekGridEvents.selectGroupClick(customRow, true, customEvent, customElement);
|
|
156
|
+
|
|
157
|
+
expect(mockTekGrid.callEvent).toHaveBeenCalledWith('groupSelected', {
|
|
158
|
+
event: customEvent,
|
|
159
|
+
element: customElement,
|
|
160
|
+
row: customRow,
|
|
161
|
+
component: mockTekGrid,
|
|
162
|
+
column: undefined,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('prevention flags', () => {
|
|
168
|
+
it('should properly reset prevention flags after operations', () => {
|
|
169
|
+
// Set flags to true
|
|
170
|
+
// @ts-ignore - access protected properties for testing
|
|
171
|
+
tekGridEvents.preventRowClick = true;
|
|
172
|
+
// @ts-ignore - access protected properties for testing
|
|
173
|
+
tekGridEvents.preventRowDoubleClick = true;
|
|
174
|
+
|
|
175
|
+
// Trigger events that should reset them
|
|
176
|
+
tekGridEvents.groupRowClick(mockGroupRow, mockEvent, mockElement);
|
|
177
|
+
tekGridEvents.rowDoubleClick(mockRow, mockEvent, mockElement);
|
|
178
|
+
|
|
179
|
+
// Verify flags were reset
|
|
180
|
+
// @ts-ignore - access protected properties for testing
|
|
181
|
+
expect(tekGridEvents.preventRowClick).toBe(false);
|
|
182
|
+
// @ts-ignore - access protected properties for testing
|
|
183
|
+
expect(tekGridEvents.preventRowDoubleClick).toBe(false);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Metadata } from '@zeedhi/core';
|
|
2
|
+
import { TekGridToolbarProvider } from '../../../../src';
|
|
3
|
+
|
|
4
|
+
describe('TekGridColumnsButton', () => {
|
|
5
|
+
describe('getAtomInstance()', () => {
|
|
6
|
+
it('when called, should call Metadata.getInstance passing the name of the atom', () => {
|
|
7
|
+
const mockGrid = { name: 'name' } as any;
|
|
8
|
+
const toolbarProvider = new TekGridToolbarProvider(mockGrid, 'show');
|
|
9
|
+
const spy = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => {});
|
|
10
|
+
toolbarProvider.getAtomInstance('TITLE');
|
|
11
|
+
expect(spy).toHaveBeenCalledWith('name_gridTitle');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('reloadGrid()', () => {
|
|
16
|
+
it('when called, should call grid.reload', () => {
|
|
17
|
+
const mockGrid = { reload: jest.fn(), callEvent: jest.fn() } as any;
|
|
18
|
+
const toolbarProvider = new TekGridToolbarProvider(mockGrid, 'show');
|
|
19
|
+
toolbarProvider.reloadGrid({ event: { defaultPrevented: false } } as any);
|
|
20
|
+
|
|
21
|
+
expect(mockGrid.callEvent).toHaveBeenCalled();
|
|
22
|
+
expect(mockGrid.reload).toHaveBeenCalled();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('when called with defaultPrevented, should not call grid.reload', () => {
|
|
26
|
+
const mockGrid = { reload: jest.fn(), callEvent: jest.fn() } as any;
|
|
27
|
+
const toolbarProvider = new TekGridToolbarProvider(mockGrid, 'show');
|
|
28
|
+
toolbarProvider.reloadGrid({ event: { defaultPrevented: true } } as any);
|
|
29
|
+
|
|
30
|
+
expect(mockGrid.callEvent).toHaveBeenCalled();
|
|
31
|
+
expect(mockGrid.reload).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|