@zeedhi/teknisa-components-common 1.45.0 → 1.48.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 +547 -576
- package/coverage/coverage-final.json +9 -9
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov.info +1078 -1143
- package/dist/tek-components-common.esm.js +497 -187
- package/dist/tek-components-common.umd.js +499 -188
- package/package.json +3 -2
- package/tests/__helpers__/mock-created-helper.ts +10 -0
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +24 -0
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +28 -1
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +5 -2
- package/tests/unit/components/tek-grid/grid.spec.ts +37 -130
- package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +234 -0
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +85 -0
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +395 -0
- package/types/components/index.d.ts +3 -0
- package/types/components/tek-grid/filter-helper.d.ts +0 -2
- package/types/components/tek-grid/interfaces.d.ts +3 -6
- package/types/components/tek-user-info/TekUserInfoController.d.ts +20 -0
- package/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/types/components/tek-user-info/tek-user-info-list.d.ts +29 -0
- package/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- package/types/utils/grid-base/grid-base.d.ts +1 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeedhi/teknisa-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "Teknisa Components Common",
|
|
5
5
|
"author": "Zeedhi <zeedhi@teknisa.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@types/lodash.debounce": "^4.0.6",
|
|
22
22
|
"@types/lodash.get": "^4.4.6",
|
|
23
23
|
"@types/lodash.merge": "^4.6.6",
|
|
24
|
+
"@zeedhi/zd-user-info-common": "^1.0.2",
|
|
24
25
|
"lodash.debounce": "^4.0.8",
|
|
25
26
|
"lodash.get": "^4.4.2",
|
|
26
27
|
"lodash.merge": "^4.6.2"
|
|
@@ -28,5 +29,5 @@
|
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"@zeedhi/core": "*"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "2b74af72b5bfd6159d947cba0beb3c990218f093"
|
|
32
33
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentRender } from '@zeedhi/common';
|
|
2
|
+
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
3
|
+
|
|
4
|
+
const mockCreated = (component: ComponentRender) => {
|
|
5
|
+
jest.spyOn(UserInfo.prototype, 'onCreated').mockImplementation(() => {
|
|
6
|
+
component.componentId = 1;
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { mockCreated };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
init,
|
|
2
3
|
Router,
|
|
3
4
|
URL,
|
|
4
5
|
} from '@zeedhi/core';
|
|
@@ -7,6 +8,14 @@ import {
|
|
|
7
8
|
} from '../../../../src';
|
|
8
9
|
|
|
9
10
|
describe('TekMemoryDatasource', () => {
|
|
11
|
+
init({
|
|
12
|
+
controllers: {
|
|
13
|
+
AppController: class AppController {
|
|
14
|
+
public value = '1';
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
10
19
|
let datasource: ITekMemoryDatasource;
|
|
11
20
|
let router: any;
|
|
12
21
|
|
|
@@ -56,6 +65,21 @@ describe('TekMemoryDatasource', () => {
|
|
|
56
65
|
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
57
66
|
});
|
|
58
67
|
|
|
68
|
+
it('should assign all properties with accessor', async () => {
|
|
69
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
70
|
+
const instance = new TekMemoryDatasource({
|
|
71
|
+
...datasource,
|
|
72
|
+
dynamicFilter: {
|
|
73
|
+
name: [{ operation: 'EQUALS', relation: 'AND', value: '{{AppController.value}}' }],
|
|
74
|
+
},
|
|
75
|
+
searchJoin: { col1: ['1', '2'], col2: [2], col3: [] },
|
|
76
|
+
});
|
|
77
|
+
await flushPromises();
|
|
78
|
+
|
|
79
|
+
expect(instance.dynamicFilter).toEqual({ name: [{ operation: 'EQUALS', relation: 'AND', value: '1' }] });
|
|
80
|
+
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
81
|
+
});
|
|
82
|
+
|
|
59
83
|
it('should create using default parameters', async () => {
|
|
60
84
|
const instance = new TekMemoryDatasource({});
|
|
61
85
|
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
IConfig, Config, Router, Http, URL, IDictionary,
|
|
2
|
+
IConfig, Config, Router, Http, URL, IDictionary, init,
|
|
3
3
|
} from '@zeedhi/core';
|
|
4
4
|
import {
|
|
5
5
|
TekRestDatasource, ITekRestDatasource,
|
|
6
6
|
} from '../../../../src';
|
|
7
7
|
|
|
8
8
|
describe('TekRestDatasource', () => {
|
|
9
|
+
init({
|
|
10
|
+
controllers: {
|
|
11
|
+
AppController: class AppController {
|
|
12
|
+
public value = '1';
|
|
13
|
+
|
|
14
|
+
public join: string[] | number[] = ['1', '2'];
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
9
18
|
let datasource: ITekRestDatasource;
|
|
10
19
|
let router: any;
|
|
11
20
|
const config: IConfig = {
|
|
@@ -82,6 +91,24 @@ describe('TekRestDatasource', () => {
|
|
|
82
91
|
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
83
92
|
});
|
|
84
93
|
|
|
94
|
+
it('should assign all properties', async () => {
|
|
95
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
96
|
+
const instance = new TekRestDatasource({
|
|
97
|
+
...datasource,
|
|
98
|
+
dynamicFilter: {
|
|
99
|
+
name: { operation: 'EQUALS', relation: 'AND', value: '{{AppController.value}}' },
|
|
100
|
+
},
|
|
101
|
+
searchJoin: { col1: '{{AppController.join}}' as any, col2: [2], col3: [] },
|
|
102
|
+
});
|
|
103
|
+
await flushPromises();
|
|
104
|
+
|
|
105
|
+
expect(instance.route).toBe('/zeedhi');
|
|
106
|
+
expect(instance.lazyLoad).toBeTruthy();
|
|
107
|
+
expect(instance.dynamicFilter).toEqual({ name: { operation: 'EQUALS', relation: 'AND', value: '1' } });
|
|
108
|
+
expect(instance.data.length).toBe(0);
|
|
109
|
+
expect(instance.searchJoin).toEqual({ col1: ['1', '2'], col2: [2], col3: [] });
|
|
110
|
+
});
|
|
111
|
+
|
|
85
112
|
it('should create without lazyLoad', async () => {
|
|
86
113
|
const flushPromises = () => new Promise(setImmediate);
|
|
87
114
|
const instance = new TekRestDatasource({
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Config, dayjs } from '@zeedhi/core';
|
|
1
|
+
import { Config, DateHelper, dayjs } from '@zeedhi/core';
|
|
2
2
|
import { TekFilterHelper, TekGrid } from '../../../../src';
|
|
3
3
|
|
|
4
4
|
describe('TekFilterHelper', () => {
|
|
5
5
|
describe('getLabel', () => {
|
|
6
6
|
it('should return helper label', () => {
|
|
7
|
-
|
|
7
|
+
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
8
|
+
|
|
9
|
+
expect(TekFilterHelper.getLabel('TODAY')).toBe('TODAY');
|
|
10
|
+
dateHelperSpy.mockClear();
|
|
8
11
|
});
|
|
9
12
|
});
|
|
10
13
|
|
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
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,
|
|
7
|
+
KeyMap, Http, Metadata, IDictionary, DateHelper,
|
|
8
8
|
} from '@zeedhi/core';
|
|
9
9
|
import {
|
|
10
|
+
IFilterPropsComponent,
|
|
10
11
|
ITekGrid,
|
|
11
12
|
TekGrid, TekGridColumn, TekRestDatasource,
|
|
12
13
|
} from '../../../../src';
|
|
@@ -1756,6 +1757,8 @@ describe('TekGrid', () => {
|
|
|
1756
1757
|
|
|
1757
1758
|
return new Modal(modal);
|
|
1758
1759
|
});
|
|
1760
|
+
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
1761
|
+
|
|
1759
1762
|
instance.onCreated();
|
|
1760
1763
|
const filterTooltip = instance.toolbarSlot[6];
|
|
1761
1764
|
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
@@ -1763,29 +1766,11 @@ describe('TekGrid', () => {
|
|
|
1763
1766
|
const event = new Event('click');
|
|
1764
1767
|
button.click(event, {} as HTMLElement);
|
|
1765
1768
|
expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
|
|
1766
|
-
expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-
|
|
1767
|
-
expect(formElements[
|
|
1768
|
-
expect(formElements[1].children.length).toBe(2);
|
|
1769
|
-
expect(formElements[1].children[0].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
|
|
1770
|
-
expect(formElements[1].children[0].component).toBe('ZdDate');
|
|
1771
|
-
expect(formElements[1].children[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0_helperdropdown');
|
|
1772
|
-
expect(formElements[1].children[1].component).toBe('ZdDropdown');
|
|
1773
|
-
expect(formElements[1].children[1].activator.cssClass).toBe('filter-helper-values-button with-label');
|
|
1774
|
-
expect(formElements[1].children[1].children.length).toBe(2);
|
|
1775
|
-
expect(formElements[1].children[1].children[0].component).toBe('ZdText');
|
|
1776
|
-
expect(formElements[1].children[1].children[0].text).toBe('TEKGRID_HELPERVALUE_TODAY');
|
|
1777
|
-
expect(formElements[1].children[1].children[1].component).toBe('ZdText');
|
|
1778
|
-
expect(formElements[1].children[1].children[1].text).toBe('TEKGRID_HELPERVALUE_TOMORROW');
|
|
1779
|
-
expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1_helperspan');
|
|
1780
|
-
expect(formElements[2].component).toBe('ZdTag');
|
|
1781
|
-
expect(formElements[2].children.length).toBe(2);
|
|
1782
|
-
expect(formElements[2].children[0].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
|
|
1783
|
-
expect(formElements[2].children[0].component).toBe('ZdDate');
|
|
1784
|
-
expect(formElements[2].children[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1_helperdropdown');
|
|
1785
|
-
expect(formElements[2].children[1].component).toBe('ZdDropdown');
|
|
1786
|
-
expect(formElements[2].children[1].activator.cssClass).toBe('filter-helper-values-button ');
|
|
1769
|
+
expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
|
|
1770
|
+
expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
|
|
1787
1771
|
}
|
|
1788
1772
|
spy.mockClear();
|
|
1773
|
+
dateHelperSpy.mockClear();
|
|
1789
1774
|
});
|
|
1790
1775
|
|
|
1791
1776
|
it('should apply helper value', () => {
|
|
@@ -1797,11 +1782,11 @@ describe('TekGrid', () => {
|
|
|
1797
1782
|
},
|
|
1798
1783
|
columns: [
|
|
1799
1784
|
{
|
|
1800
|
-
name: '
|
|
1801
|
-
componentProps: { name: '
|
|
1785
|
+
name: 'date1',
|
|
1786
|
+
componentProps: { name: 'date_edit1', component: 'ZdDate' },
|
|
1802
1787
|
filterProps: {
|
|
1803
|
-
name: '
|
|
1804
|
-
label: '
|
|
1788
|
+
name: 'date_edit1',
|
|
1789
|
+
label: 'date1',
|
|
1805
1790
|
operation: 'NOT_EQUALS',
|
|
1806
1791
|
relation: 'OR',
|
|
1807
1792
|
helperOptions: [
|
|
@@ -1810,53 +1795,23 @@ describe('TekGrid', () => {
|
|
|
1810
1795
|
],
|
|
1811
1796
|
},
|
|
1812
1797
|
},
|
|
1813
|
-
],
|
|
1814
|
-
});
|
|
1815
|
-
|
|
1816
|
-
let formElements: any = [];
|
|
1817
|
-
let form: IForm;
|
|
1818
|
-
const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
|
|
1819
|
-
if (modal.children && modal.children.length > 1) {
|
|
1820
|
-
form = modal.children[1] as IForm;
|
|
1821
|
-
formElements = form.children;
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
return new Modal(modal);
|
|
1825
|
-
});
|
|
1826
|
-
instance.onCreated();
|
|
1827
|
-
const filterTooltip = instance.toolbarSlot[6];
|
|
1828
|
-
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
1829
|
-
const button = new Button(filterTooltip.children[0]);
|
|
1830
|
-
const event = new Event('click');
|
|
1831
|
-
button.click(event, {} as HTMLElement);
|
|
1832
|
-
const todayHelper = new Text(formElements[0].children[1].children[0]);
|
|
1833
|
-
const dateComp = new Date(formElements[0].children[0]);
|
|
1834
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => dateComp);
|
|
1835
|
-
todayHelper.click(event, {} as HTMLElement);
|
|
1836
|
-
expect(dateComp.value).toBe(dayjs().format(Config.dateFormat));
|
|
1837
|
-
expect(dateComp.hint).toBe('TEKGRID_HELPERVALUE_TODAY');
|
|
1838
|
-
dateComp.change(event, {} as HTMLElement);
|
|
1839
|
-
expect(dateComp.hint).toBe('');
|
|
1840
|
-
spyMetadata.mockClear();
|
|
1841
|
-
}
|
|
1842
|
-
spy.mockClear();
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
it('should apply helper value on filterProps as an array', () => {
|
|
1846
|
-
const instance = new TekGrid({
|
|
1847
|
-
name: 'grid_filterClick8_1',
|
|
1848
|
-
component: 'TekGrid',
|
|
1849
|
-
datasource: {
|
|
1850
|
-
type: 'tek-rest',
|
|
1851
|
-
},
|
|
1852
|
-
columns: [
|
|
1853
1798
|
{
|
|
1854
|
-
name: '
|
|
1855
|
-
componentProps: { name: '
|
|
1799
|
+
name: 'date2',
|
|
1800
|
+
componentProps: { name: 'date_edit2', component: 'ZdDate' },
|
|
1856
1801
|
filterProps: [
|
|
1857
1802
|
{
|
|
1858
|
-
name: '
|
|
1859
|
-
label: '
|
|
1803
|
+
name: 'date_edit21',
|
|
1804
|
+
label: 'date21',
|
|
1805
|
+
operation: 'NOT_EQUALS',
|
|
1806
|
+
relation: 'OR',
|
|
1807
|
+
helperOptions: [
|
|
1808
|
+
'TODAY',
|
|
1809
|
+
'TOMORROW',
|
|
1810
|
+
],
|
|
1811
|
+
},
|
|
1812
|
+
{
|
|
1813
|
+
name: 'date_edit22',
|
|
1814
|
+
label: 'date22',
|
|
1860
1815
|
helperOptions: [
|
|
1861
1816
|
'TODAY',
|
|
1862
1817
|
'TOMORROW',
|
|
@@ -1883,68 +1838,20 @@ describe('TekGrid', () => {
|
|
|
1883
1838
|
const button = new Button(filterTooltip.children[0]);
|
|
1884
1839
|
const event = new Event('click');
|
|
1885
1840
|
button.click(event, {} as HTMLElement);
|
|
1886
|
-
const
|
|
1887
|
-
|
|
1888
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => dateComp);
|
|
1889
|
-
todayHelper.click(event, {} as HTMLElement);
|
|
1890
|
-
expect(dateComp.value).toBe(dayjs().format(Config.dateFormat));
|
|
1891
|
-
expect(dateComp.hint).toBe('TEKGRID_HELPERVALUE_TODAY');
|
|
1841
|
+
const dateComp = new Date(formElements[0]);
|
|
1842
|
+
dateComp.helperValue = 'TODAY';
|
|
1892
1843
|
dateComp.change(event, {} as HTMLElement);
|
|
1893
|
-
expect(
|
|
1894
|
-
spyMetadata.mockClear();
|
|
1895
|
-
}
|
|
1896
|
-
spy.mockClear();
|
|
1897
|
-
});
|
|
1898
|
-
|
|
1899
|
-
it('should apply helper value on filterProps as an array', () => {
|
|
1900
|
-
const instance = new TekGrid({
|
|
1901
|
-
name: 'grid_filterClick8_2',
|
|
1902
|
-
component: 'TekGrid',
|
|
1903
|
-
datasource: {
|
|
1904
|
-
type: 'tek-rest',
|
|
1905
|
-
},
|
|
1906
|
-
columns: [
|
|
1907
|
-
{
|
|
1908
|
-
name: 'date',
|
|
1909
|
-
componentProps: { name: 'date_edit', component: 'ZdDate' },
|
|
1910
|
-
filterProps: {
|
|
1911
|
-
name: 'date_edit',
|
|
1912
|
-
label: 'date',
|
|
1913
|
-
helperOptions: [
|
|
1914
|
-
'TODAY',
|
|
1915
|
-
'TOMORROW',
|
|
1916
|
-
],
|
|
1917
|
-
},
|
|
1918
|
-
},
|
|
1919
|
-
],
|
|
1920
|
-
});
|
|
1844
|
+
expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
|
|
1921
1845
|
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
form = modal.children[1] as IForm;
|
|
1927
|
-
formElements = form.children;
|
|
1928
|
-
}
|
|
1846
|
+
const dateComp21 = new Date(formElements[1]);
|
|
1847
|
+
dateComp21.helperValue = 'TODAY';
|
|
1848
|
+
dateComp21.change(event, {} as HTMLElement);
|
|
1849
|
+
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
|
|
1929
1850
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
|
|
1935
|
-
const button = new Button(filterTooltip.children[0]);
|
|
1936
|
-
const event = new Event('click');
|
|
1937
|
-
button.click(event, {} as HTMLElement);
|
|
1938
|
-
const dateComp = new Date(formElements[0].children[0]);
|
|
1939
|
-
if (form) {
|
|
1940
|
-
const formObj = new Form(form);
|
|
1941
|
-
const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObj);
|
|
1942
|
-
dateComp.onMounted({} as HTMLElement);
|
|
1943
|
-
expect(formObj.value).toEqual({
|
|
1944
|
-
'grid_filterClick8_2-filter-AND-CONTAINS-date-0': null,
|
|
1945
|
-
});
|
|
1946
|
-
spyMetadata.mockClear();
|
|
1947
|
-
}
|
|
1851
|
+
const dateComp22 = new Date(formElements[2]);
|
|
1852
|
+
dateComp22.helperValue = 'TODAY';
|
|
1853
|
+
dateComp22.change(event, {} as HTMLElement);
|
|
1854
|
+
expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
|
|
1948
1855
|
}
|
|
1949
1856
|
spy.mockClear();
|
|
1950
1857
|
});
|
|
@@ -2026,7 +1933,7 @@ describe('TekGrid', () => {
|
|
|
2026
1933
|
'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
|
|
2027
1934
|
'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
|
|
2028
1935
|
});
|
|
2029
|
-
expect(dateObject.hint).toBe('
|
|
1936
|
+
expect(dateObject.hint).toBe('TODAY');
|
|
2030
1937
|
spyMetadata.mockClear();
|
|
2031
1938
|
}
|
|
2032
1939
|
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { TekUserInfo } from '../../../../src';
|
|
2
|
+
import { TekUserInfoController } from '../../../../src/components/tek-user-info/TekUserInfoController';
|
|
3
|
+
|
|
4
|
+
describe('TekUserInfoController', () => {
|
|
5
|
+
describe('name property', () => {
|
|
6
|
+
it('should get name property', () => {
|
|
7
|
+
const component = new TekUserInfo({
|
|
8
|
+
name: 'user-info',
|
|
9
|
+
component: 'TekUserInfo',
|
|
10
|
+
versionInfo: {
|
|
11
|
+
name: 'Zeedhi',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
14
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
15
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const controller = new TekUserInfoController(component);
|
|
19
|
+
|
|
20
|
+
expect(controller.name).toBe('Zeedhi');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('when prop is defined, should set the component value', () => {
|
|
24
|
+
const component = new TekUserInfo({
|
|
25
|
+
name: 'user-info',
|
|
26
|
+
component: 'TekUserInfo',
|
|
27
|
+
versionInfo: {
|
|
28
|
+
name: 'Zeedhi',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
31
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
32
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const controller = new TekUserInfoController(component);
|
|
36
|
+
|
|
37
|
+
controller.name = 'new name';
|
|
38
|
+
|
|
39
|
+
expect(controller.name).toBe('new name');
|
|
40
|
+
expect(component.versionInfo?.name).toBe('new name');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('when versionInfo is null, should get empty string', () => {
|
|
44
|
+
const component = new TekUserInfo({
|
|
45
|
+
name: 'user-info',
|
|
46
|
+
component: 'TekUserInfo',
|
|
47
|
+
versionInfo: null,
|
|
48
|
+
});
|
|
49
|
+
const controller = new TekUserInfoController(component);
|
|
50
|
+
|
|
51
|
+
expect(controller.name).toBe('');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('when versionInfo is null, should not throw when setting', () => {
|
|
55
|
+
const component = new TekUserInfo({
|
|
56
|
+
name: 'user-info',
|
|
57
|
+
component: 'TekUserInfo',
|
|
58
|
+
versionInfo: null,
|
|
59
|
+
});
|
|
60
|
+
const controller = new TekUserInfoController(component);
|
|
61
|
+
|
|
62
|
+
expect(() => { controller.name = 'new name'; }).not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('version property', () => {
|
|
67
|
+
it('should get version property', () => {
|
|
68
|
+
const component = new TekUserInfo({
|
|
69
|
+
name: 'user-info',
|
|
70
|
+
component: 'TekUserInfo',
|
|
71
|
+
versionInfo: {
|
|
72
|
+
name: 'Zeedhi',
|
|
73
|
+
version: '1.0.0',
|
|
74
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
75
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
76
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const controller = new TekUserInfoController(component);
|
|
80
|
+
|
|
81
|
+
expect(controller.version).toBe('1.0.0');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('when prop is defined, should set the component value', () => {
|
|
85
|
+
const component = new TekUserInfo({
|
|
86
|
+
name: 'user-info',
|
|
87
|
+
component: 'TekUserInfo',
|
|
88
|
+
versionInfo: {
|
|
89
|
+
name: 'Zeedhi',
|
|
90
|
+
version: '1.0.0',
|
|
91
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
92
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
93
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const controller = new TekUserInfoController(component);
|
|
97
|
+
|
|
98
|
+
controller.version = '2.0.0';
|
|
99
|
+
|
|
100
|
+
expect(controller.version).toBe('2.0.0');
|
|
101
|
+
expect(component.versionInfo?.version).toBe('2.0.0');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('when versionInfo is null, should get empty string', () => {
|
|
105
|
+
const component = new TekUserInfo({
|
|
106
|
+
name: 'user-info',
|
|
107
|
+
component: 'TekUserInfo',
|
|
108
|
+
versionInfo: null,
|
|
109
|
+
});
|
|
110
|
+
const controller = new TekUserInfoController(component);
|
|
111
|
+
|
|
112
|
+
expect(controller.version).toBe('');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('when versionInfo is null, should not throw when setting', () => {
|
|
116
|
+
const component = new TekUserInfo({
|
|
117
|
+
name: 'user-info',
|
|
118
|
+
component: 'TekUserInfo',
|
|
119
|
+
versionInfo: null,
|
|
120
|
+
});
|
|
121
|
+
const controller = new TekUserInfoController(component);
|
|
122
|
+
|
|
123
|
+
expect(() => { controller.version = '2.0.0'; }).not.toThrow();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('defaultEmail property', () => {
|
|
128
|
+
it('should get defaultEmail property', () => {
|
|
129
|
+
const component = new TekUserInfo({
|
|
130
|
+
name: 'user-info',
|
|
131
|
+
component: 'TekUserInfo',
|
|
132
|
+
defaultEmail: 'zeedhi@zd.com',
|
|
133
|
+
});
|
|
134
|
+
const controller = new TekUserInfoController(component);
|
|
135
|
+
|
|
136
|
+
expect(controller.defaultEmail).toBe('zeedhi@zd.com');
|
|
137
|
+
expect(controller.hasDefaultEmail).toBeTruthy();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('when prop is defined, should set the component value', () => {
|
|
141
|
+
const component = new TekUserInfo({
|
|
142
|
+
name: 'user-info',
|
|
143
|
+
component: 'TekUserInfo',
|
|
144
|
+
});
|
|
145
|
+
const controller = new TekUserInfoController(component);
|
|
146
|
+
|
|
147
|
+
controller.defaultEmail = 'teste@email.com';
|
|
148
|
+
|
|
149
|
+
expect(controller.defaultEmail).toBe('teste@email.com');
|
|
150
|
+
expect(component.defaultEmail).toBe('teste@email.com');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('mainVersion property', () => {
|
|
155
|
+
it('should get mainVersion property', () => {
|
|
156
|
+
const component = new TekUserInfo({
|
|
157
|
+
name: 'user-info',
|
|
158
|
+
component: 'TekUserInfo',
|
|
159
|
+
versionInfo: {
|
|
160
|
+
name: 'Zeedhi',
|
|
161
|
+
version: '1.0.0',
|
|
162
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
163
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
164
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
const controller = new TekUserInfoController(component);
|
|
168
|
+
|
|
169
|
+
expect(controller.mainVersion).toBe('Zeedhi - <b>1.0.0</b>');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('when versionInfo is null, mainVersion should return empty string', () => {
|
|
173
|
+
const component = new TekUserInfo({
|
|
174
|
+
name: 'user-info',
|
|
175
|
+
component: 'TekUserInfo',
|
|
176
|
+
versionInfo: null,
|
|
177
|
+
});
|
|
178
|
+
const controller = new TekUserInfoController(component);
|
|
179
|
+
|
|
180
|
+
expect(controller.mainVersion).toBe('');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('item properties', () => {
|
|
185
|
+
it('should get the items', () => {
|
|
186
|
+
const component = new TekUserInfo({
|
|
187
|
+
name: 'user-info',
|
|
188
|
+
component: 'TekUserInfo',
|
|
189
|
+
versionInfo: {
|
|
190
|
+
name: 'Zeedhi',
|
|
191
|
+
version: '1.0.0',
|
|
192
|
+
frontend: [{ name: 'package 1', version: '1.0.0' }],
|
|
193
|
+
backend: [{ name: 'package 2', version: '2.0.0' }],
|
|
194
|
+
modules: [{ name: 'package 3', version: '3.0.0' }],
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
const controller = new TekUserInfoController(component);
|
|
198
|
+
|
|
199
|
+
expect(controller.frontendItems).toEqual(['package 1 - <b>1.0.0</b>']);
|
|
200
|
+
expect(controller.backendItems).toEqual(['package 2 - <b>2.0.0</b>']);
|
|
201
|
+
expect(controller.modulesItems).toEqual(['package 3 - <b>3.0.0</b>']);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('when versionInfo is null, should get empty array', () => {
|
|
205
|
+
const component = new TekUserInfo({
|
|
206
|
+
name: 'user-info',
|
|
207
|
+
component: 'TekUserInfo',
|
|
208
|
+
versionInfo: null,
|
|
209
|
+
});
|
|
210
|
+
const controller = new TekUserInfoController(component);
|
|
211
|
+
|
|
212
|
+
expect(controller.frontendItems).toEqual([]);
|
|
213
|
+
expect(controller.backendItems).toEqual([]);
|
|
214
|
+
expect(controller.modulesItems).toEqual([]);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('aboutImage properties', () => {
|
|
219
|
+
it('should return true if aboutImage is defined, false otherwise', () => {
|
|
220
|
+
const component = new TekUserInfo({
|
|
221
|
+
name: 'user-info',
|
|
222
|
+
component: 'TekUserInfo',
|
|
223
|
+
aboutImage: 'path',
|
|
224
|
+
});
|
|
225
|
+
const controller = new TekUserInfoController(component);
|
|
226
|
+
|
|
227
|
+
expect(controller.hasAboutImage).toBeTruthy();
|
|
228
|
+
|
|
229
|
+
component.aboutImage = '';
|
|
230
|
+
|
|
231
|
+
expect(controller.hasAboutImage).toBeFalsy();
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ListItem } from '@zeedhi/common';
|
|
2
|
+
import { Metadata } from '@zeedhi/core';
|
|
3
|
+
import { TekUserInfo, TekUserInfoList, ITekUserInfo } from '../../../../src';
|
|
4
|
+
import { mockCreated } from '../../../__helpers__/mock-created-helper';
|
|
5
|
+
|
|
6
|
+
function instantiateAndCreate(props: ITekUserInfo) {
|
|
7
|
+
const instance = new TekUserInfo(props);
|
|
8
|
+
mockCreated(instance);
|
|
9
|
+
instance.onCreated();
|
|
10
|
+
return instance;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('TekUserInfoList', () => {
|
|
14
|
+
afterEach(() => jest.clearAllMocks());
|
|
15
|
+
|
|
16
|
+
describe('constructor()', () => {
|
|
17
|
+
it('when parent is not defined, should throw', () => {
|
|
18
|
+
expect(() => (new TekUserInfoList({ name: 'TekUserInfo', component: 'TekUserInfoList' }))).toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('when parentName is defined, should call Metadata.getInstance', () => {
|
|
22
|
+
const parent = instantiateAndCreate({
|
|
23
|
+
name: 'parent',
|
|
24
|
+
component: 'TekUserInfo',
|
|
25
|
+
});
|
|
26
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => (parent));
|
|
27
|
+
|
|
28
|
+
const spy = jest.spyOn(Metadata, 'getInstance');
|
|
29
|
+
const instance = new TekUserInfoList({
|
|
30
|
+
name: 'TekUserInfo',
|
|
31
|
+
component: 'TekUserInfoList',
|
|
32
|
+
parentName: 'parent',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(instance).toBeDefined();
|
|
36
|
+
expect(spy).toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('About Click', () => {
|
|
41
|
+
it('when About item is clicked, should call parent onAboutClick method', () => {
|
|
42
|
+
const parent = instantiateAndCreate({
|
|
43
|
+
name: 'TekUserInfo',
|
|
44
|
+
component: 'TekUserInfo',
|
|
45
|
+
defaultEmail: 'zeedhi@zd.com',
|
|
46
|
+
});
|
|
47
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => (parent));
|
|
48
|
+
|
|
49
|
+
const spy = jest.spyOn(parent, 'onAboutClick');
|
|
50
|
+
const instance = new TekUserInfoList({
|
|
51
|
+
name: 'TekUserInfo',
|
|
52
|
+
component: 'TekUserInfoList',
|
|
53
|
+
parentName: 'parent',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const item = new ListItem(instance.items[1]);
|
|
57
|
+
item.click();
|
|
58
|
+
|
|
59
|
+
expect(spy).toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('Report Click', () => {
|
|
64
|
+
it('when Report item is clicked, should call parent onReportClick method', () => {
|
|
65
|
+
const parent = instantiateAndCreate({
|
|
66
|
+
name: 'TekUserInfo',
|
|
67
|
+
component: 'TekUserInfo',
|
|
68
|
+
defaultEmail: 'zeedhi@zd.com',
|
|
69
|
+
});
|
|
70
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => (parent));
|
|
71
|
+
|
|
72
|
+
const spy = jest.spyOn(parent, 'onReportClick');
|
|
73
|
+
const instance = new TekUserInfoList({
|
|
74
|
+
name: 'TekUserInfo',
|
|
75
|
+
component: 'TekUserInfoList',
|
|
76
|
+
parentName: 'parent',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const item = new ListItem(instance.items[2]);
|
|
80
|
+
item.click();
|
|
81
|
+
|
|
82
|
+
expect(spy).toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|