@zeedhi/teknisa-components-common 1.40.0 → 1.44.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/coverage/clover.xml +851 -749
- package/coverage/coverage-final.json +31 -30
- package/coverage/lcov-report/index.html +39 -25
- package/coverage/lcov.info +1566 -1353
- package/dist/tek-components-common.esm.js +281 -29
- package/dist/tek-components-common.umd.js +280 -27
- package/package.json +2 -2
- package/tests/unit/components/tek-grid/grid.spec.ts +446 -7
- package/tests/unit/components/tek-grid/layout_options.spec.ts +156 -2
- package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +9 -0
- package/tests/unit/components/tek-loading/Loading.spec.ts +30 -0
- package/tests/unit/components/tek-product-card/product-card.spec.ts +9 -0
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +159 -2
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +106 -3
- package/types/components/index.d.ts +2 -0
- package/types/components/tek-datasource/memory-datasource.d.ts +4 -2
- package/types/components/tek-grid/grid-column.d.ts +4 -1
- package/types/components/tek-grid/grid.d.ts +10 -0
- package/types/components/tek-grid/interfaces.d.ts +6 -3
- package/types/components/tek-grid/layout-options.d.ts +4 -1
- package/types/components/tek-iterable-component-render/interfaces.d.ts +3 -0
- package/types/components/tek-iterable-component-render/iterable-component-render.d.ts +12 -0
- package/types/components/tek-loading/interfaces.d.ts +6 -0
- package/types/components/tek-loading/loading.d.ts +24 -0
- package/types/components/tek-product-card/interfaces.d.ts +3 -0
- package/types/components/tek-product-card/product-card.d.ts +12 -0
- package/types/components/tek-tree-grid/interfaces.d.ts +3 -1
- package/types/components/tek-tree-grid/tree-grid.d.ts +6 -0
- package/types/utils/grid-base/grid-base.d.ts +42 -34
- package/types/utils/grid-base/grid-controller.d.ts +7 -3
- package/types/utils/index.d.ts +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Button, Date, Form, IButton, IForm, IModal, Modal, ModalService, Text,
|
|
4
|
+
Button, Date, Dropdown, Form, IButton, IForm, IModal, Modal, ModalService, Search, Text, TextInput,
|
|
5
5
|
} from '@zeedhi/common';
|
|
6
6
|
import {
|
|
7
|
-
KeyMap, Http, Metadata, dayjs, Config,
|
|
7
|
+
KeyMap, Http, Metadata, dayjs, Config, IDictionary,
|
|
8
8
|
} from '@zeedhi/core';
|
|
9
9
|
import {
|
|
10
10
|
ITekGrid,
|
|
@@ -31,6 +31,7 @@ describe('TekGrid', () => {
|
|
|
31
31
|
expect(instance.dragColumns).toBeTruthy();
|
|
32
32
|
expect(instance.resizeColumns).toBeTruthy();
|
|
33
33
|
expect(instance.showLayoutOptions).toBeTruthy();
|
|
34
|
+
expect(instance.showSearch).toBeTruthy();
|
|
34
35
|
expect(instance.showSummaryTotal).toBeTruthy();
|
|
35
36
|
expect(instance.showReload).toBeTruthy();
|
|
36
37
|
expect(instance.columnsButton).toBeFalsy();
|
|
@@ -49,6 +50,7 @@ describe('TekGrid', () => {
|
|
|
49
50
|
dragColumns: false,
|
|
50
51
|
resizeColumns: false,
|
|
51
52
|
showLayoutOptions: false,
|
|
53
|
+
showSearch: false,
|
|
52
54
|
showSummaryTotal: false,
|
|
53
55
|
showReload: false,
|
|
54
56
|
columns: [
|
|
@@ -65,6 +67,7 @@ describe('TekGrid', () => {
|
|
|
65
67
|
expect(instance.dragColumns).toBeFalsy();
|
|
66
68
|
expect(instance.resizeColumns).toBeFalsy();
|
|
67
69
|
expect(instance.showLayoutOptions).toBeFalsy();
|
|
70
|
+
expect(instance.showSearch).toBeFalsy();
|
|
68
71
|
expect(instance.showSummaryTotal).toBeFalsy();
|
|
69
72
|
expect(instance.showReload).toBeFalsy();
|
|
70
73
|
expect(instance.columns[0]).toBeInstanceOf(TekGridColumn);
|
|
@@ -656,6 +659,114 @@ describe('TekGrid', () => {
|
|
|
656
659
|
done();
|
|
657
660
|
}, 1000);
|
|
658
661
|
});
|
|
662
|
+
|
|
663
|
+
it('should open filter modal input with keymap', async () => {
|
|
664
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
665
|
+
const instance = new TekGrid({
|
|
666
|
+
name: 'grid_navigation_2',
|
|
667
|
+
component: 'TekGrid',
|
|
668
|
+
filterButton: true,
|
|
669
|
+
});
|
|
670
|
+
const elem = document.createElement('DIV');
|
|
671
|
+
|
|
672
|
+
(KeyMap as any).isElementActive = () => true;
|
|
673
|
+
|
|
674
|
+
instance.onMounted(elem);
|
|
675
|
+
await flushPromises();
|
|
676
|
+
|
|
677
|
+
const method = jest.fn();
|
|
678
|
+
|
|
679
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => new Button({
|
|
680
|
+
name: 'grid_navigation_2_filterButton',
|
|
681
|
+
component: 'ZdButton',
|
|
682
|
+
events: {
|
|
683
|
+
click: method,
|
|
684
|
+
},
|
|
685
|
+
}));
|
|
686
|
+
|
|
687
|
+
dispatchEvent(76, { ctrlKey: true }); // ctrl+l keydown
|
|
688
|
+
await flushPromises();
|
|
689
|
+
|
|
690
|
+
instance.onBeforeDestroy();
|
|
691
|
+
await flushPromises();
|
|
692
|
+
|
|
693
|
+
expect(method).toHaveBeenCalled();
|
|
694
|
+
(KeyMap as any).isElementActive = () => false;
|
|
695
|
+
spyMetadata.mockClear();
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it('should open action dropdown with keymap', async () => {
|
|
699
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
700
|
+
const instance = new TekGrid({
|
|
701
|
+
name: 'grid_navigation_2',
|
|
702
|
+
component: 'TekGrid',
|
|
703
|
+
});
|
|
704
|
+
const elem = document.createElement('DIV');
|
|
705
|
+
|
|
706
|
+
(KeyMap as any).isElementActive = () => true;
|
|
707
|
+
|
|
708
|
+
instance.onMounted(elem);
|
|
709
|
+
await flushPromises();
|
|
710
|
+
|
|
711
|
+
const instanceDropDown = new Dropdown({
|
|
712
|
+
name: 'grid_navigation_2_actions_dropdown',
|
|
713
|
+
component: 'ZdDropdown',
|
|
714
|
+
activator: {
|
|
715
|
+
name: 'grid_navigation_2_actionsButton',
|
|
716
|
+
component: 'ZdButton',
|
|
717
|
+
},
|
|
718
|
+
children: [],
|
|
719
|
+
});
|
|
720
|
+
const instanceDropDownSpy = jest.spyOn(instanceDropDown, 'setFocus').mockImplementation(() => true);
|
|
721
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => instanceDropDown);
|
|
722
|
+
|
|
723
|
+
dispatchEvent(13, { ctrlKey: true, enterKey: true }); // ctrl + enter keydown
|
|
724
|
+
await flushPromises();
|
|
725
|
+
|
|
726
|
+
expect(spyMetadata).toHaveBeenCalled();
|
|
727
|
+
expect(instanceDropDownSpy).toHaveBeenCalled();
|
|
728
|
+
|
|
729
|
+
instance.onBeforeDestroy();
|
|
730
|
+
await flushPromises();
|
|
731
|
+
|
|
732
|
+
(KeyMap as any).isElementActive = () => false;
|
|
733
|
+
spyMetadata.mockClear();
|
|
734
|
+
instanceDropDownSpy.mockClear();
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it('should focus in searchInput with keymap', async () => {
|
|
738
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
739
|
+
const instance = new TekGrid({
|
|
740
|
+
name: 'grid_navigation_3',
|
|
741
|
+
component: 'TekGrid',
|
|
742
|
+
});
|
|
743
|
+
const elem = document.createElement('DIV');
|
|
744
|
+
|
|
745
|
+
(KeyMap as any).isElementActive = () => true;
|
|
746
|
+
instance.onMounted(elem);
|
|
747
|
+
await flushPromises();
|
|
748
|
+
|
|
749
|
+
const searchInput = new Search({
|
|
750
|
+
name: 'grid_navigation_3_gridSearch',
|
|
751
|
+
component: 'ZdSearch',
|
|
752
|
+
parent: instance,
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
const spySetFocus = jest.spyOn(searchInput, 'setFocus').mockImplementation(() => true);
|
|
756
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => searchInput);
|
|
757
|
+
|
|
758
|
+
dispatchEvent(70, { ctrlKey: true }); // ctrl+f keydown
|
|
759
|
+
await flushPromises();
|
|
760
|
+
|
|
761
|
+
expect(spySetFocus).toHaveBeenCalled();
|
|
762
|
+
|
|
763
|
+
instance.onBeforeDestroy();
|
|
764
|
+
await flushPromises();
|
|
765
|
+
|
|
766
|
+
(KeyMap as any).isElementActive = () => false;
|
|
767
|
+
spySetFocus.mockClear();
|
|
768
|
+
spyMetadata.mockClear();
|
|
769
|
+
});
|
|
659
770
|
});
|
|
660
771
|
|
|
661
772
|
describe('reloadClick()', () => {
|
|
@@ -1328,6 +1439,50 @@ describe('TekGrid', () => {
|
|
|
1328
1439
|
done();
|
|
1329
1440
|
}, 1000);
|
|
1330
1441
|
});
|
|
1442
|
+
|
|
1443
|
+
it('should call debounced updateGroupData', async (done) => {
|
|
1444
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
1445
|
+
const instance = new TekGrid({
|
|
1446
|
+
name: 'grid_grouping_1',
|
|
1447
|
+
component: 'TekGrid',
|
|
1448
|
+
columns: [
|
|
1449
|
+
{
|
|
1450
|
+
name: 'id',
|
|
1451
|
+
label: 'id',
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
name: 'name',
|
|
1455
|
+
label: 'name',
|
|
1456
|
+
},
|
|
1457
|
+
{
|
|
1458
|
+
name: 'department',
|
|
1459
|
+
label: 'department',
|
|
1460
|
+
grouped: true,
|
|
1461
|
+
},
|
|
1462
|
+
],
|
|
1463
|
+
datasource: {
|
|
1464
|
+
uniqueKey: 'id',
|
|
1465
|
+
order: ['name.asc'],
|
|
1466
|
+
data: [
|
|
1467
|
+
{ id: 2, name: 'employee 2', department: 1 },
|
|
1468
|
+
{ id: 5, name: 'employee 5', department: 2 },
|
|
1469
|
+
{ id: 4, name: 'employee 4', department: 2 },
|
|
1470
|
+
{ id: 3, name: 'employee 3', department: 1 },
|
|
1471
|
+
{ id: 1, name: 'employee 1', department: 1 },
|
|
1472
|
+
],
|
|
1473
|
+
},
|
|
1474
|
+
});
|
|
1475
|
+
|
|
1476
|
+
await flushPromises();
|
|
1477
|
+
|
|
1478
|
+
instance.updateGroupedData = jest.fn();
|
|
1479
|
+
instance.columns[2].groupOpened = true;
|
|
1480
|
+
|
|
1481
|
+
setTimeout(() => {
|
|
1482
|
+
expect(instance.updateGroupedData).toBeCalled();
|
|
1483
|
+
done();
|
|
1484
|
+
}, 1000);
|
|
1485
|
+
});
|
|
1331
1486
|
});
|
|
1332
1487
|
|
|
1333
1488
|
describe('filterClick()', () => {
|
|
@@ -1456,6 +1611,54 @@ describe('TekGrid', () => {
|
|
|
1456
1611
|
spy.mockClear();
|
|
1457
1612
|
});
|
|
1458
1613
|
|
|
1614
|
+
it('should create modal with filterable and ordered form elements', () => {
|
|
1615
|
+
const instance = new TekGrid({
|
|
1616
|
+
name: 'grid-filter-order',
|
|
1617
|
+
component: 'TekGrid',
|
|
1618
|
+
columns: [
|
|
1619
|
+
{ name: 'id' },
|
|
1620
|
+
{
|
|
1621
|
+
name: 'first_name',
|
|
1622
|
+
filterable: true,
|
|
1623
|
+
filterProps: [{ name: 'first_name_edit', label: 'first_name' }],
|
|
1624
|
+
},
|
|
1625
|
+
{
|
|
1626
|
+
name: 'last_name',
|
|
1627
|
+
filterable: true,
|
|
1628
|
+
filterIndex: 1,
|
|
1629
|
+
filterProps: [{ name: 'last_name_edit', label: 'last_name' }],
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
name: 'dob',
|
|
1633
|
+
filterable: true,
|
|
1634
|
+
filterIndex: 0,
|
|
1635
|
+
filterProps: [{ name: 'dob_edit', label: 'dob' }],
|
|
1636
|
+
},
|
|
1637
|
+
],
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
let formElements: any = [];
|
|
1641
|
+
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1642
|
+
if (modal.children && modal.children.length > 1) {
|
|
1643
|
+
const form = modal.children[1];
|
|
1644
|
+
formElements = form.children;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
return new Modal(modal);
|
|
1648
|
+
});
|
|
1649
|
+
instance.onCreated();
|
|
1650
|
+
const filterTooltip = instance.toolbarSlot[6];
|
|
1651
|
+
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
1652
|
+
const button = new Button(filterTooltip.children[0]);
|
|
1653
|
+
const event = new Event('click');
|
|
1654
|
+
button.click(event, {} as HTMLElement);
|
|
1655
|
+
expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
|
|
1656
|
+
expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
|
|
1657
|
+
expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
|
|
1658
|
+
}
|
|
1659
|
+
spy.mockClear();
|
|
1660
|
+
});
|
|
1661
|
+
|
|
1459
1662
|
it('should create modal with filterable form elements and TekRestDatasource', () => {
|
|
1460
1663
|
const instance = new TekGrid({
|
|
1461
1664
|
name: 'grid_filterClick6',
|
|
@@ -1985,11 +2188,90 @@ describe('TekGrid', () => {
|
|
|
1985
2188
|
spyModalService.mockClear();
|
|
1986
2189
|
});
|
|
1987
2190
|
|
|
2191
|
+
it('should clear data from form', () => {
|
|
2192
|
+
const instance = new TekGrid({
|
|
2193
|
+
name: 'grid_filterClick12',
|
|
2194
|
+
component: 'TekGrid',
|
|
2195
|
+
datasource: {
|
|
2196
|
+
type: 'tek-rest',
|
|
2197
|
+
},
|
|
2198
|
+
columns: [
|
|
2199
|
+
{
|
|
2200
|
+
name: 'id',
|
|
2201
|
+
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
2202
|
+
},
|
|
2203
|
+
{
|
|
2204
|
+
name: 'name',
|
|
2205
|
+
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
2206
|
+
filterProps: [{
|
|
2207
|
+
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
2208
|
+
}],
|
|
2209
|
+
},
|
|
2210
|
+
{
|
|
2211
|
+
name: 'phone',
|
|
2212
|
+
filterProps: [{ name: 'phone_edit' }],
|
|
2213
|
+
},
|
|
2214
|
+
{
|
|
2215
|
+
name: 'salary',
|
|
2216
|
+
filterProps: [
|
|
2217
|
+
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
2218
|
+
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
2219
|
+
],
|
|
2220
|
+
},
|
|
2221
|
+
],
|
|
2222
|
+
});
|
|
2223
|
+
|
|
2224
|
+
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
2225
|
+
let clearButton: IButton = { name: 'clear', component: 'ZdButton' };
|
|
2226
|
+
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2227
|
+
if (modal.children && modal.children.length > 2) {
|
|
2228
|
+
form = modal.children[1] as IForm;
|
|
2229
|
+
const modalFooter = modal.children[2];
|
|
2230
|
+
if (modalFooter.leftSlot && modalFooter.leftSlot.length > 0) {
|
|
2231
|
+
clearButton = modalFooter.leftSlot[0] as IButton;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
return new Modal(modal);
|
|
2236
|
+
});
|
|
2237
|
+
|
|
2238
|
+
instance.onCreated();
|
|
2239
|
+
|
|
2240
|
+
const filterTooltip = instance.toolbarSlot[6];
|
|
2241
|
+
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
2242
|
+
const button = new Button(filterTooltip.children[0]);
|
|
2243
|
+
const event = new Event('click');
|
|
2244
|
+
button.click(event, {} as HTMLElement);
|
|
2245
|
+
const formObject = new Form(form);
|
|
2246
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
2247
|
+
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
2248
|
+
formObject.value = {
|
|
2249
|
+
'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
2250
|
+
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
2251
|
+
'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
|
|
2252
|
+
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
2253
|
+
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
2254
|
+
};
|
|
2255
|
+
const clearButtonObject = new Button(clearButton);
|
|
2256
|
+
clearButtonObject.click(event, {} as HTMLElement);
|
|
2257
|
+
expect(formObject.value).toEqual({
|
|
2258
|
+
'grid_filterClick12-filter-AND-IN-id-0': null,
|
|
2259
|
+
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
|
|
2260
|
+
'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
|
|
2261
|
+
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
|
|
2262
|
+
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
|
|
2263
|
+
});
|
|
2264
|
+
spyMetadata.mockClear();
|
|
2265
|
+
spyDatasourceGet.mockClear();
|
|
2266
|
+
}
|
|
2267
|
+
spyModalService.mockClear();
|
|
2268
|
+
});
|
|
2269
|
+
|
|
1988
2270
|
it('should apply filter from form to datasource', () => {
|
|
1989
2271
|
let beforeApplyFilterCalled = false;
|
|
1990
2272
|
let changeLayoutCalled = false;
|
|
1991
2273
|
const instance = new TekGrid({
|
|
1992
|
-
name: '
|
|
2274
|
+
name: 'grid_filterClick13',
|
|
1993
2275
|
component: 'TekGrid',
|
|
1994
2276
|
columns: [
|
|
1995
2277
|
{
|
|
@@ -2036,10 +2318,10 @@ describe('TekGrid', () => {
|
|
|
2036
2318
|
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
2037
2319
|
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
2038
2320
|
formObject.value = {
|
|
2039
|
-
'
|
|
2040
|
-
'
|
|
2041
|
-
'
|
|
2042
|
-
'
|
|
2321
|
+
'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
|
|
2322
|
+
'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
|
|
2323
|
+
'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
|
|
2324
|
+
'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
|
|
2043
2325
|
};
|
|
2044
2326
|
const applyButtonObject = new Button(applyButton);
|
|
2045
2327
|
applyButtonObject.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
@@ -2425,4 +2707,161 @@ describe('TekGrid', () => {
|
|
|
2425
2707
|
expect(groupUnselected).toHaveBeenCalled();
|
|
2426
2708
|
});
|
|
2427
2709
|
});
|
|
2710
|
+
|
|
2711
|
+
describe('layoutOptions', () => {
|
|
2712
|
+
it('should return layout options instance', async () => {
|
|
2713
|
+
const grid = new TekGrid({
|
|
2714
|
+
name: 'grid',
|
|
2715
|
+
component: 'TekGrid',
|
|
2716
|
+
showLayoutOptions: false,
|
|
2717
|
+
});
|
|
2718
|
+
|
|
2719
|
+
expect(grid.layoutOptions).toBeUndefined();
|
|
2720
|
+
|
|
2721
|
+
grid.showLayoutOptions = true;
|
|
2722
|
+
const layoutOptionsComp = { name: 'grid_layout_options' };
|
|
2723
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => layoutOptionsComp);
|
|
2724
|
+
expect(grid.layoutOptions).toEqual(layoutOptionsComp);
|
|
2725
|
+
spyMetadata.mockClear();
|
|
2726
|
+
});
|
|
2727
|
+
});
|
|
2728
|
+
|
|
2729
|
+
describe('getAtomInstance', () => {
|
|
2730
|
+
const createAtom = (name: string) => new Text({
|
|
2731
|
+
name: `${name}_gridTitle`,
|
|
2732
|
+
component: 'ZdText',
|
|
2733
|
+
text: 'Employees',
|
|
2734
|
+
});
|
|
2735
|
+
|
|
2736
|
+
it('when called, should return the instance of an atom component', () => {
|
|
2737
|
+
const instance = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
2738
|
+
const atom = createAtom(instance.name);
|
|
2739
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => atom);
|
|
2740
|
+
|
|
2741
|
+
const gridAtom = instance.getAtomInstance<Text>('TITLE');
|
|
2742
|
+
|
|
2743
|
+
expect(gridAtom).toEqual(atom);
|
|
2744
|
+
spyMetadata.mockClear();
|
|
2745
|
+
});
|
|
2746
|
+
});
|
|
2747
|
+
|
|
2748
|
+
describe('getFilterInputs', () => {
|
|
2749
|
+
const mockMetadata = (instance: TekGrid) => {
|
|
2750
|
+
const inputs: IDictionary = {};
|
|
2751
|
+
instance.columns.forEach((col) => {
|
|
2752
|
+
if (!col.filterable || !col.filterProps) return;
|
|
2753
|
+
|
|
2754
|
+
col.filterProps.forEach((filter: any, index: number) => {
|
|
2755
|
+
const relation = filter.relation || 'AND';
|
|
2756
|
+
const operation = filter.operation || 'CONTAINS';
|
|
2757
|
+
|
|
2758
|
+
const name = `${instance.name}-filter-${relation}-${operation}-${col.name}-${index}`;
|
|
2759
|
+
inputs[name] = new TextInput({
|
|
2760
|
+
name,
|
|
2761
|
+
...filter.filterProps,
|
|
2762
|
+
});
|
|
2763
|
+
});
|
|
2764
|
+
});
|
|
2765
|
+
return jest.spyOn(Metadata, 'getInstance').mockImplementation((name: string) => inputs[name]);
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
it('when called with null parameter, should return all the filter inputs', () => {
|
|
2769
|
+
const instance = new TekGrid({
|
|
2770
|
+
name: 'grid',
|
|
2771
|
+
component: 'TekGrid',
|
|
2772
|
+
datasource: {
|
|
2773
|
+
type: 'tek-rest',
|
|
2774
|
+
uniqueKey: 'id',
|
|
2775
|
+
route: '/zeedhi',
|
|
2776
|
+
lazyLoad: false,
|
|
2777
|
+
},
|
|
2778
|
+
columns: [
|
|
2779
|
+
{ name: 'id' },
|
|
2780
|
+
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
2781
|
+
{
|
|
2782
|
+
name: 'salary',
|
|
2783
|
+
filterable: true,
|
|
2784
|
+
filterProps: [
|
|
2785
|
+
{
|
|
2786
|
+
name: 'salary_edit',
|
|
2787
|
+
component: 'ZdCurrency',
|
|
2788
|
+
operation: 'GREATER_THAN_EQUALS',
|
|
2789
|
+
label: 'Salary (min)',
|
|
2790
|
+
},
|
|
2791
|
+
{
|
|
2792
|
+
name: 'salary_edit',
|
|
2793
|
+
component: 'ZdCurrency',
|
|
2794
|
+
operation: 'LESS_THAN_EQUALS',
|
|
2795
|
+
label: 'Salary (max)',
|
|
2796
|
+
},
|
|
2797
|
+
],
|
|
2798
|
+
},
|
|
2799
|
+
],
|
|
2800
|
+
});
|
|
2801
|
+
|
|
2802
|
+
const spy = mockMetadata(instance);
|
|
2803
|
+
instance.onCreated();
|
|
2804
|
+
const filterTooltip = instance.toolbarSlot[6];
|
|
2805
|
+
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
2806
|
+
const button = new Button(filterTooltip.children[0]);
|
|
2807
|
+
const event = new Event('click');
|
|
2808
|
+
button.click(event, {} as HTMLElement);
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
const inputs = instance.getFilterInputs();
|
|
2812
|
+
expect(inputs[0].name).toBe('grid-filter-AND-CONTAINS-name-0');
|
|
2813
|
+
expect(inputs[1].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
|
|
2814
|
+
expect(inputs[2].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
|
|
2815
|
+
spy.mockClear();
|
|
2816
|
+
});
|
|
2817
|
+
|
|
2818
|
+
it('when called, should return the instances of filters with multiple inputs', () => {
|
|
2819
|
+
const instance = new TekGrid({
|
|
2820
|
+
name: 'grid',
|
|
2821
|
+
component: 'TekGrid',
|
|
2822
|
+
datasource: {
|
|
2823
|
+
type: 'tek-rest',
|
|
2824
|
+
uniqueKey: 'id',
|
|
2825
|
+
route: '/zeedhi',
|
|
2826
|
+
lazyLoad: false,
|
|
2827
|
+
},
|
|
2828
|
+
columns: [
|
|
2829
|
+
{ name: 'id' },
|
|
2830
|
+
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
2831
|
+
{
|
|
2832
|
+
name: 'salary',
|
|
2833
|
+
filterable: true,
|
|
2834
|
+
filterProps: [
|
|
2835
|
+
{
|
|
2836
|
+
name: 'salary_edit',
|
|
2837
|
+
component: 'ZdCurrency',
|
|
2838
|
+
operation: 'GREATER_THAN_EQUALS',
|
|
2839
|
+
label: 'Salary (min)',
|
|
2840
|
+
},
|
|
2841
|
+
{
|
|
2842
|
+
name: 'salary_edit',
|
|
2843
|
+
component: 'ZdCurrency',
|
|
2844
|
+
operation: 'LESS_THAN_EQUALS',
|
|
2845
|
+
label: 'Salary (max)',
|
|
2846
|
+
},
|
|
2847
|
+
],
|
|
2848
|
+
},
|
|
2849
|
+
],
|
|
2850
|
+
});
|
|
2851
|
+
|
|
2852
|
+
const spy = mockMetadata(instance);
|
|
2853
|
+
instance.onCreated();
|
|
2854
|
+
const filterTooltip = instance.toolbarSlot[6];
|
|
2855
|
+
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
2856
|
+
const button = new Button(filterTooltip.children[0]);
|
|
2857
|
+
const event = new Event('click');
|
|
2858
|
+
button.click(event, {} as HTMLElement);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
const inputs = instance.getFilterInputs('salary');
|
|
2862
|
+
expect(inputs[0].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
|
|
2863
|
+
expect(inputs[1].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
|
|
2864
|
+
spy.mockClear();
|
|
2865
|
+
});
|
|
2866
|
+
});
|
|
2428
2867
|
});
|