@zeedhi/teknisa-components-common 1.107.2 → 1.108.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/LICENSE +21 -21
- package/README.md +7 -7
- package/coverage/clover.xml +772 -692
- package/coverage/coverage-final.json +47 -47
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +7 -7
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
- package/coverage/lcov.info +1459 -1275
- package/dist/tek-components-common.esm.js +375 -252
- package/dist/tek-components-common.umd.js +375 -252
- package/jest.config.js +1 -1
- package/package.json +2 -2
- package/tests/__helpers__/component-event-helper.ts +5 -5
- package/tests/__helpers__/flush-promises-helper.ts +3 -3
- package/tests/__helpers__/get-child-helper.ts +27 -27
- package/tests/__helpers__/index.ts +3 -3
- package/tests/__helpers__/mock-created-helper.ts +12 -12
- package/tests/__mocks__/@zeedhi/core/i18n.js +74 -74
- package/tests/__mocks__/@zeedhi/core.js +4 -4
- package/tests/unit/components/crud/crud-add-button.spec.ts +56 -56
- package/tests/unit/components/crud/crud-button.spec.ts +94 -94
- package/tests/unit/components/crud/crud-cancel-button.spec.ts +91 -91
- package/tests/unit/components/crud/crud-delete-button.spec.ts +122 -122
- package/tests/unit/components/crud/crud-form.spec.ts +165 -165
- package/tests/unit/components/crud/crud-save-button.spec.ts +118 -118
- package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +42 -42
- package/tests/unit/components/tek-card-title/CardTitle.spec.ts +34 -34
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +470 -470
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +364 -364
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -112
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +148 -148
- package/tests/unit/components/tek-grid/grid-column.spec.ts +270 -270
- package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +195 -195
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +967 -967
- package/tests/unit/components/tek-grid/grid.spec.ts +3340 -3116
- package/tests/unit/components/tek-grid/layout_options.spec.ts +980 -980
- package/tests/unit/components/tek-image/Image.spec.ts +67 -67
- package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +37 -37
- package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +200 -200
- package/tests/unit/components/tek-loading/Loading.spec.ts +30 -30
- package/tests/unit/components/tek-notifications/notifications.spec.ts +201 -201
- package/tests/unit/components/tek-product-card/product-card.spec.ts +61 -61
- package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +220 -220
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +86 -86
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +430 -430
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +776 -776
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +24 -0
- package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -44
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -135
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +267 -174
- package/tests/unit/utils/report-filter/report-filter.spec.ts +66 -66
- package/tsconfig.eslint.json +8 -8
- package/types/components/tek-datasource/memory-datasource.d.ts +2 -4
- package/types/components/tek-datasource/rest-datasource.d.ts +6 -3
- package/types/components/tek-grid/grid.d.ts +50 -6
- package/types/components/tek-grid/interfaces.d.ts +5 -3
- package/types/components/tek-tree-grid/tree-grid.d.ts +5 -1
- package/types/utils/grid-base/grid-base.d.ts +12 -229
- package/types/utils/grid-base/grid-controller.d.ts +1 -3
- package/types/components/tek-ag-grid/default-icons.d.ts +0 -53
- package/types/components/tek-ag-grid/interfaces.d.ts +0 -9
- package/types/components/tek-ag-grid/tek-ag-grid.d.ts +0 -35
- package/types/components/tek-datasource/datasource.d.ts +0 -94
- package/types/components/tek-grid/default-icons.d.ts +0 -53
- package/types/components/tek-grid/filter-dynamic-values.d.ts +0 -9
- package/types/components/tek-grid/grid-controller.d.ts +0 -19
- package/types/components/tek-grid/grid_column.d.ts +0 -14
- package/types/components/tek-grid/grid_controller.d.ts +0 -15
- package/types/components/tek-grid/tek-grid.d.ts +0 -35
- package/types/components/tek-login/interfaces.d.ts +0 -3
- package/types/components/tek-login/login-children.d.ts +0 -3
- package/types/components/tek-login/login.d.ts +0 -58
- package/types/components/tek-login/login_children.d.ts +0 -3
|
@@ -1,967 +1,967 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Button, Date, Form, IButton, IForm, IModal, ISelectMultiple, Modal, ModalService, SelectMultiple,
|
|
5
|
-
} from '@zeedhi/common';
|
|
6
|
-
import {
|
|
7
|
-
Http, Metadata, DateHelper, Config,
|
|
8
|
-
} from '@zeedhi/core';
|
|
9
|
-
import {
|
|
10
|
-
IFilterPropsComponent,
|
|
11
|
-
ITekGridFilterButton,
|
|
12
|
-
TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
|
|
13
|
-
} from '../../../../src';
|
|
14
|
-
import { setClick, getChild } from '../../../__helpers__';
|
|
15
|
-
|
|
16
|
-
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
17
|
-
|
|
18
|
-
jest.useFakeTimers();
|
|
19
|
-
|
|
20
|
-
const clickOnFilterButton = (grid: TekGrid, event?: any) => {
|
|
21
|
-
const buttonProps = getChild<ITekGridFilterButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
|
|
22
|
-
const filterButton = new TekGridFilterButton(buttonProps);
|
|
23
|
-
setClick(filterButton, event);
|
|
24
|
-
|
|
25
|
-
return filterButton;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
describe('TekGridFilterButton', () => {
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
// clear all metadata instances before testing
|
|
31
|
-
const { instances } = Metadata as any;
|
|
32
|
-
Object.keys(instances).forEach((key) => {
|
|
33
|
-
Metadata.clearInstance(key, instances[key].componentId);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
jest.clearAllTimers();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('loadGrid()', () => {
|
|
40
|
-
it('should load grid by the gridName', () => {
|
|
41
|
-
const instance = new TekGrid({
|
|
42
|
-
name: 'grid-1',
|
|
43
|
-
component: 'TekGrid',
|
|
44
|
-
});
|
|
45
|
-
instance.onCreated();
|
|
46
|
-
|
|
47
|
-
const filterButton = new TekGridFilterButton({
|
|
48
|
-
name: 'columns-button-1',
|
|
49
|
-
component: 'TekGridColumnsButton',
|
|
50
|
-
gridName: 'grid-1',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(filterButton.grid).toEqual(instance);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should load grid by the gridName', () => {
|
|
57
|
-
const instance = new TekGrid({
|
|
58
|
-
name: 'grid-1',
|
|
59
|
-
component: 'TekGrid',
|
|
60
|
-
});
|
|
61
|
-
instance.onCreated();
|
|
62
|
-
|
|
63
|
-
const filterButton = new TekGridFilterButton({
|
|
64
|
-
name: 'columns-button-1',
|
|
65
|
-
component: 'TekGridColumnsButton',
|
|
66
|
-
grid: instance,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(filterButton.grid).toEqual(instance);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should load grid by the gridName', () => {
|
|
73
|
-
const instance = new TekGrid({
|
|
74
|
-
name: 'grid-1',
|
|
75
|
-
component: 'TekGrid',
|
|
76
|
-
});
|
|
77
|
-
instance.onCreated();
|
|
78
|
-
const filterButton = new TekGridFilterButton({
|
|
79
|
-
name: 'columns-button-1',
|
|
80
|
-
component: 'TekGridColumnsButton',
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
filterButton.loadGrid('grid-1');
|
|
84
|
-
|
|
85
|
-
expect(filterButton.grid).toEqual(instance);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('filterClick()', () => {
|
|
90
|
-
it('should call createFilterFromColumns', () => {
|
|
91
|
-
const instance = new TekGrid({
|
|
92
|
-
name: 'grid_filterClick1',
|
|
93
|
-
component: 'TekGrid',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const formInstance = new Form({
|
|
97
|
-
name: 'form',
|
|
98
|
-
component: 'ZdForm',
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const spy = jest.spyOn(ModalService, 'create');
|
|
102
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formInstance);
|
|
103
|
-
instance.onCreated();
|
|
104
|
-
|
|
105
|
-
const button = clickOnFilterButton(instance);
|
|
106
|
-
button.onCreated();
|
|
107
|
-
|
|
108
|
-
expect(spy).toBeCalledTimes(1);
|
|
109
|
-
button.click();
|
|
110
|
-
expect(spy).toBeCalledTimes(1);
|
|
111
|
-
expect(button.isVisible).toBeFalsy();
|
|
112
|
-
(instance as any).gridBase.hideFilterModal();
|
|
113
|
-
|
|
114
|
-
button.onBeforeDestroy();
|
|
115
|
-
|
|
116
|
-
spy.mockReset();
|
|
117
|
-
spyMetadata.mockReset();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should call events', () => {
|
|
121
|
-
let filterClickCalled = false;
|
|
122
|
-
const instance = new TekGrid({
|
|
123
|
-
name: 'grid_filterClick2',
|
|
124
|
-
component: 'TekGrid',
|
|
125
|
-
events: {
|
|
126
|
-
filterClick: () => { filterClickCalled = true; },
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal) => new Modal(modal));
|
|
131
|
-
|
|
132
|
-
instance.onCreated();
|
|
133
|
-
clickOnFilterButton(instance);
|
|
134
|
-
|
|
135
|
-
expect(filterClickCalled).toBeTruthy();
|
|
136
|
-
|
|
137
|
-
spy.mockReset();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should not call saveEditedRows if filterClick call preventDefault', () => {
|
|
141
|
-
let filterClickCalled = false;
|
|
142
|
-
const instance = new TekGrid({
|
|
143
|
-
name: 'grid_filterClick3',
|
|
144
|
-
component: 'TekGrid',
|
|
145
|
-
events: {
|
|
146
|
-
filterClick: () => { filterClickCalled = true; },
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const spy = jest.spyOn(ModalService, 'create');
|
|
151
|
-
|
|
152
|
-
instance.onCreated();
|
|
153
|
-
clickOnFilterButton(instance, { defaultPrevented: true });
|
|
154
|
-
|
|
155
|
-
expect(filterClickCalled).toBeTruthy();
|
|
156
|
-
expect(spy).not.toBeCalled();
|
|
157
|
-
|
|
158
|
-
spy.mockReset();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should create modal with no form elements', () => {
|
|
162
|
-
const instance = new TekGrid({
|
|
163
|
-
name: 'grid_filterClick4',
|
|
164
|
-
component: 'TekGrid',
|
|
165
|
-
columns: [
|
|
166
|
-
{ name: 'id' },
|
|
167
|
-
{ name: 'name', filterable: false, filterProps: { name: 'name_edit', label: 'name' } },
|
|
168
|
-
],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
let formElements: any = [];
|
|
172
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
173
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
174
|
-
formElements = form.children;
|
|
175
|
-
|
|
176
|
-
return new Modal(modal);
|
|
177
|
-
});
|
|
178
|
-
instance.onCreated();
|
|
179
|
-
clickOnFilterButton(instance);
|
|
180
|
-
|
|
181
|
-
expect(formElements).toEqual([]);
|
|
182
|
-
spy.mockReset();
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('should create modal with filterable form elements', () => {
|
|
186
|
-
const instance = new TekGrid({
|
|
187
|
-
name: 'grid_filterClick5',
|
|
188
|
-
component: 'TekGrid',
|
|
189
|
-
columns: [
|
|
190
|
-
{ name: 'id' },
|
|
191
|
-
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
192
|
-
],
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
let formElements: any = [];
|
|
196
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
197
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
198
|
-
formElements = form.children;
|
|
199
|
-
|
|
200
|
-
return new Modal(modal);
|
|
201
|
-
});
|
|
202
|
-
instance.onCreated();
|
|
203
|
-
clickOnFilterButton(instance);
|
|
204
|
-
|
|
205
|
-
expect(formElements[0].name).toBe('grid_filterClick5-filter-AND-CONTAINS-name-0');
|
|
206
|
-
|
|
207
|
-
spy.mockReset();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('when creating a SelectMultiple filter, default should not add showCheckboxAll prop', () => {
|
|
211
|
-
const instance = new TekGrid({
|
|
212
|
-
name: 'grid_filterClick5',
|
|
213
|
-
component: 'TekGrid',
|
|
214
|
-
columns: [
|
|
215
|
-
{
|
|
216
|
-
name: 'id',
|
|
217
|
-
filterable: true,
|
|
218
|
-
filterProps: [{
|
|
219
|
-
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
220
|
-
}],
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
name: 'name',
|
|
224
|
-
filterable: true,
|
|
225
|
-
filterProps: [{ name: 'name_edit', label: 'name', component: 'ZdSelectMultiple' }],
|
|
226
|
-
},
|
|
227
|
-
],
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
let formElements: any = [];
|
|
231
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
232
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
233
|
-
formElements = form.children;
|
|
234
|
-
|
|
235
|
-
return new Modal(modal);
|
|
236
|
-
});
|
|
237
|
-
instance.onCreated();
|
|
238
|
-
clickOnFilterButton(instance);
|
|
239
|
-
|
|
240
|
-
expect(formElements[0].showCheckboxAll).toBeFalsy();
|
|
241
|
-
expect(formElements[1].showCheckboxAll).toBeFalsy();
|
|
242
|
-
|
|
243
|
-
spy.mockReset();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('when using the prop showCheckboxAllFilter, should add showCheckboxAll prop to SelectMultiple filters', () => {
|
|
247
|
-
const instance = new TekGrid({
|
|
248
|
-
name: 'grid_filterClick5',
|
|
249
|
-
component: 'TekGrid',
|
|
250
|
-
showCheckboxAllFilter: true,
|
|
251
|
-
columns: [
|
|
252
|
-
{
|
|
253
|
-
name: 'id',
|
|
254
|
-
filterable: true,
|
|
255
|
-
filterProps: [{
|
|
256
|
-
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
257
|
-
}],
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
name: 'name',
|
|
261
|
-
filterable: true,
|
|
262
|
-
filterProps: [{ name: 'name_edit', label: 'name', component: 'ZdSelectMultiple' }],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
let formElements: any = [];
|
|
268
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
269
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
270
|
-
formElements = form.children;
|
|
271
|
-
|
|
272
|
-
return new Modal(modal);
|
|
273
|
-
});
|
|
274
|
-
instance.onCreated();
|
|
275
|
-
clickOnFilterButton(instance);
|
|
276
|
-
|
|
277
|
-
expect(formElements[0].showCheckboxAll).toBeFalsy();
|
|
278
|
-
expect(formElements[1].showCheckboxAll).toBeTruthy();
|
|
279
|
-
|
|
280
|
-
spy.mockReset();
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('when creating a SelectMultiple filter, should change the filter value depending on checkboxAll', () => {
|
|
284
|
-
const instance = new TekGrid({
|
|
285
|
-
name: 'grid_filterClick5',
|
|
286
|
-
component: 'TekGrid',
|
|
287
|
-
columns: [
|
|
288
|
-
{
|
|
289
|
-
name: 'id',
|
|
290
|
-
filterable: true,
|
|
291
|
-
filterProps: [{
|
|
292
|
-
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
293
|
-
}],
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
299
|
-
let select: ISelectMultiple = { name: 'select', component: 'ZdSelectMultiple' };
|
|
300
|
-
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
301
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
302
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
303
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
304
|
-
select = getChild(form.children || [], `${instance.name}-filter-AND-CONTAINS-id-0`);
|
|
305
|
-
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
306
|
-
|
|
307
|
-
return new Modal(modal);
|
|
308
|
-
});
|
|
309
|
-
instance.onCreated();
|
|
310
|
-
clickOnFilterButton(instance);
|
|
311
|
-
const applyButtonObject = new Button(applyButton);
|
|
312
|
-
|
|
313
|
-
const formObject = new Form(form);
|
|
314
|
-
const selectObject = new SelectMultiple(select);
|
|
315
|
-
jest.spyOn(Metadata, 'getInstance').mockReturnValue(formObject);
|
|
316
|
-
jest.spyOn(formObject, 'getChildInstance').mockReturnValue(selectObject);
|
|
317
|
-
|
|
318
|
-
formObject.value['grid_filterClick5-filter-AND-CONTAINS-id-0'] = ['example'];
|
|
319
|
-
setClick(applyButtonObject);
|
|
320
|
-
|
|
321
|
-
expect(instance.datasource.filter).toEqual({});
|
|
322
|
-
|
|
323
|
-
selectObject.checkboxAll = true;
|
|
324
|
-
setClick(applyButtonObject);
|
|
325
|
-
|
|
326
|
-
expect(instance.datasource.filter).toEqual({});
|
|
327
|
-
|
|
328
|
-
(Config as any).set({ selectAllCompatibilityMode: true });
|
|
329
|
-
setClick(applyButtonObject);
|
|
330
|
-
expect(instance.datasource.filter).toEqual({});
|
|
331
|
-
|
|
332
|
-
spy.mockReset();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it('should create modal with filterable and ordered form elements', () => {
|
|
336
|
-
const instance = new TekGrid({
|
|
337
|
-
name: 'grid-filter-order',
|
|
338
|
-
component: 'TekGrid',
|
|
339
|
-
columns: [
|
|
340
|
-
{ name: 'id' },
|
|
341
|
-
{
|
|
342
|
-
name: 'first_name',
|
|
343
|
-
filterable: true,
|
|
344
|
-
filterProps: [{ name: 'first_name_edit', label: 'first_name' }],
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: 'last_name',
|
|
348
|
-
filterable: true,
|
|
349
|
-
filterIndex: 1,
|
|
350
|
-
filterProps: [{ name: 'last_name_edit', label: 'last_name' }],
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: 'dob',
|
|
354
|
-
filterable: true,
|
|
355
|
-
filterIndex: 0,
|
|
356
|
-
filterProps: [{ name: 'dob_edit', label: 'dob' }],
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
let formElements: any = [];
|
|
362
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
363
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
364
|
-
formElements = form.children;
|
|
365
|
-
|
|
366
|
-
return new Modal(modal);
|
|
367
|
-
});
|
|
368
|
-
instance.onCreated();
|
|
369
|
-
|
|
370
|
-
clickOnFilterButton(instance);
|
|
371
|
-
|
|
372
|
-
expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
|
|
373
|
-
expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
|
|
374
|
-
expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
|
|
375
|
-
|
|
376
|
-
spy.mockReset();
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it('should create modal with filterable form elements and TekRestDatasource', () => {
|
|
380
|
-
const instance = new TekGrid({
|
|
381
|
-
name: 'grid_filterClick6',
|
|
382
|
-
component: 'TekGrid',
|
|
383
|
-
datasource: {
|
|
384
|
-
type: 'tek-rest',
|
|
385
|
-
lazyLoad: true,
|
|
386
|
-
},
|
|
387
|
-
columns: [
|
|
388
|
-
{
|
|
389
|
-
name: 'id',
|
|
390
|
-
filterProps: [{ name: 'id_edit' }],
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
name: 'name',
|
|
394
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
395
|
-
filterProps: [{
|
|
396
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
397
|
-
}],
|
|
398
|
-
},
|
|
399
|
-
],
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
let formElements: any = [];
|
|
403
|
-
let form: IForm;
|
|
404
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
405
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
406
|
-
formElements = form.children;
|
|
407
|
-
|
|
408
|
-
return new Modal(modal);
|
|
409
|
-
});
|
|
410
|
-
instance.onCreated();
|
|
411
|
-
|
|
412
|
-
clickOnFilterButton(instance);
|
|
413
|
-
|
|
414
|
-
expect(formElements[0].name).toBe('grid_filterClick6-filter-AND-CONTAINS-id-0');
|
|
415
|
-
expect(formElements[1].name).toBe('grid_filterClick6-filter-OR-NOT_EQUALS-name-0');
|
|
416
|
-
expect(formElements[1].component).toBe('ZdSelect');
|
|
417
|
-
|
|
418
|
-
spy.mockReset();
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('should create modal with helper component', () => {
|
|
422
|
-
const instance = new TekGrid({
|
|
423
|
-
name: 'grid_filterClick7',
|
|
424
|
-
component: 'TekGrid',
|
|
425
|
-
datasource: {
|
|
426
|
-
type: 'tek-rest',
|
|
427
|
-
lazyLoad: true,
|
|
428
|
-
},
|
|
429
|
-
columns: [
|
|
430
|
-
{
|
|
431
|
-
name: 'id',
|
|
432
|
-
filterProps: [{ name: 'id_edit' }],
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
name: 'date',
|
|
436
|
-
componentProps: { name: 'date_edit', component: 'ZdDate' },
|
|
437
|
-
filterProps: [
|
|
438
|
-
{
|
|
439
|
-
name: 'date_edit1',
|
|
440
|
-
label: 'date1',
|
|
441
|
-
operation: 'NOT_EQUALS',
|
|
442
|
-
relation: 'OR',
|
|
443
|
-
helperOptions: [
|
|
444
|
-
'TODAY',
|
|
445
|
-
'TOMORROW',
|
|
446
|
-
],
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
name: 'date_edit2',
|
|
450
|
-
label: 'date2',
|
|
451
|
-
showLabel: false,
|
|
452
|
-
operation: 'NOT_EQUALS',
|
|
453
|
-
relation: 'OR',
|
|
454
|
-
helperOptions: [
|
|
455
|
-
'TODAY',
|
|
456
|
-
'TOMORROW',
|
|
457
|
-
],
|
|
458
|
-
},
|
|
459
|
-
],
|
|
460
|
-
},
|
|
461
|
-
],
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
let formElements: any = [];
|
|
465
|
-
let form: IForm;
|
|
466
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
467
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
468
|
-
formElements = form.children;
|
|
469
|
-
|
|
470
|
-
return new Modal(modal);
|
|
471
|
-
});
|
|
472
|
-
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
473
|
-
|
|
474
|
-
instance.onCreated();
|
|
475
|
-
clickOnFilterButton(instance);
|
|
476
|
-
|
|
477
|
-
expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
|
|
478
|
-
expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
|
|
479
|
-
expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
|
|
480
|
-
|
|
481
|
-
spy.mockReset();
|
|
482
|
-
dateHelperSpy.mockReset();
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
it('should apply helper value', () => {
|
|
486
|
-
const instance = new TekGrid({
|
|
487
|
-
name: 'grid_filterClick8',
|
|
488
|
-
component: 'TekGrid',
|
|
489
|
-
datasource: {
|
|
490
|
-
type: 'tek-rest',
|
|
491
|
-
lazyLoad: true,
|
|
492
|
-
},
|
|
493
|
-
columns: [
|
|
494
|
-
{
|
|
495
|
-
name: 'date1',
|
|
496
|
-
componentProps: { name: 'date_edit1', component: 'ZdDate' },
|
|
497
|
-
filterProps: {
|
|
498
|
-
name: 'date_edit1',
|
|
499
|
-
label: 'date1',
|
|
500
|
-
operation: 'NOT_EQUALS',
|
|
501
|
-
relation: 'OR',
|
|
502
|
-
helperOptions: [
|
|
503
|
-
'TODAY',
|
|
504
|
-
'TOMORROW',
|
|
505
|
-
],
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
name: 'date2',
|
|
510
|
-
componentProps: { name: 'date_edit2', component: 'ZdDate' },
|
|
511
|
-
filterProps: [
|
|
512
|
-
{
|
|
513
|
-
name: 'date_edit21',
|
|
514
|
-
label: 'date21',
|
|
515
|
-
operation: 'NOT_EQUALS',
|
|
516
|
-
relation: 'OR',
|
|
517
|
-
helperOptions: [
|
|
518
|
-
'TODAY',
|
|
519
|
-
'TOMORROW',
|
|
520
|
-
],
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
name: 'date_edit22',
|
|
524
|
-
label: 'date22',
|
|
525
|
-
helperOptions: [
|
|
526
|
-
'TODAY',
|
|
527
|
-
'TOMORROW',
|
|
528
|
-
],
|
|
529
|
-
},
|
|
530
|
-
],
|
|
531
|
-
},
|
|
532
|
-
],
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
let formElements: any = [];
|
|
536
|
-
let form: IForm;
|
|
537
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
538
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
539
|
-
formElements = form.children;
|
|
540
|
-
|
|
541
|
-
return new Modal(modal);
|
|
542
|
-
});
|
|
543
|
-
instance.onCreated();
|
|
544
|
-
clickOnFilterButton(instance);
|
|
545
|
-
|
|
546
|
-
const dateComp = new Date(formElements[0]);
|
|
547
|
-
dateComp.helperValue = 'TODAY';
|
|
548
|
-
dateComp.change({} as Event, {} as HTMLElement);
|
|
549
|
-
expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
|
|
550
|
-
|
|
551
|
-
const dateComp21 = new Date(formElements[1]);
|
|
552
|
-
dateComp21.helperValue = 'TODAY';
|
|
553
|
-
dateComp21.change({} as Event, {} as HTMLElement);
|
|
554
|
-
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
|
|
555
|
-
|
|
556
|
-
const dateComp22 = new Date(formElements[2]);
|
|
557
|
-
dateComp22.helperValue = 'TODAY';
|
|
558
|
-
dateComp22.change({} as Event, {} as HTMLElement);
|
|
559
|
-
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
|
|
560
|
-
|
|
561
|
-
spy.mockReset();
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
it('should load form values from tekdatasource', () => {
|
|
565
|
-
const instance = new TekGrid({
|
|
566
|
-
name: 'grid_filterClick9',
|
|
567
|
-
component: 'TekGrid',
|
|
568
|
-
datasource: {
|
|
569
|
-
type: 'tek-rest',
|
|
570
|
-
lazyLoad: true,
|
|
571
|
-
dynamicFilter: {
|
|
572
|
-
name: [
|
|
573
|
-
{
|
|
574
|
-
operation: 'NOT_EQUALS',
|
|
575
|
-
relation: 'OR',
|
|
576
|
-
value: 'teste',
|
|
577
|
-
},
|
|
578
|
-
],
|
|
579
|
-
phone: [
|
|
580
|
-
{
|
|
581
|
-
value: '9',
|
|
582
|
-
},
|
|
583
|
-
],
|
|
584
|
-
date: [
|
|
585
|
-
{
|
|
586
|
-
operation: 'IN',
|
|
587
|
-
relation: 'OR',
|
|
588
|
-
value: ['2021-11-12', '2021-12-12'],
|
|
589
|
-
},
|
|
590
|
-
],
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
columns: [
|
|
594
|
-
{
|
|
595
|
-
name: 'id',
|
|
596
|
-
filterProps: [{ name: 'id_edit' }],
|
|
597
|
-
},
|
|
598
|
-
{
|
|
599
|
-
name: 'name',
|
|
600
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
601
|
-
filterProps: {
|
|
602
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
603
|
-
},
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
name: 'phone',
|
|
607
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
name: 'date',
|
|
611
|
-
filterProps: { name: 'date_edit', helperValue: 'TODAY' },
|
|
612
|
-
},
|
|
613
|
-
],
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
617
|
-
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
618
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
619
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
620
|
-
|
|
621
|
-
return new Modal(modal);
|
|
622
|
-
});
|
|
623
|
-
instance.onCreated();
|
|
624
|
-
|
|
625
|
-
clickOnFilterButton(instance);
|
|
626
|
-
|
|
627
|
-
expect(form.name).toBe('grid_filterClick9-filter-form');
|
|
628
|
-
const formObject = new Form(form);
|
|
629
|
-
formObject.value = {
|
|
630
|
-
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
631
|
-
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': null,
|
|
632
|
-
'grid_filterClick9-filter-AND-CONTAINS-phone-0': null,
|
|
633
|
-
'grid_filterClick9-filter-OR-IN-date-0': null,
|
|
634
|
-
};
|
|
635
|
-
const dateObject = new Date({ name: 'date', component: 'ZdDate' });
|
|
636
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
|
|
637
|
-
formObject.onMounted({} as HTMLElement);
|
|
638
|
-
expect(formObject.value).toEqual({
|
|
639
|
-
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
640
|
-
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
641
|
-
'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
|
|
642
|
-
'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
|
|
643
|
-
});
|
|
644
|
-
expect(dateObject.hint).toBe('TODAY');
|
|
645
|
-
spyMetadata.mockReset();
|
|
646
|
-
dateHelperSpy.mockReset();
|
|
647
|
-
spy.mockReset();
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
it('should load form values from datasource', () => {
|
|
651
|
-
const instance = new TekGrid({
|
|
652
|
-
name: 'grid_filterClick10',
|
|
653
|
-
component: 'TekGrid',
|
|
654
|
-
datasource: {
|
|
655
|
-
filter: {
|
|
656
|
-
id: '',
|
|
657
|
-
name: 'teste',
|
|
658
|
-
phone: '9',
|
|
659
|
-
},
|
|
660
|
-
},
|
|
661
|
-
columns: [
|
|
662
|
-
{
|
|
663
|
-
name: 'id',
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
name: 'name',
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
name: 'phone',
|
|
670
|
-
},
|
|
671
|
-
],
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
let formProps: IForm = {} as IForm;
|
|
675
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
676
|
-
formProps = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
677
|
-
|
|
678
|
-
return new Modal(modal);
|
|
679
|
-
});
|
|
680
|
-
instance.onCreated();
|
|
681
|
-
clickOnFilterButton(instance);
|
|
682
|
-
|
|
683
|
-
const formObject = new Form(formProps);
|
|
684
|
-
formObject.onMounted({} as HTMLElement);
|
|
685
|
-
|
|
686
|
-
expect(formObject.value).toEqual({
|
|
687
|
-
'grid_filterClick10-filter-AND-CONTAINS-name-0': 'teste',
|
|
688
|
-
'grid_filterClick10-filter-AND-CONTAINS-phone-0': '9',
|
|
689
|
-
});
|
|
690
|
-
spy.mockReset();
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
it('should apply filter from form to tekdatasource', () => {
|
|
694
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
695
|
-
data: {
|
|
696
|
-
data: [
|
|
697
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
698
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
699
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
700
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
701
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
702
|
-
],
|
|
703
|
-
pagination: {
|
|
704
|
-
page: 1,
|
|
705
|
-
total: 5,
|
|
706
|
-
limit: 15,
|
|
707
|
-
},
|
|
708
|
-
},
|
|
709
|
-
}));
|
|
710
|
-
const instance = new TekGrid({
|
|
711
|
-
name: 'grid_filterClick11',
|
|
712
|
-
component: 'TekGrid',
|
|
713
|
-
datasource: {
|
|
714
|
-
type: 'tek-rest',
|
|
715
|
-
},
|
|
716
|
-
columns: [
|
|
717
|
-
{
|
|
718
|
-
name: 'id',
|
|
719
|
-
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
name: 'name',
|
|
723
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
724
|
-
filterProps: [{
|
|
725
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
726
|
-
}],
|
|
727
|
-
},
|
|
728
|
-
{
|
|
729
|
-
name: 'phone',
|
|
730
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
name: 'salary',
|
|
734
|
-
filterProps: [
|
|
735
|
-
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
736
|
-
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
737
|
-
],
|
|
738
|
-
},
|
|
739
|
-
],
|
|
740
|
-
});
|
|
741
|
-
|
|
742
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
743
|
-
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
744
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
745
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
746
|
-
|
|
747
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
748
|
-
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
749
|
-
|
|
750
|
-
return new Modal(modal);
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
instance.onCreated();
|
|
754
|
-
|
|
755
|
-
const buttonProps = getChild<ITekGridFilterButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
756
|
-
const button = new TekGridFilterButton(buttonProps);
|
|
757
|
-
setClick(button);
|
|
758
|
-
|
|
759
|
-
const formObject = new Form(form);
|
|
760
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
761
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
762
|
-
formObject.value = {
|
|
763
|
-
'grid_filterClick11-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
764
|
-
'grid_filterClick11-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
765
|
-
'grid_filterClick11-filter-AND-CONTAINS-phone-0': '',
|
|
766
|
-
'grid_filterClick11-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
767
|
-
'grid_filterClick11-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
768
|
-
};
|
|
769
|
-
const applyButtonObject = new Button(applyButton);
|
|
770
|
-
formObject.validate = () => false;
|
|
771
|
-
setClick(applyButtonObject);
|
|
772
|
-
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({});
|
|
773
|
-
|
|
774
|
-
formObject.validate = () => true;
|
|
775
|
-
setClick(applyButtonObject);
|
|
776
|
-
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({
|
|
777
|
-
id: [
|
|
778
|
-
{
|
|
779
|
-
operation: 'IN',
|
|
780
|
-
relation: 'AND',
|
|
781
|
-
value: ['1', '2', '3'],
|
|
782
|
-
},
|
|
783
|
-
],
|
|
784
|
-
name: [
|
|
785
|
-
{
|
|
786
|
-
operation: 'NOT_EQUALS',
|
|
787
|
-
relation: 'OR',
|
|
788
|
-
value: 'teste',
|
|
789
|
-
},
|
|
790
|
-
],
|
|
791
|
-
salary: [
|
|
792
|
-
{
|
|
793
|
-
operation: 'GREATER_THAN_EQUALS',
|
|
794
|
-
relation: 'AND',
|
|
795
|
-
value: '1000',
|
|
796
|
-
},
|
|
797
|
-
{
|
|
798
|
-
operation: 'LESS_THAN_EQUALS',
|
|
799
|
-
relation: 'AND',
|
|
800
|
-
value: '2000',
|
|
801
|
-
},
|
|
802
|
-
],
|
|
803
|
-
});
|
|
804
|
-
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
|
|
805
|
-
expect(spyDatasourceGet).toBeCalled();
|
|
806
|
-
spyMetadata.mockReset();
|
|
807
|
-
spyDatasourceGet.mockReset();
|
|
808
|
-
spyModalService.mockReset();
|
|
809
|
-
httpSpy.mockReset();
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it('should clear data from form', () => {
|
|
813
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
814
|
-
data: {
|
|
815
|
-
data: [
|
|
816
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
817
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
818
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
819
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
820
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
821
|
-
],
|
|
822
|
-
pagination: {
|
|
823
|
-
page: 1,
|
|
824
|
-
total: 5,
|
|
825
|
-
limit: 15,
|
|
826
|
-
},
|
|
827
|
-
},
|
|
828
|
-
}));
|
|
829
|
-
const instance = new TekGrid({
|
|
830
|
-
name: 'grid_filterClick12',
|
|
831
|
-
component: 'TekGrid',
|
|
832
|
-
datasource: {
|
|
833
|
-
type: 'tek-rest',
|
|
834
|
-
},
|
|
835
|
-
columns: [
|
|
836
|
-
{
|
|
837
|
-
name: 'id',
|
|
838
|
-
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
839
|
-
},
|
|
840
|
-
{
|
|
841
|
-
name: 'name',
|
|
842
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
843
|
-
filterProps: [{
|
|
844
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
845
|
-
}],
|
|
846
|
-
},
|
|
847
|
-
{
|
|
848
|
-
name: 'phone',
|
|
849
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
name: 'salary',
|
|
853
|
-
filterProps: [
|
|
854
|
-
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
855
|
-
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
856
|
-
],
|
|
857
|
-
},
|
|
858
|
-
],
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
862
|
-
let clearButton: IButton = { name: 'clear', component: 'ZdButton' };
|
|
863
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
864
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
865
|
-
|
|
866
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
867
|
-
clearButton = getChild(modalFooter.leftSlot, `${instance.name}-filter-clearButton`);
|
|
868
|
-
|
|
869
|
-
return new Modal(modal);
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
instance.onCreated();
|
|
873
|
-
|
|
874
|
-
const buttonProps = getChild<ITekGridFilterButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
875
|
-
const button = new TekGridFilterButton(buttonProps);
|
|
876
|
-
setClick(button);
|
|
877
|
-
|
|
878
|
-
const formObject = new Form(form);
|
|
879
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
880
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
881
|
-
formObject.value = {
|
|
882
|
-
'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
883
|
-
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
884
|
-
'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
|
|
885
|
-
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
886
|
-
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
887
|
-
};
|
|
888
|
-
const clearButtonObject = new Button(clearButton);
|
|
889
|
-
setClick(clearButtonObject);
|
|
890
|
-
expect(formObject.value).toEqual({
|
|
891
|
-
'grid_filterClick12-filter-AND-IN-id-0': null,
|
|
892
|
-
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
|
|
893
|
-
'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
|
|
894
|
-
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
|
|
895
|
-
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
|
|
896
|
-
});
|
|
897
|
-
spyMetadata.mockReset();
|
|
898
|
-
spyDatasourceGet.mockReset();
|
|
899
|
-
spyModalService.mockReset();
|
|
900
|
-
httpSpy.mockReset();
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
it('should apply filter from form to datasource', () => {
|
|
904
|
-
let beforeApplyFilterCalled = false;
|
|
905
|
-
let changeLayoutCalled = false;
|
|
906
|
-
const instance = new TekGrid({
|
|
907
|
-
name: 'grid_filterClick13',
|
|
908
|
-
component: 'TekGrid',
|
|
909
|
-
columns: [
|
|
910
|
-
{
|
|
911
|
-
name: 'id',
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
name: 'name',
|
|
915
|
-
},
|
|
916
|
-
{
|
|
917
|
-
name: 'phone',
|
|
918
|
-
},
|
|
919
|
-
{
|
|
920
|
-
name: 'salary',
|
|
921
|
-
},
|
|
922
|
-
],
|
|
923
|
-
events: {
|
|
924
|
-
beforeApplyFilter: () => { beforeApplyFilterCalled = true; },
|
|
925
|
-
changeLayout: () => { changeLayoutCalled = true; },
|
|
926
|
-
},
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
930
|
-
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
931
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
932
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
933
|
-
|
|
934
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
935
|
-
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
936
|
-
|
|
937
|
-
return new Modal(modal);
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
instance.onCreated();
|
|
941
|
-
|
|
942
|
-
clickOnFilterButton(instance);
|
|
943
|
-
|
|
944
|
-
const formObject = new Form(form);
|
|
945
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
946
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
947
|
-
formObject.value = {
|
|
948
|
-
'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
|
|
949
|
-
'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
|
|
950
|
-
'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
|
|
951
|
-
'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
|
|
952
|
-
};
|
|
953
|
-
const applyButtonObject = new Button(applyButton);
|
|
954
|
-
setClick(applyButtonObject);
|
|
955
|
-
expect(instance.datasource.filter).toEqual({});
|
|
956
|
-
expect(beforeApplyFilterCalled).toBeTruthy();
|
|
957
|
-
expect(changeLayoutCalled).toBeTruthy();
|
|
958
|
-
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBe(undefined);
|
|
959
|
-
|
|
960
|
-
setClick(applyButtonObject, { defaultPrevented: true });
|
|
961
|
-
expect(spyDatasourceGet).toBeCalledTimes(1);
|
|
962
|
-
spyMetadata.mockReset();
|
|
963
|
-
spyDatasourceGet.mockReset();
|
|
964
|
-
spyModalService.mockReset();
|
|
965
|
-
});
|
|
966
|
-
});
|
|
967
|
-
});
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Button, Date, Form, IButton, IForm, IModal, ISelectMultiple, Modal, ModalService, SelectMultiple,
|
|
5
|
+
} from '@zeedhi/common';
|
|
6
|
+
import {
|
|
7
|
+
Http, Metadata, DateHelper, Config,
|
|
8
|
+
} from '@zeedhi/core';
|
|
9
|
+
import {
|
|
10
|
+
IFilterPropsComponent,
|
|
11
|
+
ITekGridFilterButton,
|
|
12
|
+
TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
|
|
13
|
+
} from '../../../../src';
|
|
14
|
+
import { setClick, getChild } from '../../../__helpers__';
|
|
15
|
+
|
|
16
|
+
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
17
|
+
|
|
18
|
+
jest.useFakeTimers();
|
|
19
|
+
|
|
20
|
+
const clickOnFilterButton = (grid: TekGrid, event?: any) => {
|
|
21
|
+
const buttonProps = getChild<ITekGridFilterButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
|
|
22
|
+
const filterButton = new TekGridFilterButton(buttonProps);
|
|
23
|
+
setClick(filterButton, event);
|
|
24
|
+
|
|
25
|
+
return filterButton;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('TekGridFilterButton', () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
// clear all metadata instances before testing
|
|
31
|
+
const { instances } = Metadata as any;
|
|
32
|
+
Object.keys(instances).forEach((key) => {
|
|
33
|
+
Metadata.clearInstance(key, instances[key].componentId);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
jest.clearAllTimers();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('loadGrid()', () => {
|
|
40
|
+
it('should load grid by the gridName', () => {
|
|
41
|
+
const instance = new TekGrid({
|
|
42
|
+
name: 'grid-1',
|
|
43
|
+
component: 'TekGrid',
|
|
44
|
+
});
|
|
45
|
+
instance.onCreated();
|
|
46
|
+
|
|
47
|
+
const filterButton = new TekGridFilterButton({
|
|
48
|
+
name: 'columns-button-1',
|
|
49
|
+
component: 'TekGridColumnsButton',
|
|
50
|
+
gridName: 'grid-1',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(filterButton.grid).toEqual(instance);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should load grid by the gridName', () => {
|
|
57
|
+
const instance = new TekGrid({
|
|
58
|
+
name: 'grid-1',
|
|
59
|
+
component: 'TekGrid',
|
|
60
|
+
});
|
|
61
|
+
instance.onCreated();
|
|
62
|
+
|
|
63
|
+
const filterButton = new TekGridFilterButton({
|
|
64
|
+
name: 'columns-button-1',
|
|
65
|
+
component: 'TekGridColumnsButton',
|
|
66
|
+
grid: instance,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(filterButton.grid).toEqual(instance);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should load grid by the gridName', () => {
|
|
73
|
+
const instance = new TekGrid({
|
|
74
|
+
name: 'grid-1',
|
|
75
|
+
component: 'TekGrid',
|
|
76
|
+
});
|
|
77
|
+
instance.onCreated();
|
|
78
|
+
const filterButton = new TekGridFilterButton({
|
|
79
|
+
name: 'columns-button-1',
|
|
80
|
+
component: 'TekGridColumnsButton',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
filterButton.loadGrid('grid-1');
|
|
84
|
+
|
|
85
|
+
expect(filterButton.grid).toEqual(instance);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('filterClick()', () => {
|
|
90
|
+
it('should call createFilterFromColumns', () => {
|
|
91
|
+
const instance = new TekGrid({
|
|
92
|
+
name: 'grid_filterClick1',
|
|
93
|
+
component: 'TekGrid',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const formInstance = new Form({
|
|
97
|
+
name: 'form',
|
|
98
|
+
component: 'ZdForm',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const spy = jest.spyOn(ModalService, 'create');
|
|
102
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formInstance);
|
|
103
|
+
instance.onCreated();
|
|
104
|
+
|
|
105
|
+
const button = clickOnFilterButton(instance);
|
|
106
|
+
button.onCreated();
|
|
107
|
+
|
|
108
|
+
expect(spy).toBeCalledTimes(1);
|
|
109
|
+
button.click();
|
|
110
|
+
expect(spy).toBeCalledTimes(1);
|
|
111
|
+
expect(button.isVisible).toBeFalsy();
|
|
112
|
+
(instance as any).gridBase.hideFilterModal();
|
|
113
|
+
|
|
114
|
+
button.onBeforeDestroy();
|
|
115
|
+
|
|
116
|
+
spy.mockReset();
|
|
117
|
+
spyMetadata.mockReset();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should call events', () => {
|
|
121
|
+
let filterClickCalled = false;
|
|
122
|
+
const instance = new TekGrid({
|
|
123
|
+
name: 'grid_filterClick2',
|
|
124
|
+
component: 'TekGrid',
|
|
125
|
+
events: {
|
|
126
|
+
filterClick: () => { filterClickCalled = true; },
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal) => new Modal(modal));
|
|
131
|
+
|
|
132
|
+
instance.onCreated();
|
|
133
|
+
clickOnFilterButton(instance);
|
|
134
|
+
|
|
135
|
+
expect(filterClickCalled).toBeTruthy();
|
|
136
|
+
|
|
137
|
+
spy.mockReset();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should not call saveEditedRows if filterClick call preventDefault', () => {
|
|
141
|
+
let filterClickCalled = false;
|
|
142
|
+
const instance = new TekGrid({
|
|
143
|
+
name: 'grid_filterClick3',
|
|
144
|
+
component: 'TekGrid',
|
|
145
|
+
events: {
|
|
146
|
+
filterClick: () => { filterClickCalled = true; },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const spy = jest.spyOn(ModalService, 'create');
|
|
151
|
+
|
|
152
|
+
instance.onCreated();
|
|
153
|
+
clickOnFilterButton(instance, { defaultPrevented: true });
|
|
154
|
+
|
|
155
|
+
expect(filterClickCalled).toBeTruthy();
|
|
156
|
+
expect(spy).not.toBeCalled();
|
|
157
|
+
|
|
158
|
+
spy.mockReset();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should create modal with no form elements', () => {
|
|
162
|
+
const instance = new TekGrid({
|
|
163
|
+
name: 'grid_filterClick4',
|
|
164
|
+
component: 'TekGrid',
|
|
165
|
+
columns: [
|
|
166
|
+
{ name: 'id' },
|
|
167
|
+
{ name: 'name', filterable: false, filterProps: { name: 'name_edit', label: 'name' } },
|
|
168
|
+
],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
let formElements: any = [];
|
|
172
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
173
|
+
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
174
|
+
formElements = form.children;
|
|
175
|
+
|
|
176
|
+
return new Modal(modal);
|
|
177
|
+
});
|
|
178
|
+
instance.onCreated();
|
|
179
|
+
clickOnFilterButton(instance);
|
|
180
|
+
|
|
181
|
+
expect(formElements).toEqual([]);
|
|
182
|
+
spy.mockReset();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should create modal with filterable form elements', () => {
|
|
186
|
+
const instance = new TekGrid({
|
|
187
|
+
name: 'grid_filterClick5',
|
|
188
|
+
component: 'TekGrid',
|
|
189
|
+
columns: [
|
|
190
|
+
{ name: 'id' },
|
|
191
|
+
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
let formElements: any = [];
|
|
196
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
197
|
+
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
198
|
+
formElements = form.children;
|
|
199
|
+
|
|
200
|
+
return new Modal(modal);
|
|
201
|
+
});
|
|
202
|
+
instance.onCreated();
|
|
203
|
+
clickOnFilterButton(instance);
|
|
204
|
+
|
|
205
|
+
expect(formElements[0].name).toBe('grid_filterClick5-filter-AND-CONTAINS-name-0');
|
|
206
|
+
|
|
207
|
+
spy.mockReset();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('when creating a SelectMultiple filter, default should not add showCheckboxAll prop', () => {
|
|
211
|
+
const instance = new TekGrid({
|
|
212
|
+
name: 'grid_filterClick5',
|
|
213
|
+
component: 'TekGrid',
|
|
214
|
+
columns: [
|
|
215
|
+
{
|
|
216
|
+
name: 'id',
|
|
217
|
+
filterable: true,
|
|
218
|
+
filterProps: [{
|
|
219
|
+
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
220
|
+
}],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'name',
|
|
224
|
+
filterable: true,
|
|
225
|
+
filterProps: [{ name: 'name_edit', label: 'name', component: 'ZdSelectMultiple' }],
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
let formElements: any = [];
|
|
231
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
232
|
+
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
233
|
+
formElements = form.children;
|
|
234
|
+
|
|
235
|
+
return new Modal(modal);
|
|
236
|
+
});
|
|
237
|
+
instance.onCreated();
|
|
238
|
+
clickOnFilterButton(instance);
|
|
239
|
+
|
|
240
|
+
expect(formElements[0].showCheckboxAll).toBeFalsy();
|
|
241
|
+
expect(formElements[1].showCheckboxAll).toBeFalsy();
|
|
242
|
+
|
|
243
|
+
spy.mockReset();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('when using the prop showCheckboxAllFilter, should add showCheckboxAll prop to SelectMultiple filters', () => {
|
|
247
|
+
const instance = new TekGrid({
|
|
248
|
+
name: 'grid_filterClick5',
|
|
249
|
+
component: 'TekGrid',
|
|
250
|
+
showCheckboxAllFilter: true,
|
|
251
|
+
columns: [
|
|
252
|
+
{
|
|
253
|
+
name: 'id',
|
|
254
|
+
filterable: true,
|
|
255
|
+
filterProps: [{
|
|
256
|
+
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
257
|
+
}],
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'name',
|
|
261
|
+
filterable: true,
|
|
262
|
+
filterProps: [{ name: 'name_edit', label: 'name', component: 'ZdSelectMultiple' }],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
let formElements: any = [];
|
|
268
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
269
|
+
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
270
|
+
formElements = form.children;
|
|
271
|
+
|
|
272
|
+
return new Modal(modal);
|
|
273
|
+
});
|
|
274
|
+
instance.onCreated();
|
|
275
|
+
clickOnFilterButton(instance);
|
|
276
|
+
|
|
277
|
+
expect(formElements[0].showCheckboxAll).toBeFalsy();
|
|
278
|
+
expect(formElements[1].showCheckboxAll).toBeTruthy();
|
|
279
|
+
|
|
280
|
+
spy.mockReset();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('when creating a SelectMultiple filter, should change the filter value depending on checkboxAll', () => {
|
|
284
|
+
const instance = new TekGrid({
|
|
285
|
+
name: 'grid_filterClick5',
|
|
286
|
+
component: 'TekGrid',
|
|
287
|
+
columns: [
|
|
288
|
+
{
|
|
289
|
+
name: 'id',
|
|
290
|
+
filterable: true,
|
|
291
|
+
filterProps: [{
|
|
292
|
+
name: 'id_edit', label: 'id', component: 'ZdSelectMultiple', showCheckboxAll: false,
|
|
293
|
+
}],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
299
|
+
let select: ISelectMultiple = { name: 'select', component: 'ZdSelectMultiple' };
|
|
300
|
+
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
301
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
302
|
+
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
303
|
+
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
304
|
+
select = getChild(form.children || [], `${instance.name}-filter-AND-CONTAINS-id-0`);
|
|
305
|
+
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
306
|
+
|
|
307
|
+
return new Modal(modal);
|
|
308
|
+
});
|
|
309
|
+
instance.onCreated();
|
|
310
|
+
clickOnFilterButton(instance);
|
|
311
|
+
const applyButtonObject = new Button(applyButton);
|
|
312
|
+
|
|
313
|
+
const formObject = new Form(form);
|
|
314
|
+
const selectObject = new SelectMultiple(select);
|
|
315
|
+
jest.spyOn(Metadata, 'getInstance').mockReturnValue(formObject);
|
|
316
|
+
jest.spyOn(formObject, 'getChildInstance').mockReturnValue(selectObject);
|
|
317
|
+
|
|
318
|
+
formObject.value['grid_filterClick5-filter-AND-CONTAINS-id-0'] = ['example'];
|
|
319
|
+
setClick(applyButtonObject);
|
|
320
|
+
|
|
321
|
+
expect(instance.datasource.filter).toEqual({});
|
|
322
|
+
|
|
323
|
+
selectObject.checkboxAll = true;
|
|
324
|
+
setClick(applyButtonObject);
|
|
325
|
+
|
|
326
|
+
expect(instance.datasource.filter).toEqual({});
|
|
327
|
+
|
|
328
|
+
(Config as any).set({ selectAllCompatibilityMode: true });
|
|
329
|
+
setClick(applyButtonObject);
|
|
330
|
+
expect(instance.datasource.filter).toEqual({});
|
|
331
|
+
|
|
332
|
+
spy.mockReset();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('should create modal with filterable and ordered form elements', () => {
|
|
336
|
+
const instance = new TekGrid({
|
|
337
|
+
name: 'grid-filter-order',
|
|
338
|
+
component: 'TekGrid',
|
|
339
|
+
columns: [
|
|
340
|
+
{ name: 'id' },
|
|
341
|
+
{
|
|
342
|
+
name: 'first_name',
|
|
343
|
+
filterable: true,
|
|
344
|
+
filterProps: [{ name: 'first_name_edit', label: 'first_name' }],
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: 'last_name',
|
|
348
|
+
filterable: true,
|
|
349
|
+
filterIndex: 1,
|
|
350
|
+
filterProps: [{ name: 'last_name_edit', label: 'last_name' }],
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: 'dob',
|
|
354
|
+
filterable: true,
|
|
355
|
+
filterIndex: 0,
|
|
356
|
+
filterProps: [{ name: 'dob_edit', label: 'dob' }],
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
let formElements: any = [];
|
|
362
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
363
|
+
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
364
|
+
formElements = form.children;
|
|
365
|
+
|
|
366
|
+
return new Modal(modal);
|
|
367
|
+
});
|
|
368
|
+
instance.onCreated();
|
|
369
|
+
|
|
370
|
+
clickOnFilterButton(instance);
|
|
371
|
+
|
|
372
|
+
expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
|
|
373
|
+
expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
|
|
374
|
+
expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
|
|
375
|
+
|
|
376
|
+
spy.mockReset();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('should create modal with filterable form elements and TekRestDatasource', () => {
|
|
380
|
+
const instance = new TekGrid({
|
|
381
|
+
name: 'grid_filterClick6',
|
|
382
|
+
component: 'TekGrid',
|
|
383
|
+
datasource: {
|
|
384
|
+
type: 'tek-rest',
|
|
385
|
+
lazyLoad: true,
|
|
386
|
+
},
|
|
387
|
+
columns: [
|
|
388
|
+
{
|
|
389
|
+
name: 'id',
|
|
390
|
+
filterProps: [{ name: 'id_edit' }],
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: 'name',
|
|
394
|
+
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
395
|
+
filterProps: [{
|
|
396
|
+
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
397
|
+
}],
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
let formElements: any = [];
|
|
403
|
+
let form: IForm;
|
|
404
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
405
|
+
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
406
|
+
formElements = form.children;
|
|
407
|
+
|
|
408
|
+
return new Modal(modal);
|
|
409
|
+
});
|
|
410
|
+
instance.onCreated();
|
|
411
|
+
|
|
412
|
+
clickOnFilterButton(instance);
|
|
413
|
+
|
|
414
|
+
expect(formElements[0].name).toBe('grid_filterClick6-filter-AND-CONTAINS-id-0');
|
|
415
|
+
expect(formElements[1].name).toBe('grid_filterClick6-filter-OR-NOT_EQUALS-name-0');
|
|
416
|
+
expect(formElements[1].component).toBe('ZdSelect');
|
|
417
|
+
|
|
418
|
+
spy.mockReset();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('should create modal with helper component', () => {
|
|
422
|
+
const instance = new TekGrid({
|
|
423
|
+
name: 'grid_filterClick7',
|
|
424
|
+
component: 'TekGrid',
|
|
425
|
+
datasource: {
|
|
426
|
+
type: 'tek-rest',
|
|
427
|
+
lazyLoad: true,
|
|
428
|
+
},
|
|
429
|
+
columns: [
|
|
430
|
+
{
|
|
431
|
+
name: 'id',
|
|
432
|
+
filterProps: [{ name: 'id_edit' }],
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
name: 'date',
|
|
436
|
+
componentProps: { name: 'date_edit', component: 'ZdDate' },
|
|
437
|
+
filterProps: [
|
|
438
|
+
{
|
|
439
|
+
name: 'date_edit1',
|
|
440
|
+
label: 'date1',
|
|
441
|
+
operation: 'NOT_EQUALS',
|
|
442
|
+
relation: 'OR',
|
|
443
|
+
helperOptions: [
|
|
444
|
+
'TODAY',
|
|
445
|
+
'TOMORROW',
|
|
446
|
+
],
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
name: 'date_edit2',
|
|
450
|
+
label: 'date2',
|
|
451
|
+
showLabel: false,
|
|
452
|
+
operation: 'NOT_EQUALS',
|
|
453
|
+
relation: 'OR',
|
|
454
|
+
helperOptions: [
|
|
455
|
+
'TODAY',
|
|
456
|
+
'TOMORROW',
|
|
457
|
+
],
|
|
458
|
+
},
|
|
459
|
+
],
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
let formElements: any = [];
|
|
465
|
+
let form: IForm;
|
|
466
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
467
|
+
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
468
|
+
formElements = form.children;
|
|
469
|
+
|
|
470
|
+
return new Modal(modal);
|
|
471
|
+
});
|
|
472
|
+
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
473
|
+
|
|
474
|
+
instance.onCreated();
|
|
475
|
+
clickOnFilterButton(instance);
|
|
476
|
+
|
|
477
|
+
expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
|
|
478
|
+
expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
|
|
479
|
+
expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
|
|
480
|
+
|
|
481
|
+
spy.mockReset();
|
|
482
|
+
dateHelperSpy.mockReset();
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it('should apply helper value', () => {
|
|
486
|
+
const instance = new TekGrid({
|
|
487
|
+
name: 'grid_filterClick8',
|
|
488
|
+
component: 'TekGrid',
|
|
489
|
+
datasource: {
|
|
490
|
+
type: 'tek-rest',
|
|
491
|
+
lazyLoad: true,
|
|
492
|
+
},
|
|
493
|
+
columns: [
|
|
494
|
+
{
|
|
495
|
+
name: 'date1',
|
|
496
|
+
componentProps: { name: 'date_edit1', component: 'ZdDate' },
|
|
497
|
+
filterProps: {
|
|
498
|
+
name: 'date_edit1',
|
|
499
|
+
label: 'date1',
|
|
500
|
+
operation: 'NOT_EQUALS',
|
|
501
|
+
relation: 'OR',
|
|
502
|
+
helperOptions: [
|
|
503
|
+
'TODAY',
|
|
504
|
+
'TOMORROW',
|
|
505
|
+
],
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
name: 'date2',
|
|
510
|
+
componentProps: { name: 'date_edit2', component: 'ZdDate' },
|
|
511
|
+
filterProps: [
|
|
512
|
+
{
|
|
513
|
+
name: 'date_edit21',
|
|
514
|
+
label: 'date21',
|
|
515
|
+
operation: 'NOT_EQUALS',
|
|
516
|
+
relation: 'OR',
|
|
517
|
+
helperOptions: [
|
|
518
|
+
'TODAY',
|
|
519
|
+
'TOMORROW',
|
|
520
|
+
],
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
name: 'date_edit22',
|
|
524
|
+
label: 'date22',
|
|
525
|
+
helperOptions: [
|
|
526
|
+
'TODAY',
|
|
527
|
+
'TOMORROW',
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
let formElements: any = [];
|
|
536
|
+
let form: IForm;
|
|
537
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
538
|
+
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
539
|
+
formElements = form.children;
|
|
540
|
+
|
|
541
|
+
return new Modal(modal);
|
|
542
|
+
});
|
|
543
|
+
instance.onCreated();
|
|
544
|
+
clickOnFilterButton(instance);
|
|
545
|
+
|
|
546
|
+
const dateComp = new Date(formElements[0]);
|
|
547
|
+
dateComp.helperValue = 'TODAY';
|
|
548
|
+
dateComp.change({} as Event, {} as HTMLElement);
|
|
549
|
+
expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
|
|
550
|
+
|
|
551
|
+
const dateComp21 = new Date(formElements[1]);
|
|
552
|
+
dateComp21.helperValue = 'TODAY';
|
|
553
|
+
dateComp21.change({} as Event, {} as HTMLElement);
|
|
554
|
+
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
|
|
555
|
+
|
|
556
|
+
const dateComp22 = new Date(formElements[2]);
|
|
557
|
+
dateComp22.helperValue = 'TODAY';
|
|
558
|
+
dateComp22.change({} as Event, {} as HTMLElement);
|
|
559
|
+
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
|
|
560
|
+
|
|
561
|
+
spy.mockReset();
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it('should load form values from tekdatasource', () => {
|
|
565
|
+
const instance = new TekGrid({
|
|
566
|
+
name: 'grid_filterClick9',
|
|
567
|
+
component: 'TekGrid',
|
|
568
|
+
datasource: {
|
|
569
|
+
type: 'tek-rest',
|
|
570
|
+
lazyLoad: true,
|
|
571
|
+
dynamicFilter: {
|
|
572
|
+
name: [
|
|
573
|
+
{
|
|
574
|
+
operation: 'NOT_EQUALS',
|
|
575
|
+
relation: 'OR',
|
|
576
|
+
value: 'teste',
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
phone: [
|
|
580
|
+
{
|
|
581
|
+
value: '9',
|
|
582
|
+
},
|
|
583
|
+
],
|
|
584
|
+
date: [
|
|
585
|
+
{
|
|
586
|
+
operation: 'IN',
|
|
587
|
+
relation: 'OR',
|
|
588
|
+
value: ['2021-11-12', '2021-12-12'],
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
columns: [
|
|
594
|
+
{
|
|
595
|
+
name: 'id',
|
|
596
|
+
filterProps: [{ name: 'id_edit' }],
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
name: 'name',
|
|
600
|
+
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
601
|
+
filterProps: {
|
|
602
|
+
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
name: 'phone',
|
|
607
|
+
filterProps: [{ name: 'phone_edit' }],
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: 'date',
|
|
611
|
+
filterProps: { name: 'date_edit', helperValue: 'TODAY' },
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
617
|
+
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
618
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
619
|
+
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
620
|
+
|
|
621
|
+
return new Modal(modal);
|
|
622
|
+
});
|
|
623
|
+
instance.onCreated();
|
|
624
|
+
|
|
625
|
+
clickOnFilterButton(instance);
|
|
626
|
+
|
|
627
|
+
expect(form.name).toBe('grid_filterClick9-filter-form');
|
|
628
|
+
const formObject = new Form(form);
|
|
629
|
+
formObject.value = {
|
|
630
|
+
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
631
|
+
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': null,
|
|
632
|
+
'grid_filterClick9-filter-AND-CONTAINS-phone-0': null,
|
|
633
|
+
'grid_filterClick9-filter-OR-IN-date-0': null,
|
|
634
|
+
};
|
|
635
|
+
const dateObject = new Date({ name: 'date', component: 'ZdDate' });
|
|
636
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
|
|
637
|
+
formObject.onMounted({} as HTMLElement);
|
|
638
|
+
expect(formObject.value).toEqual({
|
|
639
|
+
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
640
|
+
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
641
|
+
'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
|
|
642
|
+
'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
|
|
643
|
+
});
|
|
644
|
+
expect(dateObject.hint).toBe('TODAY');
|
|
645
|
+
spyMetadata.mockReset();
|
|
646
|
+
dateHelperSpy.mockReset();
|
|
647
|
+
spy.mockReset();
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it('should load form values from datasource', () => {
|
|
651
|
+
const instance = new TekGrid({
|
|
652
|
+
name: 'grid_filterClick10',
|
|
653
|
+
component: 'TekGrid',
|
|
654
|
+
datasource: {
|
|
655
|
+
filter: {
|
|
656
|
+
id: '',
|
|
657
|
+
name: 'teste',
|
|
658
|
+
phone: '9',
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
columns: [
|
|
662
|
+
{
|
|
663
|
+
name: 'id',
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
name: 'name',
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
name: 'phone',
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
let formProps: IForm = {} as IForm;
|
|
675
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
676
|
+
formProps = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
677
|
+
|
|
678
|
+
return new Modal(modal);
|
|
679
|
+
});
|
|
680
|
+
instance.onCreated();
|
|
681
|
+
clickOnFilterButton(instance);
|
|
682
|
+
|
|
683
|
+
const formObject = new Form(formProps);
|
|
684
|
+
formObject.onMounted({} as HTMLElement);
|
|
685
|
+
|
|
686
|
+
expect(formObject.value).toEqual({
|
|
687
|
+
'grid_filterClick10-filter-AND-CONTAINS-name-0': 'teste',
|
|
688
|
+
'grid_filterClick10-filter-AND-CONTAINS-phone-0': '9',
|
|
689
|
+
});
|
|
690
|
+
spy.mockReset();
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it('should apply filter from form to tekdatasource', () => {
|
|
694
|
+
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
695
|
+
data: {
|
|
696
|
+
data: [
|
|
697
|
+
{ id: 1, name: 'employee 1', department: 1 },
|
|
698
|
+
{ id: 2, name: 'employee 2', department: 1 },
|
|
699
|
+
{ id: 3, name: 'employee 3', department: 1 },
|
|
700
|
+
{ id: 4, name: 'employee 4', department: 2 },
|
|
701
|
+
{ id: 5, name: 'employee 5', department: 2 },
|
|
702
|
+
],
|
|
703
|
+
pagination: {
|
|
704
|
+
page: 1,
|
|
705
|
+
total: 5,
|
|
706
|
+
limit: 15,
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
}));
|
|
710
|
+
const instance = new TekGrid({
|
|
711
|
+
name: 'grid_filterClick11',
|
|
712
|
+
component: 'TekGrid',
|
|
713
|
+
datasource: {
|
|
714
|
+
type: 'tek-rest',
|
|
715
|
+
},
|
|
716
|
+
columns: [
|
|
717
|
+
{
|
|
718
|
+
name: 'id',
|
|
719
|
+
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
name: 'name',
|
|
723
|
+
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
724
|
+
filterProps: [{
|
|
725
|
+
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
726
|
+
}],
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: 'phone',
|
|
730
|
+
filterProps: [{ name: 'phone_edit' }],
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
name: 'salary',
|
|
734
|
+
filterProps: [
|
|
735
|
+
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
736
|
+
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
737
|
+
],
|
|
738
|
+
},
|
|
739
|
+
],
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
743
|
+
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
744
|
+
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
745
|
+
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
746
|
+
|
|
747
|
+
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
748
|
+
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
749
|
+
|
|
750
|
+
return new Modal(modal);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
instance.onCreated();
|
|
754
|
+
|
|
755
|
+
const buttonProps = getChild<ITekGridFilterButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
756
|
+
const button = new TekGridFilterButton(buttonProps);
|
|
757
|
+
setClick(button);
|
|
758
|
+
|
|
759
|
+
const formObject = new Form(form);
|
|
760
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
761
|
+
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
762
|
+
formObject.value = {
|
|
763
|
+
'grid_filterClick11-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
764
|
+
'grid_filterClick11-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
765
|
+
'grid_filterClick11-filter-AND-CONTAINS-phone-0': '',
|
|
766
|
+
'grid_filterClick11-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
767
|
+
'grid_filterClick11-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
768
|
+
};
|
|
769
|
+
const applyButtonObject = new Button(applyButton);
|
|
770
|
+
formObject.validate = () => false;
|
|
771
|
+
setClick(applyButtonObject);
|
|
772
|
+
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({});
|
|
773
|
+
|
|
774
|
+
formObject.validate = () => true;
|
|
775
|
+
setClick(applyButtonObject);
|
|
776
|
+
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({
|
|
777
|
+
id: [
|
|
778
|
+
{
|
|
779
|
+
operation: 'IN',
|
|
780
|
+
relation: 'AND',
|
|
781
|
+
value: ['1', '2', '3'],
|
|
782
|
+
},
|
|
783
|
+
],
|
|
784
|
+
name: [
|
|
785
|
+
{
|
|
786
|
+
operation: 'NOT_EQUALS',
|
|
787
|
+
relation: 'OR',
|
|
788
|
+
value: 'teste',
|
|
789
|
+
},
|
|
790
|
+
],
|
|
791
|
+
salary: [
|
|
792
|
+
{
|
|
793
|
+
operation: 'GREATER_THAN_EQUALS',
|
|
794
|
+
relation: 'AND',
|
|
795
|
+
value: '1000',
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
operation: 'LESS_THAN_EQUALS',
|
|
799
|
+
relation: 'AND',
|
|
800
|
+
value: '2000',
|
|
801
|
+
},
|
|
802
|
+
],
|
|
803
|
+
});
|
|
804
|
+
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
|
|
805
|
+
expect(spyDatasourceGet).toBeCalled();
|
|
806
|
+
spyMetadata.mockReset();
|
|
807
|
+
spyDatasourceGet.mockReset();
|
|
808
|
+
spyModalService.mockReset();
|
|
809
|
+
httpSpy.mockReset();
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
it('should clear data from form', () => {
|
|
813
|
+
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
814
|
+
data: {
|
|
815
|
+
data: [
|
|
816
|
+
{ id: 1, name: 'employee 1', department: 1 },
|
|
817
|
+
{ id: 2, name: 'employee 2', department: 1 },
|
|
818
|
+
{ id: 3, name: 'employee 3', department: 1 },
|
|
819
|
+
{ id: 4, name: 'employee 4', department: 2 },
|
|
820
|
+
{ id: 5, name: 'employee 5', department: 2 },
|
|
821
|
+
],
|
|
822
|
+
pagination: {
|
|
823
|
+
page: 1,
|
|
824
|
+
total: 5,
|
|
825
|
+
limit: 15,
|
|
826
|
+
},
|
|
827
|
+
},
|
|
828
|
+
}));
|
|
829
|
+
const instance = new TekGrid({
|
|
830
|
+
name: 'grid_filterClick12',
|
|
831
|
+
component: 'TekGrid',
|
|
832
|
+
datasource: {
|
|
833
|
+
type: 'tek-rest',
|
|
834
|
+
},
|
|
835
|
+
columns: [
|
|
836
|
+
{
|
|
837
|
+
name: 'id',
|
|
838
|
+
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
name: 'name',
|
|
842
|
+
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
843
|
+
filterProps: [{
|
|
844
|
+
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
845
|
+
}],
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
name: 'phone',
|
|
849
|
+
filterProps: [{ name: 'phone_edit' }],
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
name: 'salary',
|
|
853
|
+
filterProps: [
|
|
854
|
+
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
855
|
+
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
856
|
+
],
|
|
857
|
+
},
|
|
858
|
+
],
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
862
|
+
let clearButton: IButton = { name: 'clear', component: 'ZdButton' };
|
|
863
|
+
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
864
|
+
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
865
|
+
|
|
866
|
+
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
867
|
+
clearButton = getChild(modalFooter.leftSlot, `${instance.name}-filter-clearButton`);
|
|
868
|
+
|
|
869
|
+
return new Modal(modal);
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
instance.onCreated();
|
|
873
|
+
|
|
874
|
+
const buttonProps = getChild<ITekGridFilterButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
875
|
+
const button = new TekGridFilterButton(buttonProps);
|
|
876
|
+
setClick(button);
|
|
877
|
+
|
|
878
|
+
const formObject = new Form(form);
|
|
879
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
880
|
+
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
881
|
+
formObject.value = {
|
|
882
|
+
'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
883
|
+
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
884
|
+
'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
|
|
885
|
+
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
886
|
+
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
887
|
+
};
|
|
888
|
+
const clearButtonObject = new Button(clearButton);
|
|
889
|
+
setClick(clearButtonObject);
|
|
890
|
+
expect(formObject.value).toEqual({
|
|
891
|
+
'grid_filterClick12-filter-AND-IN-id-0': null,
|
|
892
|
+
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
|
|
893
|
+
'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
|
|
894
|
+
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
|
|
895
|
+
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
|
|
896
|
+
});
|
|
897
|
+
spyMetadata.mockReset();
|
|
898
|
+
spyDatasourceGet.mockReset();
|
|
899
|
+
spyModalService.mockReset();
|
|
900
|
+
httpSpy.mockReset();
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
it('should apply filter from form to datasource', () => {
|
|
904
|
+
let beforeApplyFilterCalled = false;
|
|
905
|
+
let changeLayoutCalled = false;
|
|
906
|
+
const instance = new TekGrid({
|
|
907
|
+
name: 'grid_filterClick13',
|
|
908
|
+
component: 'TekGrid',
|
|
909
|
+
columns: [
|
|
910
|
+
{
|
|
911
|
+
name: 'id',
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
name: 'name',
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
name: 'phone',
|
|
918
|
+
},
|
|
919
|
+
{
|
|
920
|
+
name: 'salary',
|
|
921
|
+
},
|
|
922
|
+
],
|
|
923
|
+
events: {
|
|
924
|
+
beforeApplyFilter: () => { beforeApplyFilterCalled = true; },
|
|
925
|
+
changeLayout: () => { changeLayoutCalled = true; },
|
|
926
|
+
},
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
930
|
+
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
931
|
+
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
932
|
+
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
933
|
+
|
|
934
|
+
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
935
|
+
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
936
|
+
|
|
937
|
+
return new Modal(modal);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
instance.onCreated();
|
|
941
|
+
|
|
942
|
+
clickOnFilterButton(instance);
|
|
943
|
+
|
|
944
|
+
const formObject = new Form(form);
|
|
945
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
946
|
+
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
947
|
+
formObject.value = {
|
|
948
|
+
'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
|
|
949
|
+
'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
|
|
950
|
+
'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
|
|
951
|
+
'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
|
|
952
|
+
};
|
|
953
|
+
const applyButtonObject = new Button(applyButton);
|
|
954
|
+
setClick(applyButtonObject);
|
|
955
|
+
expect(instance.datasource.filter).toEqual({});
|
|
956
|
+
expect(beforeApplyFilterCalled).toBeTruthy();
|
|
957
|
+
expect(changeLayoutCalled).toBeTruthy();
|
|
958
|
+
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBe(undefined);
|
|
959
|
+
|
|
960
|
+
setClick(applyButtonObject, { defaultPrevented: true });
|
|
961
|
+
expect(spyDatasourceGet).toBeCalledTimes(1);
|
|
962
|
+
spyMetadata.mockReset();
|
|
963
|
+
spyDatasourceGet.mockReset();
|
|
964
|
+
spyModalService.mockReset();
|
|
965
|
+
});
|
|
966
|
+
});
|
|
967
|
+
});
|