@zeedhi/teknisa-components-common 1.88.0 → 1.89.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 +679 -622
- package/coverage/coverage-final.json +41 -39
- package/coverage/lcov-report/index.html +31 -16
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +4 -4
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +12 -12
- package/coverage/lcov-report/tests/__helpers__/index.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +5 -5
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +4 -4
- package/coverage/lcov.info +1135 -1038
- package/dist/tek-components-common.esm.js +613 -496
- package/dist/tek-components-common.umd.js +615 -497
- package/package.json +3 -2
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -0
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +846 -0
- package/tests/unit/components/tek-grid/grid.spec.ts +20 -769
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +15 -9
- package/types/components/index.d.ts +3 -0
- package/types/components/tek-drag-grid/interfaces.d.ts +7 -0
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +36 -0
- package/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/types/components/tek-grid/interfaces.d.ts +6 -2
- package/types/utils/grid-base/grid-base.d.ts +9 -19
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Button,
|
|
4
|
+
Button, Dropdown, IButton, IModal, Modal, ModalService, Search, TextInput, Text, Report,
|
|
5
5
|
} from '@zeedhi/common';
|
|
6
6
|
import {
|
|
7
|
-
KeyMap, Http, Metadata,
|
|
7
|
+
KeyMap, Http, Metadata, IDictionary,
|
|
8
8
|
} from '@zeedhi/core';
|
|
9
9
|
import {
|
|
10
|
-
IFilterPropsComponent,
|
|
11
10
|
ITekGrid,
|
|
12
|
-
|
|
11
|
+
ITekGridFilterButton,
|
|
12
|
+
TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
|
|
13
13
|
} from '../../../../src';
|
|
14
14
|
import { ReportFilter } from '../../../../src/utils';
|
|
15
15
|
import { setClick, getChild } from '../../../__helpers__';
|
|
@@ -20,11 +20,11 @@ jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
|
20
20
|
jest.useFakeTimers();
|
|
21
21
|
|
|
22
22
|
const clickOnFilterButton = (grid: TekGrid, event?: any) => {
|
|
23
|
-
const buttonProps = getChild<
|
|
24
|
-
const
|
|
25
|
-
setClick(
|
|
23
|
+
const buttonProps = getChild<ITekGridFilterButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
|
|
24
|
+
const filterButton = new TekGridFilterButton(buttonProps);
|
|
25
|
+
setClick(filterButton, event);
|
|
26
26
|
|
|
27
|
-
return
|
|
27
|
+
return filterButton;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const createAndMount = (props: ITekGrid) => {
|
|
@@ -917,13 +917,17 @@ describe('TekGrid', () => {
|
|
|
917
917
|
|
|
918
918
|
const method = jest.fn();
|
|
919
919
|
|
|
920
|
-
const
|
|
920
|
+
const filterButton = new TekGridFilterButton({
|
|
921
921
|
name: 'grid_navigation_2_filterButton',
|
|
922
|
-
component: '
|
|
922
|
+
component: 'TekGridFilterButton',
|
|
923
|
+
grid: instance,
|
|
923
924
|
events: {
|
|
924
925
|
click: method,
|
|
925
926
|
},
|
|
926
|
-
})
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => filterButton);
|
|
930
|
+
filterButton.onCreated();
|
|
927
931
|
|
|
928
932
|
dispatchEvent('l', { ctrlKey: true }); // ctrl+l keydown
|
|
929
933
|
await flushPromises();
|
|
@@ -1705,762 +1709,6 @@ describe('TekGrid', () => {
|
|
|
1705
1709
|
});
|
|
1706
1710
|
});
|
|
1707
1711
|
|
|
1708
|
-
describe('filterClick()', () => {
|
|
1709
|
-
it('should call createFilterFromColumns', () => {
|
|
1710
|
-
const instance = new TekGrid({
|
|
1711
|
-
name: 'grid_filterClick1',
|
|
1712
|
-
component: 'TekGrid',
|
|
1713
|
-
});
|
|
1714
|
-
|
|
1715
|
-
const formInstance = new Form({
|
|
1716
|
-
name: 'form',
|
|
1717
|
-
component: 'ZdForm',
|
|
1718
|
-
});
|
|
1719
|
-
|
|
1720
|
-
const spy = jest.spyOn(ModalService, 'create');
|
|
1721
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formInstance);
|
|
1722
|
-
instance.onCreated();
|
|
1723
|
-
|
|
1724
|
-
const button = clickOnFilterButton(instance);
|
|
1725
|
-
expect(spy).toBeCalledTimes(1);
|
|
1726
|
-
clickOnFilterButton(instance);
|
|
1727
|
-
expect(spy).toBeCalledTimes(1);
|
|
1728
|
-
expect(button.isVisible).toBeFalsy();
|
|
1729
|
-
(instance as any).gridBase.hideFilterModal();
|
|
1730
|
-
|
|
1731
|
-
instance.onBeforeDestroy();
|
|
1732
|
-
|
|
1733
|
-
spy.mockReset();
|
|
1734
|
-
spyMetadata.mockReset();
|
|
1735
|
-
});
|
|
1736
|
-
|
|
1737
|
-
it('should call events', () => {
|
|
1738
|
-
let filterClickCalled = false;
|
|
1739
|
-
const instance = new TekGrid({
|
|
1740
|
-
name: 'grid_filterClick2',
|
|
1741
|
-
component: 'TekGrid',
|
|
1742
|
-
events: {
|
|
1743
|
-
filterClick: () => { filterClickCalled = true; },
|
|
1744
|
-
},
|
|
1745
|
-
});
|
|
1746
|
-
|
|
1747
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal) => new Modal(modal));
|
|
1748
|
-
|
|
1749
|
-
instance.onCreated();
|
|
1750
|
-
clickOnFilterButton(instance);
|
|
1751
|
-
|
|
1752
|
-
expect(filterClickCalled).toBeTruthy();
|
|
1753
|
-
|
|
1754
|
-
spy.mockReset();
|
|
1755
|
-
});
|
|
1756
|
-
|
|
1757
|
-
it('should not call saveEditedRows if filterClick call preventDefault', () => {
|
|
1758
|
-
let filterClickCalled = false;
|
|
1759
|
-
const instance = new TekGrid({
|
|
1760
|
-
name: 'grid_filterClick3',
|
|
1761
|
-
component: 'TekGrid',
|
|
1762
|
-
events: {
|
|
1763
|
-
filterClick: () => { filterClickCalled = true; },
|
|
1764
|
-
},
|
|
1765
|
-
});
|
|
1766
|
-
|
|
1767
|
-
const spy = jest.spyOn(ModalService, 'create');
|
|
1768
|
-
|
|
1769
|
-
instance.onCreated();
|
|
1770
|
-
clickOnFilterButton(instance, { defaultPrevented: true });
|
|
1771
|
-
|
|
1772
|
-
expect(filterClickCalled).toBeTruthy();
|
|
1773
|
-
expect(spy).not.toBeCalled();
|
|
1774
|
-
|
|
1775
|
-
spy.mockReset();
|
|
1776
|
-
});
|
|
1777
|
-
|
|
1778
|
-
it('should create modal with no form elements', () => {
|
|
1779
|
-
const instance = new TekGrid({
|
|
1780
|
-
name: 'grid_filterClick4',
|
|
1781
|
-
component: 'TekGrid',
|
|
1782
|
-
columns: [
|
|
1783
|
-
{ name: 'id' },
|
|
1784
|
-
{ name: 'name', filterable: false, filterProps: { name: 'name_edit', label: 'name' } },
|
|
1785
|
-
],
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
|
-
let formElements: any = [];
|
|
1789
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1790
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
1791
|
-
formElements = form.children;
|
|
1792
|
-
|
|
1793
|
-
return new Modal(modal);
|
|
1794
|
-
});
|
|
1795
|
-
instance.onCreated();
|
|
1796
|
-
clickOnFilterButton(instance);
|
|
1797
|
-
|
|
1798
|
-
expect(formElements).toEqual([]);
|
|
1799
|
-
spy.mockReset();
|
|
1800
|
-
});
|
|
1801
|
-
|
|
1802
|
-
it('should create modal with filterable form elements', () => {
|
|
1803
|
-
const instance = new TekGrid({
|
|
1804
|
-
name: 'grid_filterClick5',
|
|
1805
|
-
component: 'TekGrid',
|
|
1806
|
-
columns: [
|
|
1807
|
-
{ name: 'id' },
|
|
1808
|
-
{ name: 'name', filterable: true, filterProps: [{ name: 'name_edit', label: 'name' }] },
|
|
1809
|
-
],
|
|
1810
|
-
});
|
|
1811
|
-
|
|
1812
|
-
let formElements: any = [];
|
|
1813
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1814
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
1815
|
-
formElements = form.children;
|
|
1816
|
-
|
|
1817
|
-
return new Modal(modal);
|
|
1818
|
-
});
|
|
1819
|
-
instance.onCreated();
|
|
1820
|
-
clickOnFilterButton(instance);
|
|
1821
|
-
|
|
1822
|
-
expect(formElements[0].name).toBe('grid_filterClick5-filter-AND-CONTAINS-name-0');
|
|
1823
|
-
|
|
1824
|
-
spy.mockReset();
|
|
1825
|
-
});
|
|
1826
|
-
|
|
1827
|
-
it('should create modal with filterable and ordered form elements', () => {
|
|
1828
|
-
const instance = new TekGrid({
|
|
1829
|
-
name: 'grid-filter-order',
|
|
1830
|
-
component: 'TekGrid',
|
|
1831
|
-
columns: [
|
|
1832
|
-
{ name: 'id' },
|
|
1833
|
-
{
|
|
1834
|
-
name: 'first_name',
|
|
1835
|
-
filterable: true,
|
|
1836
|
-
filterProps: [{ name: 'first_name_edit', label: 'first_name' }],
|
|
1837
|
-
},
|
|
1838
|
-
{
|
|
1839
|
-
name: 'last_name',
|
|
1840
|
-
filterable: true,
|
|
1841
|
-
filterIndex: 1,
|
|
1842
|
-
filterProps: [{ name: 'last_name_edit', label: 'last_name' }],
|
|
1843
|
-
},
|
|
1844
|
-
{
|
|
1845
|
-
name: 'dob',
|
|
1846
|
-
filterable: true,
|
|
1847
|
-
filterIndex: 0,
|
|
1848
|
-
filterProps: [{ name: 'dob_edit', label: 'dob' }],
|
|
1849
|
-
},
|
|
1850
|
-
],
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
|
-
let formElements: any = [];
|
|
1854
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1855
|
-
const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
1856
|
-
formElements = form.children;
|
|
1857
|
-
|
|
1858
|
-
return new Modal(modal);
|
|
1859
|
-
});
|
|
1860
|
-
instance.onCreated();
|
|
1861
|
-
|
|
1862
|
-
clickOnFilterButton(instance);
|
|
1863
|
-
|
|
1864
|
-
expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
|
|
1865
|
-
expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
|
|
1866
|
-
expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
|
|
1867
|
-
|
|
1868
|
-
spy.mockReset();
|
|
1869
|
-
});
|
|
1870
|
-
|
|
1871
|
-
it('should create modal with filterable form elements and TekRestDatasource', () => {
|
|
1872
|
-
const instance = new TekGrid({
|
|
1873
|
-
name: 'grid_filterClick6',
|
|
1874
|
-
component: 'TekGrid',
|
|
1875
|
-
datasource: {
|
|
1876
|
-
type: 'tek-rest',
|
|
1877
|
-
lazyLoad: true,
|
|
1878
|
-
},
|
|
1879
|
-
columns: [
|
|
1880
|
-
{
|
|
1881
|
-
name: 'id',
|
|
1882
|
-
filterProps: [{ name: 'id_edit' }],
|
|
1883
|
-
},
|
|
1884
|
-
{
|
|
1885
|
-
name: 'name',
|
|
1886
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
1887
|
-
filterProps: [{
|
|
1888
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
1889
|
-
}],
|
|
1890
|
-
},
|
|
1891
|
-
],
|
|
1892
|
-
});
|
|
1893
|
-
|
|
1894
|
-
let formElements: any = [];
|
|
1895
|
-
let form: IForm;
|
|
1896
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1897
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
1898
|
-
formElements = form.children;
|
|
1899
|
-
|
|
1900
|
-
return new Modal(modal);
|
|
1901
|
-
});
|
|
1902
|
-
instance.onCreated();
|
|
1903
|
-
|
|
1904
|
-
clickOnFilterButton(instance);
|
|
1905
|
-
|
|
1906
|
-
expect(formElements[0].name).toBe('grid_filterClick6-filter-AND-CONTAINS-id-0');
|
|
1907
|
-
expect(formElements[1].name).toBe('grid_filterClick6-filter-OR-NOT_EQUALS-name-0');
|
|
1908
|
-
expect(formElements[1].component).toBe('ZdSelect');
|
|
1909
|
-
|
|
1910
|
-
spy.mockReset();
|
|
1911
|
-
});
|
|
1912
|
-
|
|
1913
|
-
it('should create modal with helper component', () => {
|
|
1914
|
-
const instance = new TekGrid({
|
|
1915
|
-
name: 'grid_filterClick7',
|
|
1916
|
-
component: 'TekGrid',
|
|
1917
|
-
datasource: {
|
|
1918
|
-
type: 'tek-rest',
|
|
1919
|
-
lazyLoad: true,
|
|
1920
|
-
},
|
|
1921
|
-
columns: [
|
|
1922
|
-
{
|
|
1923
|
-
name: 'id',
|
|
1924
|
-
filterProps: [{ name: 'id_edit' }],
|
|
1925
|
-
},
|
|
1926
|
-
{
|
|
1927
|
-
name: 'date',
|
|
1928
|
-
componentProps: { name: 'date_edit', component: 'ZdDate' },
|
|
1929
|
-
filterProps: [
|
|
1930
|
-
{
|
|
1931
|
-
name: 'date_edit1',
|
|
1932
|
-
label: 'date1',
|
|
1933
|
-
operation: 'NOT_EQUALS',
|
|
1934
|
-
relation: 'OR',
|
|
1935
|
-
helperOptions: [
|
|
1936
|
-
'TODAY',
|
|
1937
|
-
'TOMORROW',
|
|
1938
|
-
],
|
|
1939
|
-
},
|
|
1940
|
-
{
|
|
1941
|
-
name: 'date_edit2',
|
|
1942
|
-
label: 'date2',
|
|
1943
|
-
showLabel: false,
|
|
1944
|
-
operation: 'NOT_EQUALS',
|
|
1945
|
-
relation: 'OR',
|
|
1946
|
-
helperOptions: [
|
|
1947
|
-
'TODAY',
|
|
1948
|
-
'TOMORROW',
|
|
1949
|
-
],
|
|
1950
|
-
},
|
|
1951
|
-
],
|
|
1952
|
-
},
|
|
1953
|
-
],
|
|
1954
|
-
});
|
|
1955
|
-
|
|
1956
|
-
let formElements: any = [];
|
|
1957
|
-
let form: IForm;
|
|
1958
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1959
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
1960
|
-
formElements = form.children;
|
|
1961
|
-
|
|
1962
|
-
return new Modal(modal);
|
|
1963
|
-
});
|
|
1964
|
-
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
1965
|
-
|
|
1966
|
-
instance.onCreated();
|
|
1967
|
-
clickOnFilterButton(instance);
|
|
1968
|
-
|
|
1969
|
-
expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
|
|
1970
|
-
expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
|
|
1971
|
-
expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
|
|
1972
|
-
|
|
1973
|
-
spy.mockReset();
|
|
1974
|
-
dateHelperSpy.mockReset();
|
|
1975
|
-
});
|
|
1976
|
-
|
|
1977
|
-
it('should apply helper value', () => {
|
|
1978
|
-
const instance = new TekGrid({
|
|
1979
|
-
name: 'grid_filterClick8',
|
|
1980
|
-
component: 'TekGrid',
|
|
1981
|
-
datasource: {
|
|
1982
|
-
type: 'tek-rest',
|
|
1983
|
-
lazyLoad: true,
|
|
1984
|
-
},
|
|
1985
|
-
columns: [
|
|
1986
|
-
{
|
|
1987
|
-
name: 'date1',
|
|
1988
|
-
componentProps: { name: 'date_edit1', component: 'ZdDate' },
|
|
1989
|
-
filterProps: {
|
|
1990
|
-
name: 'date_edit1',
|
|
1991
|
-
label: 'date1',
|
|
1992
|
-
operation: 'NOT_EQUALS',
|
|
1993
|
-
relation: 'OR',
|
|
1994
|
-
helperOptions: [
|
|
1995
|
-
'TODAY',
|
|
1996
|
-
'TOMORROW',
|
|
1997
|
-
],
|
|
1998
|
-
},
|
|
1999
|
-
},
|
|
2000
|
-
{
|
|
2001
|
-
name: 'date2',
|
|
2002
|
-
componentProps: { name: 'date_edit2', component: 'ZdDate' },
|
|
2003
|
-
filterProps: [
|
|
2004
|
-
{
|
|
2005
|
-
name: 'date_edit21',
|
|
2006
|
-
label: 'date21',
|
|
2007
|
-
operation: 'NOT_EQUALS',
|
|
2008
|
-
relation: 'OR',
|
|
2009
|
-
helperOptions: [
|
|
2010
|
-
'TODAY',
|
|
2011
|
-
'TOMORROW',
|
|
2012
|
-
],
|
|
2013
|
-
},
|
|
2014
|
-
{
|
|
2015
|
-
name: 'date_edit22',
|
|
2016
|
-
label: 'date22',
|
|
2017
|
-
helperOptions: [
|
|
2018
|
-
'TODAY',
|
|
2019
|
-
'TOMORROW',
|
|
2020
|
-
],
|
|
2021
|
-
},
|
|
2022
|
-
],
|
|
2023
|
-
},
|
|
2024
|
-
],
|
|
2025
|
-
});
|
|
2026
|
-
|
|
2027
|
-
let formElements: any = [];
|
|
2028
|
-
let form: IForm;
|
|
2029
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2030
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
2031
|
-
formElements = form.children;
|
|
2032
|
-
|
|
2033
|
-
return new Modal(modal);
|
|
2034
|
-
});
|
|
2035
|
-
instance.onCreated();
|
|
2036
|
-
clickOnFilterButton(instance);
|
|
2037
|
-
|
|
2038
|
-
const dateComp = new Date(formElements[0]);
|
|
2039
|
-
dateComp.helperValue = 'TODAY';
|
|
2040
|
-
dateComp.change({} as Event, {} as HTMLElement);
|
|
2041
|
-
expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
|
|
2042
|
-
|
|
2043
|
-
const dateComp21 = new Date(formElements[1]);
|
|
2044
|
-
dateComp21.helperValue = 'TODAY';
|
|
2045
|
-
dateComp21.change({} as Event, {} as HTMLElement);
|
|
2046
|
-
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
|
|
2047
|
-
|
|
2048
|
-
const dateComp22 = new Date(formElements[2]);
|
|
2049
|
-
dateComp22.helperValue = 'TODAY';
|
|
2050
|
-
dateComp22.change({} as Event, {} as HTMLElement);
|
|
2051
|
-
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
|
|
2052
|
-
|
|
2053
|
-
spy.mockReset();
|
|
2054
|
-
});
|
|
2055
|
-
|
|
2056
|
-
it('should load form values from tekdatasource', () => {
|
|
2057
|
-
const instance = new TekGrid({
|
|
2058
|
-
name: 'grid_filterClick9',
|
|
2059
|
-
component: 'TekGrid',
|
|
2060
|
-
datasource: {
|
|
2061
|
-
type: 'tek-rest',
|
|
2062
|
-
lazyLoad: true,
|
|
2063
|
-
dynamicFilter: {
|
|
2064
|
-
name: [
|
|
2065
|
-
{
|
|
2066
|
-
operation: 'NOT_EQUALS',
|
|
2067
|
-
relation: 'OR',
|
|
2068
|
-
value: 'teste',
|
|
2069
|
-
},
|
|
2070
|
-
],
|
|
2071
|
-
phone: [
|
|
2072
|
-
{
|
|
2073
|
-
value: '9',
|
|
2074
|
-
},
|
|
2075
|
-
],
|
|
2076
|
-
date: [
|
|
2077
|
-
{
|
|
2078
|
-
operation: 'IN',
|
|
2079
|
-
relation: 'OR',
|
|
2080
|
-
value: ['2021-11-12', '2021-12-12'],
|
|
2081
|
-
},
|
|
2082
|
-
],
|
|
2083
|
-
},
|
|
2084
|
-
},
|
|
2085
|
-
columns: [
|
|
2086
|
-
{
|
|
2087
|
-
name: 'id',
|
|
2088
|
-
filterProps: [{ name: 'id_edit' }],
|
|
2089
|
-
},
|
|
2090
|
-
{
|
|
2091
|
-
name: 'name',
|
|
2092
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
2093
|
-
filterProps: {
|
|
2094
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
2095
|
-
},
|
|
2096
|
-
},
|
|
2097
|
-
{
|
|
2098
|
-
name: 'phone',
|
|
2099
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
2100
|
-
},
|
|
2101
|
-
{
|
|
2102
|
-
name: 'date',
|
|
2103
|
-
filterProps: { name: 'date_edit', helperValue: 'TODAY' },
|
|
2104
|
-
},
|
|
2105
|
-
],
|
|
2106
|
-
});
|
|
2107
|
-
|
|
2108
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
2109
|
-
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
2110
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2111
|
-
form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
2112
|
-
|
|
2113
|
-
return new Modal(modal);
|
|
2114
|
-
});
|
|
2115
|
-
instance.onCreated();
|
|
2116
|
-
|
|
2117
|
-
clickOnFilterButton(instance);
|
|
2118
|
-
|
|
2119
|
-
expect(form.name).toBe('grid_filterClick9-filter-form');
|
|
2120
|
-
const formObject = new Form(form);
|
|
2121
|
-
formObject.value = {
|
|
2122
|
-
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
2123
|
-
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': null,
|
|
2124
|
-
'grid_filterClick9-filter-AND-CONTAINS-phone-0': null,
|
|
2125
|
-
'grid_filterClick9-filter-OR-IN-date-0': null,
|
|
2126
|
-
};
|
|
2127
|
-
const dateObject = new Date({ name: 'date', component: 'ZdDate' });
|
|
2128
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
|
|
2129
|
-
formObject.onMounted({} as HTMLElement);
|
|
2130
|
-
expect(formObject.value).toEqual({
|
|
2131
|
-
'grid_filterClick9-filter-AND_CONTAINS-id-0': null,
|
|
2132
|
-
'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
2133
|
-
'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
|
|
2134
|
-
'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
|
|
2135
|
-
});
|
|
2136
|
-
expect(dateObject.hint).toBe('TODAY');
|
|
2137
|
-
spyMetadata.mockReset();
|
|
2138
|
-
dateHelperSpy.mockReset();
|
|
2139
|
-
spy.mockReset();
|
|
2140
|
-
});
|
|
2141
|
-
|
|
2142
|
-
it('should load form values from datasource', () => {
|
|
2143
|
-
const instance = new TekGrid({
|
|
2144
|
-
name: 'grid_filterClick10',
|
|
2145
|
-
component: 'TekGrid',
|
|
2146
|
-
datasource: {
|
|
2147
|
-
filter: {
|
|
2148
|
-
id: '',
|
|
2149
|
-
name: 'teste',
|
|
2150
|
-
phone: '9',
|
|
2151
|
-
},
|
|
2152
|
-
},
|
|
2153
|
-
columns: [
|
|
2154
|
-
{
|
|
2155
|
-
name: 'id',
|
|
2156
|
-
},
|
|
2157
|
-
{
|
|
2158
|
-
name: 'name',
|
|
2159
|
-
},
|
|
2160
|
-
{
|
|
2161
|
-
name: 'phone',
|
|
2162
|
-
},
|
|
2163
|
-
],
|
|
2164
|
-
});
|
|
2165
|
-
|
|
2166
|
-
let formProps: IForm = {} as IForm;
|
|
2167
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2168
|
-
formProps = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
|
|
2169
|
-
|
|
2170
|
-
return new Modal(modal);
|
|
2171
|
-
});
|
|
2172
|
-
instance.onCreated();
|
|
2173
|
-
clickOnFilterButton(instance);
|
|
2174
|
-
|
|
2175
|
-
const formObject = new Form(formProps);
|
|
2176
|
-
formObject.onMounted({} as HTMLElement);
|
|
2177
|
-
|
|
2178
|
-
expect(formObject.value).toEqual({
|
|
2179
|
-
'grid_filterClick10-filter-AND-CONTAINS-name-0': 'teste',
|
|
2180
|
-
'grid_filterClick10-filter-AND-CONTAINS-phone-0': '9',
|
|
2181
|
-
});
|
|
2182
|
-
spy.mockReset();
|
|
2183
|
-
});
|
|
2184
|
-
|
|
2185
|
-
it('should apply filter from form to tekdatasource', () => {
|
|
2186
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
2187
|
-
data: {
|
|
2188
|
-
data: [
|
|
2189
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
2190
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
2191
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
2192
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
2193
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
2194
|
-
],
|
|
2195
|
-
pagination: {
|
|
2196
|
-
page: 1,
|
|
2197
|
-
total: 5,
|
|
2198
|
-
limit: 15,
|
|
2199
|
-
},
|
|
2200
|
-
},
|
|
2201
|
-
}));
|
|
2202
|
-
const instance = new TekGrid({
|
|
2203
|
-
name: 'grid_filterClick11',
|
|
2204
|
-
component: 'TekGrid',
|
|
2205
|
-
datasource: {
|
|
2206
|
-
type: 'tek-rest',
|
|
2207
|
-
},
|
|
2208
|
-
columns: [
|
|
2209
|
-
{
|
|
2210
|
-
name: 'id',
|
|
2211
|
-
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
2212
|
-
},
|
|
2213
|
-
{
|
|
2214
|
-
name: 'name',
|
|
2215
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
2216
|
-
filterProps: [{
|
|
2217
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
2218
|
-
}],
|
|
2219
|
-
},
|
|
2220
|
-
{
|
|
2221
|
-
name: 'phone',
|
|
2222
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
2223
|
-
},
|
|
2224
|
-
{
|
|
2225
|
-
name: 'salary',
|
|
2226
|
-
filterProps: [
|
|
2227
|
-
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
2228
|
-
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
2229
|
-
],
|
|
2230
|
-
},
|
|
2231
|
-
],
|
|
2232
|
-
});
|
|
2233
|
-
|
|
2234
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
2235
|
-
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
2236
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2237
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
2238
|
-
|
|
2239
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
2240
|
-
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
2241
|
-
|
|
2242
|
-
return new Modal(modal);
|
|
2243
|
-
});
|
|
2244
|
-
|
|
2245
|
-
instance.onCreated();
|
|
2246
|
-
|
|
2247
|
-
const buttonProps = getChild<IButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
2248
|
-
const button = new Button(buttonProps);
|
|
2249
|
-
setClick(button);
|
|
2250
|
-
|
|
2251
|
-
const formObject = new Form(form);
|
|
2252
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
2253
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
2254
|
-
formObject.value = {
|
|
2255
|
-
'grid_filterClick11-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
2256
|
-
'grid_filterClick11-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
2257
|
-
'grid_filterClick11-filter-AND-CONTAINS-phone-0': '',
|
|
2258
|
-
'grid_filterClick11-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
2259
|
-
'grid_filterClick11-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
2260
|
-
};
|
|
2261
|
-
const applyButtonObject = new Button(applyButton);
|
|
2262
|
-
formObject.validate = () => false;
|
|
2263
|
-
setClick(applyButtonObject);
|
|
2264
|
-
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({});
|
|
2265
|
-
|
|
2266
|
-
formObject.validate = () => true;
|
|
2267
|
-
setClick(applyButtonObject);
|
|
2268
|
-
expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({
|
|
2269
|
-
id: [
|
|
2270
|
-
{
|
|
2271
|
-
operation: 'IN',
|
|
2272
|
-
relation: 'AND',
|
|
2273
|
-
value: ['1', '2', '3'],
|
|
2274
|
-
},
|
|
2275
|
-
],
|
|
2276
|
-
name: [
|
|
2277
|
-
{
|
|
2278
|
-
operation: 'NOT_EQUALS',
|
|
2279
|
-
relation: 'OR',
|
|
2280
|
-
value: 'teste',
|
|
2281
|
-
},
|
|
2282
|
-
],
|
|
2283
|
-
salary: [
|
|
2284
|
-
{
|
|
2285
|
-
operation: 'GREATER_THAN_EQUALS',
|
|
2286
|
-
relation: 'AND',
|
|
2287
|
-
value: '1000',
|
|
2288
|
-
},
|
|
2289
|
-
{
|
|
2290
|
-
operation: 'LESS_THAN_EQUALS',
|
|
2291
|
-
relation: 'AND',
|
|
2292
|
-
value: '2000',
|
|
2293
|
-
},
|
|
2294
|
-
],
|
|
2295
|
-
});
|
|
2296
|
-
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
|
|
2297
|
-
expect(spyDatasourceGet).toBeCalled();
|
|
2298
|
-
spyMetadata.mockReset();
|
|
2299
|
-
spyDatasourceGet.mockReset();
|
|
2300
|
-
spyModalService.mockReset();
|
|
2301
|
-
httpSpy.mockReset();
|
|
2302
|
-
});
|
|
2303
|
-
|
|
2304
|
-
it('should clear data from form', () => {
|
|
2305
|
-
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
2306
|
-
data: {
|
|
2307
|
-
data: [
|
|
2308
|
-
{ id: 1, name: 'employee 1', department: 1 },
|
|
2309
|
-
{ id: 2, name: 'employee 2', department: 1 },
|
|
2310
|
-
{ id: 3, name: 'employee 3', department: 1 },
|
|
2311
|
-
{ id: 4, name: 'employee 4', department: 2 },
|
|
2312
|
-
{ id: 5, name: 'employee 5', department: 2 },
|
|
2313
|
-
],
|
|
2314
|
-
pagination: {
|
|
2315
|
-
page: 1,
|
|
2316
|
-
total: 5,
|
|
2317
|
-
limit: 15,
|
|
2318
|
-
},
|
|
2319
|
-
},
|
|
2320
|
-
}));
|
|
2321
|
-
const instance = new TekGrid({
|
|
2322
|
-
name: 'grid_filterClick12',
|
|
2323
|
-
component: 'TekGrid',
|
|
2324
|
-
datasource: {
|
|
2325
|
-
type: 'tek-rest',
|
|
2326
|
-
},
|
|
2327
|
-
columns: [
|
|
2328
|
-
{
|
|
2329
|
-
name: 'id',
|
|
2330
|
-
filterProps: [{ name: 'id_edit', operation: 'IN', relation: 'AND' }],
|
|
2331
|
-
},
|
|
2332
|
-
{
|
|
2333
|
-
name: 'name',
|
|
2334
|
-
componentProps: { name: 'name_edit', component: 'ZdSelect' },
|
|
2335
|
-
filterProps: [{
|
|
2336
|
-
name: 'name_edit', label: 'name', operation: 'NOT_EQUALS', relation: 'OR',
|
|
2337
|
-
}],
|
|
2338
|
-
},
|
|
2339
|
-
{
|
|
2340
|
-
name: 'phone',
|
|
2341
|
-
filterProps: [{ name: 'phone_edit' }],
|
|
2342
|
-
},
|
|
2343
|
-
{
|
|
2344
|
-
name: 'salary',
|
|
2345
|
-
filterProps: [
|
|
2346
|
-
{ name: 'salary_min', operation: 'GREATER_THAN_EQUALS', relation: 'AND' },
|
|
2347
|
-
{ name: 'salary_max', operation: 'LESS_THAN_EQUALS', relation: 'AND' },
|
|
2348
|
-
],
|
|
2349
|
-
},
|
|
2350
|
-
],
|
|
2351
|
-
});
|
|
2352
|
-
|
|
2353
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
2354
|
-
let clearButton: IButton = { name: 'clear', component: 'ZdButton' };
|
|
2355
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2356
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
2357
|
-
|
|
2358
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
2359
|
-
clearButton = getChild(modalFooter.leftSlot, `${instance.name}-filter-clearButton`);
|
|
2360
|
-
|
|
2361
|
-
return new Modal(modal);
|
|
2362
|
-
});
|
|
2363
|
-
|
|
2364
|
-
instance.onCreated();
|
|
2365
|
-
|
|
2366
|
-
const buttonProps = getChild<IButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
|
|
2367
|
-
const button = new Button(buttonProps);
|
|
2368
|
-
setClick(button);
|
|
2369
|
-
|
|
2370
|
-
const formObject = new Form(form);
|
|
2371
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
2372
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
2373
|
-
formObject.value = {
|
|
2374
|
-
'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
|
|
2375
|
-
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
|
|
2376
|
-
'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
|
|
2377
|
-
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
|
|
2378
|
-
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
|
|
2379
|
-
};
|
|
2380
|
-
const clearButtonObject = new Button(clearButton);
|
|
2381
|
-
setClick(clearButtonObject);
|
|
2382
|
-
expect(formObject.value).toEqual({
|
|
2383
|
-
'grid_filterClick12-filter-AND-IN-id-0': null,
|
|
2384
|
-
'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
|
|
2385
|
-
'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
|
|
2386
|
-
'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
|
|
2387
|
-
'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
|
|
2388
|
-
});
|
|
2389
|
-
spyMetadata.mockReset();
|
|
2390
|
-
spyDatasourceGet.mockReset();
|
|
2391
|
-
spyModalService.mockReset();
|
|
2392
|
-
httpSpy.mockReset();
|
|
2393
|
-
});
|
|
2394
|
-
|
|
2395
|
-
it('should apply filter from form to datasource', () => {
|
|
2396
|
-
let beforeApplyFilterCalled = false;
|
|
2397
|
-
let changeLayoutCalled = false;
|
|
2398
|
-
const instance = new TekGrid({
|
|
2399
|
-
name: 'grid_filterClick13',
|
|
2400
|
-
component: 'TekGrid',
|
|
2401
|
-
columns: [
|
|
2402
|
-
{
|
|
2403
|
-
name: 'id',
|
|
2404
|
-
},
|
|
2405
|
-
{
|
|
2406
|
-
name: 'name',
|
|
2407
|
-
},
|
|
2408
|
-
{
|
|
2409
|
-
name: 'phone',
|
|
2410
|
-
},
|
|
2411
|
-
{
|
|
2412
|
-
name: 'salary',
|
|
2413
|
-
},
|
|
2414
|
-
],
|
|
2415
|
-
events: {
|
|
2416
|
-
beforeApplyFilter: () => { beforeApplyFilterCalled = true; },
|
|
2417
|
-
changeLayout: () => { changeLayoutCalled = true; },
|
|
2418
|
-
},
|
|
2419
|
-
});
|
|
2420
|
-
|
|
2421
|
-
let form: IForm = { name: 'form', component: 'ZdForm' };
|
|
2422
|
-
let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
|
|
2423
|
-
const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
2424
|
-
form = getChild(modal.children || [], `${instance.name}-filter-form`);
|
|
2425
|
-
|
|
2426
|
-
const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
|
|
2427
|
-
applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
|
|
2428
|
-
|
|
2429
|
-
return new Modal(modal);
|
|
2430
|
-
});
|
|
2431
|
-
|
|
2432
|
-
instance.onCreated();
|
|
2433
|
-
|
|
2434
|
-
clickOnFilterButton(instance);
|
|
2435
|
-
|
|
2436
|
-
const formObject = new Form(form);
|
|
2437
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
|
|
2438
|
-
const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
|
|
2439
|
-
formObject.value = {
|
|
2440
|
-
'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
|
|
2441
|
-
'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
|
|
2442
|
-
'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
|
|
2443
|
-
'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
|
|
2444
|
-
};
|
|
2445
|
-
const applyButtonObject = new Button(applyButton);
|
|
2446
|
-
setClick(applyButtonObject);
|
|
2447
|
-
expect(instance.datasource.filter).toEqual({
|
|
2448
|
-
id: '1;2;3',
|
|
2449
|
-
name: 'teste',
|
|
2450
|
-
salary: '1000',
|
|
2451
|
-
});
|
|
2452
|
-
expect(beforeApplyFilterCalled).toBeTruthy();
|
|
2453
|
-
expect(changeLayoutCalled).toBeTruthy();
|
|
2454
|
-
expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
|
|
2455
|
-
|
|
2456
|
-
setClick(applyButtonObject, { defaultPrevented: true });
|
|
2457
|
-
expect(spyDatasourceGet).toBeCalledTimes(1);
|
|
2458
|
-
spyMetadata.mockReset();
|
|
2459
|
-
spyDatasourceGet.mockReset();
|
|
2460
|
-
spyModalService.mockReset();
|
|
2461
|
-
});
|
|
2462
|
-
});
|
|
2463
|
-
|
|
2464
1712
|
describe('setSearch()', () => {
|
|
2465
1713
|
let baseProps: ITekGrid;
|
|
2466
1714
|
let httpSpy: jest.SpyInstance;
|
|
@@ -2929,7 +2177,9 @@ describe('TekGrid', () => {
|
|
|
2929
2177
|
|
|
2930
2178
|
const spy = mockMetadata(instance);
|
|
2931
2179
|
instance.onCreated();
|
|
2932
|
-
|
|
2180
|
+
|
|
2181
|
+
const filterButton = clickOnFilterButton(instance);
|
|
2182
|
+
filterButton.onCreated();
|
|
2933
2183
|
|
|
2934
2184
|
const inputs = instance.getFilterInputs();
|
|
2935
2185
|
expect(inputs[0].name).toBe('grid-filter-AND-CONTAINS-name-0');
|
|
@@ -2977,7 +2227,8 @@ describe('TekGrid', () => {
|
|
|
2977
2227
|
const spy = mockMetadata(instance);
|
|
2978
2228
|
instance.onCreated();
|
|
2979
2229
|
|
|
2980
|
-
clickOnFilterButton(instance);
|
|
2230
|
+
const filterButton = clickOnFilterButton(instance);
|
|
2231
|
+
filterButton.onCreated();
|
|
2981
2232
|
|
|
2982
2233
|
const inputs = instance.getFilterInputs('salary');
|
|
2983
2234
|
expect(inputs[0].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
|