@zeedhi/teknisa-components-common 1.129.0 → 1.131.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.package.json +39 -0
- package/coverage/clover.xml +1204 -1142
- package/coverage/coverage-final.json +48 -47
- package/coverage/lcov-report/index.html +18 -18
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +3 -3
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +11 -11
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +4 -4
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +3 -3
- package/coverage/lcov.info +2082 -1961
- package/dist/tek-components-common.esm.js +278 -163
- package/dist/tek-components-common.umd.js +278 -162
- package/package.json +2 -2
- package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +123 -2
- package/tests/unit/components/tek-grid/grid-export-button.spec.ts +403 -0
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +147 -4
- package/tests/unit/components/tek-grid/grid.spec.ts +142 -9
- package/tests/unit/components/tek-grid/layout_options.spec.ts +166 -0
- package/types/components/index.d.ts +1 -0
- package/types/components/tek-ag-grid/default-icons.d.ts +53 -0
- package/types/components/tek-ag-grid/interfaces.d.ts +9 -0
- package/types/components/tek-ag-grid/tek-ag-grid.d.ts +35 -0
- package/types/components/tek-datasource/datasource.d.ts +94 -0
- package/types/components/tek-grid/default-icons.d.ts +53 -0
- package/types/components/tek-grid/filter-dynamic-values.d.ts +9 -0
- package/types/components/tek-grid/grid-columns-button.d.ts +2 -1
- package/types/components/tek-grid/grid-controller.d.ts +19 -0
- package/types/components/tek-grid/grid-export-button.d.ts +19 -0
- package/types/components/tek-grid/grid-filter-button.d.ts +1 -0
- package/types/components/tek-grid/grid.d.ts +4 -0
- package/types/components/tek-grid/grid_column.d.ts +14 -0
- package/types/components/tek-grid/grid_controller.d.ts +15 -0
- package/types/components/tek-grid/interfaces.d.ts +8 -0
- package/types/components/tek-grid/layout-options.d.ts +6 -0
- package/types/components/tek-grid/tek-grid.d.ts +35 -0
- package/types/components/tek-login/interfaces.d.ts +3 -0
- package/types/components/tek-login/login-children.d.ts +3 -0
- package/types/components/tek-login/login.d.ts +58 -0
- package/types/components/tek-login/login_children.d.ts +3 -0
- package/types/components/tek-tree-grid/tree-grid.d.ts +2 -0
- package/types/utils/grid-base/export-options/button-option.d.ts +3 -1
- package/types/utils/grid-base/export-options/multi-option.d.ts +3 -1
- package/types/utils/grid-base/grid-base.d.ts +1 -3
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { Checkbox, Iterable } from '@zeedhi/common';
|
|
2
|
-
import { I18n } from '@zeedhi/core';
|
|
1
|
+
import { Checkbox, Iterable, IterableColumnsButton } from '@zeedhi/common';
|
|
2
|
+
import { I18n, Metadata } from '@zeedhi/core';
|
|
3
3
|
import { TekGrid, TekGridColumnsButton } from '../../../../src';
|
|
4
4
|
import { TekGridColumnsButtonController } from '../../../../src/components/tek-grid/grid-columns-button-controller';
|
|
5
5
|
|
|
6
6
|
describe('TekGridColumnsButton', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
const { instances } = Metadata as any;
|
|
9
|
+
Object.keys(instances).forEach((key) => {
|
|
10
|
+
const instance = instances[key];
|
|
11
|
+
if (Array.isArray(instance)) {
|
|
12
|
+
instance.forEach((item) => Metadata.clearInstance(key, item.componentId));
|
|
13
|
+
} else {
|
|
14
|
+
Metadata.clearInstance(key, instance.componentId);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
7
19
|
describe('getAggregationSelectData', () => {
|
|
8
20
|
it('should get aggregation data', () => {
|
|
9
21
|
let I18Called = false;
|
|
@@ -39,7 +51,114 @@ describe('TekGridColumnsButton', () => {
|
|
|
39
51
|
});
|
|
40
52
|
|
|
41
53
|
describe('controller', () => {
|
|
54
|
+
it('should create without grid and resolve it by gridName after the grid is created', () => {
|
|
55
|
+
const instance = new TekGridColumnsButton({
|
|
56
|
+
name: 'external-columns-button-by-grid-name',
|
|
57
|
+
component: 'TekGridColumnsButton',
|
|
58
|
+
gridName: 'grid-created-after-columns-button-by-grid-name',
|
|
59
|
+
});
|
|
60
|
+
instance.onCreated();
|
|
61
|
+
|
|
62
|
+
expect(instance.iterableComponent).toBeUndefined();
|
|
63
|
+
expect(instance.filteredColumns()).toEqual([]);
|
|
64
|
+
expect(instance.controller).toBeUndefined();
|
|
65
|
+
expect(instance.iterableComponentName).toBe('grid-created-after-columns-button-by-grid-name');
|
|
66
|
+
|
|
67
|
+
const grid = new TekGrid({
|
|
68
|
+
name: 'grid-created-after-columns-button-by-grid-name',
|
|
69
|
+
component: 'TekGrid',
|
|
70
|
+
columnsButton: false,
|
|
71
|
+
columns: [
|
|
72
|
+
{ name: 'id' },
|
|
73
|
+
{ name: 'name' },
|
|
74
|
+
{ name: 'salary' },
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
grid.onCreated();
|
|
78
|
+
|
|
79
|
+
expect(instance.filteredColumns().map((column) => column.name)).toEqual(['id', 'name', 'salary']);
|
|
80
|
+
expect(instance.iterableComponent).toBe(grid);
|
|
81
|
+
expect(instance.iterableComponentName).toBe(grid.name);
|
|
82
|
+
expect(instance.controller).toBeInstanceOf(TekGridColumnsButtonController);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should create without grid and resolve it after the grid is created', () => {
|
|
86
|
+
const instance = new TekGridColumnsButton({
|
|
87
|
+
name: 'external-columns-button',
|
|
88
|
+
component: 'TekGridColumnsButton',
|
|
89
|
+
iterableComponentName: 'grid-created-after-columns-button',
|
|
90
|
+
});
|
|
91
|
+
instance.onCreated();
|
|
92
|
+
|
|
93
|
+
expect(instance.iterableComponent).toBeUndefined();
|
|
94
|
+
expect(instance.filteredColumns()).toEqual([]);
|
|
95
|
+
expect(instance.controller).toBeUndefined();
|
|
96
|
+
|
|
97
|
+
const grid = new TekGrid({
|
|
98
|
+
name: 'grid-created-after-columns-button',
|
|
99
|
+
component: 'TekGrid',
|
|
100
|
+
columnsButton: false,
|
|
101
|
+
columns: [
|
|
102
|
+
{ name: 'id' },
|
|
103
|
+
{ name: 'name' },
|
|
104
|
+
{ name: 'salary' },
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
grid.onCreated();
|
|
108
|
+
|
|
109
|
+
expect(instance.filteredColumns().map((column) => column.name)).toEqual(['id', 'name', 'salary']);
|
|
110
|
+
expect(instance.iterableComponent).toBe(grid);
|
|
111
|
+
expect(instance.iterableComponentName).toBe(grid.name);
|
|
112
|
+
expect(instance.controller).toBeInstanceOf(TekGridColumnsButtonController);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should prefer gridName when both gridName and iterableComponentName are provided', () => {
|
|
116
|
+
const grid = new TekGrid({
|
|
117
|
+
name: 'columns-button-grid-name-wins',
|
|
118
|
+
component: 'TekGrid',
|
|
119
|
+
columnsButton: false,
|
|
120
|
+
columns: [
|
|
121
|
+
{ name: 'id' },
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
grid.onCreated();
|
|
125
|
+
const ignoredGrid = new TekGrid({
|
|
126
|
+
name: 'columns-button-iterable-name-loses',
|
|
127
|
+
component: 'TekGrid',
|
|
128
|
+
columnsButton: false,
|
|
129
|
+
columns: [
|
|
130
|
+
{ name: 'ignored' },
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
ignoredGrid.onCreated();
|
|
134
|
+
|
|
135
|
+
const instance = new TekGridColumnsButton({
|
|
136
|
+
name: 'external-columns-button-conflict',
|
|
137
|
+
component: 'TekGridColumnsButton',
|
|
138
|
+
gridName: 'columns-button-grid-name-wins',
|
|
139
|
+
iterableComponentName: 'columns-button-iterable-name-loses',
|
|
140
|
+
});
|
|
141
|
+
instance.onCreated();
|
|
142
|
+
|
|
143
|
+
expect(instance.iterableComponent).toBe(grid);
|
|
144
|
+
expect(instance.iterableComponentName).toBe(grid.name);
|
|
145
|
+
expect(instance.filteredColumns().map((column) => column.name)).toEqual(['id']);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should return empty columns while grid is unresolved', () => {
|
|
149
|
+
const instance = new TekGridColumnsButton({
|
|
150
|
+
name: 'external-columns-button-without-grid',
|
|
151
|
+
component: 'TekGridColumnsButton',
|
|
152
|
+
iterableComponentName: 'missing-grid',
|
|
153
|
+
});
|
|
154
|
+
instance.onCreated();
|
|
155
|
+
|
|
156
|
+
expect(instance.filteredColumns()).toEqual([]);
|
|
157
|
+
expect(instance.controller).toBeUndefined();
|
|
158
|
+
});
|
|
159
|
+
|
|
42
160
|
it('should create component controller', () => {
|
|
161
|
+
const baseControllerSpy = jest.spyOn(IterableColumnsButton.prototype, 'createController');
|
|
43
162
|
const checkbox = new Checkbox({
|
|
44
163
|
name: 'checkbox',
|
|
45
164
|
component: 'ZdCheckbox',
|
|
@@ -66,6 +185,7 @@ describe('TekGridColumnsButton', () => {
|
|
|
66
185
|
parent: grid,
|
|
67
186
|
});
|
|
68
187
|
instance.onCreated();
|
|
188
|
+
expect(baseControllerSpy).not.toBeCalled();
|
|
69
189
|
expect(instance.controller).toBeInstanceOf(TekGridColumnsButtonController);
|
|
70
190
|
expect(iterable.columns[0].isVisible).toBeTruthy();
|
|
71
191
|
instance.controller.showHideTekColumn(iterable.columns[0], { component: checkbox });
|
|
@@ -75,6 +195,7 @@ describe('TekGridColumnsButton', () => {
|
|
|
75
195
|
iterable.columns[0].isVisible = false;
|
|
76
196
|
instance.controller.showHideTekColumn(iterable.columns[0], { component: checkbox });
|
|
77
197
|
expect(iterable.columns[0].isVisible).toBeFalsy();
|
|
198
|
+
baseControllerSpy.mockRestore();
|
|
78
199
|
});
|
|
79
200
|
|
|
80
201
|
it('changeGroupedColumn', () => {
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Button, IButton } from '@zeedhi/common';
|
|
2
|
+
import { Metadata } from '@zeedhi/core';
|
|
3
|
+
import {
|
|
4
|
+
TekGrid, TekGridExportButton,
|
|
5
|
+
} from '../../../../src';
|
|
6
|
+
import { getChild } from '../../../__helpers__';
|
|
7
|
+
|
|
8
|
+
describe('TekGridExportButton', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
const { instances } = Metadata as any;
|
|
11
|
+
Object.keys(instances).forEach((key) => {
|
|
12
|
+
const instance = instances[key];
|
|
13
|
+
if (Array.isArray(instance)) {
|
|
14
|
+
instance.forEach((item) => Metadata.clearInstance(key, item.componentId));
|
|
15
|
+
} else {
|
|
16
|
+
Metadata.clearInstance(key, instance.componentId);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('loadGrid()', () => {
|
|
22
|
+
it('should load grid by gridName', () => {
|
|
23
|
+
const grid = new TekGrid({
|
|
24
|
+
name: 'grid-1',
|
|
25
|
+
component: 'TekGrid',
|
|
26
|
+
});
|
|
27
|
+
grid.onCreated();
|
|
28
|
+
|
|
29
|
+
const exportButton = new TekGridExportButton({
|
|
30
|
+
name: 'external-export',
|
|
31
|
+
component: 'TekGridExportButton',
|
|
32
|
+
gridName: 'grid-1',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(exportButton.grid).toEqual(grid);
|
|
36
|
+
expect(exportButton.gridName).toBe('grid-1');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should load grid by gridName after the export button is created', () => {
|
|
40
|
+
const exportButton = new TekGridExportButton({
|
|
41
|
+
name: 'external-export',
|
|
42
|
+
component: 'TekGridExportButton',
|
|
43
|
+
gridName: 'grid-created-after-export-button',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(exportButton.grid).toBeUndefined();
|
|
47
|
+
|
|
48
|
+
const grid = new TekGrid({
|
|
49
|
+
name: 'grid-created-after-export-button',
|
|
50
|
+
component: 'TekGrid',
|
|
51
|
+
});
|
|
52
|
+
grid.onCreated();
|
|
53
|
+
|
|
54
|
+
exportButton.loadGrid();
|
|
55
|
+
|
|
56
|
+
expect(exportButton.grid).toEqual(grid);
|
|
57
|
+
expect(exportButton.children).toHaveLength(grid.exportConfig.length);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should load grid by gridName argument', () => {
|
|
61
|
+
const grid = new TekGrid({
|
|
62
|
+
name: 'grid-loaded-by-argument',
|
|
63
|
+
component: 'TekGrid',
|
|
64
|
+
});
|
|
65
|
+
grid.onCreated();
|
|
66
|
+
|
|
67
|
+
const exportButton = new TekGridExportButton({
|
|
68
|
+
name: 'external-export',
|
|
69
|
+
component: 'TekGridExportButton',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
exportButton.loadGrid('grid-loaded-by-argument');
|
|
73
|
+
|
|
74
|
+
expect(exportButton.grid).toBe(grid);
|
|
75
|
+
expect(exportButton.gridName).toBe(grid.name);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('onCreated()', () => {
|
|
80
|
+
it('should load the grid when the component is created', () => {
|
|
81
|
+
const exportButton = new TekGridExportButton({
|
|
82
|
+
name: 'external-export',
|
|
83
|
+
component: 'TekGridExportButton',
|
|
84
|
+
});
|
|
85
|
+
const loadGrid = jest.spyOn(exportButton, 'loadGrid');
|
|
86
|
+
|
|
87
|
+
exportButton.onCreated();
|
|
88
|
+
|
|
89
|
+
expect(loadGrid).toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('children', () => {
|
|
94
|
+
it('should return no export config buttons without a grid', () => {
|
|
95
|
+
const exportButton = new TekGridExportButton({
|
|
96
|
+
name: 'external-export',
|
|
97
|
+
component: 'TekGridExportButton',
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect((exportButton as any).getExportConfigButtons()).toEqual([]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should not load children without a grid', () => {
|
|
104
|
+
const exportButton = new TekGridExportButton({
|
|
105
|
+
name: 'external-export',
|
|
106
|
+
component: 'TekGridExportButton',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
(exportButton as any).loadChildren();
|
|
110
|
+
|
|
111
|
+
expect(exportButton.children).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should use grid exportActions when present', () => {
|
|
115
|
+
const exportActions = [
|
|
116
|
+
{
|
|
117
|
+
name: 'custom-export-action',
|
|
118
|
+
component: 'ZdButton',
|
|
119
|
+
label: 'Custom export',
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
const grid = new TekGrid({
|
|
123
|
+
name: 'grid-with-export-actions',
|
|
124
|
+
component: 'TekGrid',
|
|
125
|
+
exportActions,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const exportButton = new TekGridExportButton({
|
|
129
|
+
name: 'external-export',
|
|
130
|
+
component: 'TekGridExportButton',
|
|
131
|
+
grid,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(exportButton.children).toBe(exportActions);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should use component exportActions when present', () => {
|
|
138
|
+
const exportActions = [
|
|
139
|
+
{
|
|
140
|
+
name: 'button-export-action',
|
|
141
|
+
component: 'ZdButton',
|
|
142
|
+
label: 'Button export',
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
const grid = new TekGrid({
|
|
146
|
+
name: 'grid-with-button-export-actions',
|
|
147
|
+
component: 'TekGrid',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const exportButton = new TekGridExportButton({
|
|
151
|
+
name: 'external-export',
|
|
152
|
+
component: 'TekGridExportButton',
|
|
153
|
+
grid,
|
|
154
|
+
exportActions,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(exportButton.children).toBe(exportActions);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('component exportActions should override component exportConfig and grid exportActions', () => {
|
|
161
|
+
const gridExportActions = [
|
|
162
|
+
{
|
|
163
|
+
name: 'grid-export-action',
|
|
164
|
+
component: 'ZdButton',
|
|
165
|
+
label: 'Grid export',
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
const buttonExportActions = [
|
|
169
|
+
{
|
|
170
|
+
name: 'button-export-action',
|
|
171
|
+
component: 'ZdButton',
|
|
172
|
+
label: 'Button export',
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
const grid = new TekGrid({
|
|
176
|
+
name: 'grid-with-all-export-overrides',
|
|
177
|
+
component: 'TekGrid',
|
|
178
|
+
exportActions: gridExportActions,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const exportButton = new TekGridExportButton({
|
|
182
|
+
name: 'external-export',
|
|
183
|
+
component: 'TekGridExportButton',
|
|
184
|
+
grid,
|
|
185
|
+
exportActions: buttonExportActions,
|
|
186
|
+
exportConfig: [
|
|
187
|
+
{
|
|
188
|
+
type: 'csv',
|
|
189
|
+
label: 'Button CSV',
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(exportButton.children).toBe(buttonExportActions);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('should build export buttons from grid exportConfig', () => {
|
|
198
|
+
const grid = new TekGrid({
|
|
199
|
+
name: 'grid-with-export-config',
|
|
200
|
+
component: 'TekGrid',
|
|
201
|
+
exportConfig: [
|
|
202
|
+
{
|
|
203
|
+
type: 'pdf',
|
|
204
|
+
label: 'Export PDF',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const exportButton = new TekGridExportButton({
|
|
210
|
+
name: 'external-export',
|
|
211
|
+
component: 'TekGridExportButton',
|
|
212
|
+
grid,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(exportButton.children).toHaveLength(1);
|
|
216
|
+
expect(exportButton.children![0]).toEqual(expect.objectContaining({
|
|
217
|
+
name: 'grid-with-export-config_export_pdf_portrait',
|
|
218
|
+
component: 'ZdButton',
|
|
219
|
+
label: 'Export PDF',
|
|
220
|
+
}));
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should build export buttons from component exportConfig', () => {
|
|
224
|
+
const grid = new TekGrid({
|
|
225
|
+
name: 'grid-with-button-export-config',
|
|
226
|
+
component: 'TekGrid',
|
|
227
|
+
exportConfig: [
|
|
228
|
+
{
|
|
229
|
+
type: 'pdf',
|
|
230
|
+
label: 'Grid PDF',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const exportButton = new TekGridExportButton({
|
|
236
|
+
name: 'external-export',
|
|
237
|
+
component: 'TekGridExportButton',
|
|
238
|
+
grid,
|
|
239
|
+
exportConfig: [
|
|
240
|
+
{
|
|
241
|
+
type: 'csv',
|
|
242
|
+
label: 'Button CSV',
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(exportButton.children).toHaveLength(1);
|
|
248
|
+
expect(exportButton.children![0]).toEqual(expect.objectContaining({
|
|
249
|
+
name: 'grid-with-button-export-config_export_csv_portrait',
|
|
250
|
+
component: 'ZdButton',
|
|
251
|
+
label: 'Button CSV',
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('component exportConfig should override grid exportActions', () => {
|
|
256
|
+
const exportActions = [
|
|
257
|
+
{
|
|
258
|
+
name: 'custom-export-action',
|
|
259
|
+
component: 'ZdButton',
|
|
260
|
+
label: 'Custom export',
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
const grid = new TekGrid({
|
|
264
|
+
name: 'grid-with-export-actions-and-button-config',
|
|
265
|
+
component: 'TekGrid',
|
|
266
|
+
exportActions,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const exportButton = new TekGridExportButton({
|
|
270
|
+
name: 'external-export',
|
|
271
|
+
component: 'TekGridExportButton',
|
|
272
|
+
grid,
|
|
273
|
+
exportConfig: [
|
|
274
|
+
{
|
|
275
|
+
type: 'xls',
|
|
276
|
+
label: 'Button XLS',
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(exportButton.children).not.toBe(exportActions);
|
|
282
|
+
expect(exportButton.children).toHaveLength(1);
|
|
283
|
+
expect(exportButton.children![0]).toEqual(expect.objectContaining({
|
|
284
|
+
name: 'grid-with-export-actions-and-button-config_export_xls_portrait',
|
|
285
|
+
label: 'Button XLS',
|
|
286
|
+
}));
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should use component exportConfig after grid is created later', () => {
|
|
290
|
+
const exportButton = new TekGridExportButton({
|
|
291
|
+
name: 'external-export',
|
|
292
|
+
component: 'TekGridExportButton',
|
|
293
|
+
gridName: 'grid-created-after-button-with-config',
|
|
294
|
+
exportConfig: [
|
|
295
|
+
{
|
|
296
|
+
type: 'csv',
|
|
297
|
+
label: 'Button CSV',
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
expect(exportButton.grid).toBeUndefined();
|
|
303
|
+
expect(exportButton.children).toHaveLength(0);
|
|
304
|
+
|
|
305
|
+
const grid = new TekGrid({
|
|
306
|
+
name: 'grid-created-after-button-with-config',
|
|
307
|
+
component: 'TekGrid',
|
|
308
|
+
});
|
|
309
|
+
grid.onCreated();
|
|
310
|
+
|
|
311
|
+
exportButton.loadGrid();
|
|
312
|
+
|
|
313
|
+
expect(exportButton.grid).toEqual(grid);
|
|
314
|
+
expect(exportButton.children).toHaveLength(1);
|
|
315
|
+
expect(exportButton.children![0]).toEqual(expect.objectContaining({
|
|
316
|
+
name: 'grid-created-after-button-with-config_export_csv_portrait',
|
|
317
|
+
label: 'Button CSV',
|
|
318
|
+
}));
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should use component exportActions after grid is created later', () => {
|
|
322
|
+
const exportActions = [
|
|
323
|
+
{
|
|
324
|
+
name: 'delayed-button-export-action',
|
|
325
|
+
component: 'ZdButton',
|
|
326
|
+
label: 'Delayed button export',
|
|
327
|
+
},
|
|
328
|
+
];
|
|
329
|
+
const exportButton = new TekGridExportButton({
|
|
330
|
+
name: 'external-export',
|
|
331
|
+
component: 'TekGridExportButton',
|
|
332
|
+
gridName: 'grid-created-after-button-with-actions',
|
|
333
|
+
exportActions,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(exportButton.grid).toBeUndefined();
|
|
337
|
+
expect(exportButton.children).toHaveLength(0);
|
|
338
|
+
|
|
339
|
+
const grid = new TekGrid({
|
|
340
|
+
name: 'grid-created-after-button-with-actions',
|
|
341
|
+
component: 'TekGrid',
|
|
342
|
+
});
|
|
343
|
+
grid.onCreated();
|
|
344
|
+
|
|
345
|
+
exportButton.loadGrid();
|
|
346
|
+
|
|
347
|
+
expect(exportButton.grid).toEqual(grid);
|
|
348
|
+
expect(exportButton.children).toBe(exportActions);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('generated export action should call grid.getReport on click', () => {
|
|
352
|
+
const grid = new TekGrid({
|
|
353
|
+
name: 'grid-with-click-export',
|
|
354
|
+
component: 'TekGrid',
|
|
355
|
+
exportConfig: [
|
|
356
|
+
{
|
|
357
|
+
type: 'csv',
|
|
358
|
+
label: 'Export CSV',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
});
|
|
362
|
+
const getReportSpy = jest.fn();
|
|
363
|
+
grid.getReport = getReportSpy;
|
|
364
|
+
|
|
365
|
+
const exportButton = new TekGridExportButton({
|
|
366
|
+
name: 'external-export',
|
|
367
|
+
component: 'TekGridExportButton',
|
|
368
|
+
grid,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const button = new Button(exportButton.children![0] as IButton);
|
|
372
|
+
button.click();
|
|
373
|
+
|
|
374
|
+
expect(getReportSpy).toHaveBeenCalledWith('csv', true);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should be rendered by the default grid toolbar', () => {
|
|
378
|
+
const grid = new TekGrid({
|
|
379
|
+
name: 'grid-with-toolbar-export',
|
|
380
|
+
component: 'TekGrid',
|
|
381
|
+
});
|
|
382
|
+
grid.onCreated();
|
|
383
|
+
|
|
384
|
+
const toolbarExport = getChild<any>(grid.toolbarSlot, 'grid-with-toolbar-export_export_dropdown');
|
|
385
|
+
|
|
386
|
+
expect(toolbarExport).toEqual(expect.objectContaining({
|
|
387
|
+
name: 'grid-with-toolbar-export_export_dropdown',
|
|
388
|
+
component: 'TekGridExportButton',
|
|
389
|
+
gridName: 'grid-with-toolbar-export',
|
|
390
|
+
}));
|
|
391
|
+
expect(toolbarExport.activator).toBeUndefined();
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('should not create activator metadata when gridName is not provided', () => {
|
|
395
|
+
const exportButton = new TekGridExportButton({
|
|
396
|
+
name: 'standalone-export',
|
|
397
|
+
component: 'TekGridExportButton',
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
expect((exportButton as any).activator).toBeUndefined();
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
});
|