@zeedhi/teknisa-components-common 3.0.3 → 3.1.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 +6 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +100 -0
- package/coverage/lcov-report/tests/__helpers__/create-component.ts.html +109 -0
- package/coverage/lcov-report/tests/__helpers__/find-component.ts.html +139 -0
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +94 -0
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +166 -0
- package/coverage/lcov-report/tests/__helpers__/index.html +221 -0
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +106 -0
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +121 -0
- package/coverage/lcov-report/tests/__helpers__/spy-on-all-methods.ts.html +223 -0
- package/coverage/lcov.info +0 -0
- package/dist/teknisa-components-common.js +73 -67
- package/dist/teknisa-components-common.min.js +73 -67
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +16 -16
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +18 -20
- package/dist/types/components/tek-grid/grouped-data-navigator.d.ts +12 -0
- package/dist/types/components/tek-grid/index.d.ts +1 -1
- package/dist/types/components/tek-grid/tek-grid.d.ts +2 -1
- package/dist/types/components/tek-loading/interfaces.d.ts +6 -0
- package/dist/types/components/tek-loading/loading.d.ts +16 -0
- package/environments.json +12 -0
- package/jest.config.cjs +23 -0
- package/package.json +5 -3
- package/src/components/index.ts +2 -2
- package/src/components/tek-datasource/tek-memory-datasource.ts +2 -2
- package/src/components/tek-datasource/tek-rest-datasource.ts +2 -2
- package/src/components/tek-grid/grid-filter-button.ts +5 -3
- package/src/components/tek-grid/grouped-data-navigator.ts +66 -0
- package/src/components/tek-grid/index.ts +1 -1
- package/src/components/tek-grid/tek-grid-column.ts +1 -1
- package/src/components/tek-grid/tek-grid.ts +19 -15
- package/src/components/tek-loading/interfaces.ts +7 -0
- package/src/components/tek-loading/loading.ts +27 -0
- package/tests/__helpers__/create-component.ts +8 -0
- package/tests/__helpers__/find-component.ts +18 -0
- package/tests/__helpers__/index.ts +4 -0
- package/tests/__helpers__/spy-on-all-methods.ts +46 -0
- package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +2 -1
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +4 -1
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +1 -1
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +8 -4
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +1 -1
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +1 -1
- package/tests/unit/components/tek-grid/grouped-data-navigator.spec.ts +143 -0
- package/tests/unit/components/tek-grid/layout-options.spec.ts +1 -1
- package/tests/unit/components/tek-grid/tek-grid-column.spec.ts +23 -17
- package/tests/unit/components/tek-grid/tek-grid-columns-button.spec.ts +2 -1
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +14 -12
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +1 -1
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +1 -1
- package/tests/unit/components/tek-loading/loading.spec.ts +29 -0
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +12 -2
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +18 -6
- package/tests/unit/utils/mock-console.ts +18 -0
- package/tests/unit/utils/setup.ts +5 -0
- package/dist/types/error/delete-rows-error.d.ts +0 -6
- package/jest.config.js +0 -1
- package/src/components/tek-grid/grouped-view-navigator.ts +0 -84
- package/tests/unit/components/crud/crud-add-button.spec.ts +0 -56
- package/tests/unit/components/crud/crud-button.spec.ts +0 -94
- package/tests/unit/components/crud/crud-cancel-button.spec.ts +0 -91
- package/tests/unit/components/crud/crud-delete-button.spec.ts +0 -122
- package/tests/unit/components/crud/crud-form.spec.ts +0 -165
- package/tests/unit/components/crud/crud-save-button.spec.ts +0 -118
- package/tests/unit/components/tek-card-title/CardTitle.spec.ts +0 -34
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +0 -112
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +0 -244
- package/tests/unit/components/tek-grid/multi-option.spec.ts +0 -139
- package/tests/unit/components/tek-image/Image.spec.ts +0 -67
- package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +0 -37
- package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +0 -200
- package/tests/unit/components/tek-loading/Loading.spec.ts +0 -30
- package/tests/unit/components/tek-notifications/notifications.spec.ts +0 -201
- package/tests/unit/components/tek-product-card/product-card.spec.ts +0 -61
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +0 -776
- package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +0 -44
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +0 -135
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +0 -174
- package/tests/unit/utils/report-filter/report-filter.spec.ts +0 -66
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
TekGridLayoutOptions,
|
|
8
8
|
ITekGridProps,
|
|
9
9
|
} from '../../../../src';
|
|
10
|
-
import { flushPromises } from '
|
|
10
|
+
import { flushPromises } from '../../../__helpers__';
|
|
11
11
|
|
|
12
12
|
let savedLayouts: string = '';
|
|
13
13
|
const testLayouts: ITekGridLayoutInfo = {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
TekGrid,
|
|
8
8
|
TekGridColumn,
|
|
9
9
|
} from '../../../../src';
|
|
10
|
-
import { flushPromises } from '
|
|
10
|
+
import { flushPromises } from '../../../__helpers__';
|
|
11
11
|
|
|
12
12
|
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
13
13
|
|
|
@@ -123,16 +123,19 @@ describe('TekGridColumn', () => {
|
|
|
123
123
|
describe('getLookupData()', () => {
|
|
124
124
|
it('should get lookup data', async () => {
|
|
125
125
|
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
126
|
+
grid.onCreated();
|
|
126
127
|
const column = new TekGridColumn(baseProps, grid);
|
|
127
128
|
column.initialize();
|
|
128
129
|
|
|
129
130
|
let data = column.getLookupData('name', 'employee 1');
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
setTimeout(async () => {
|
|
132
|
+
expect(data).toEqual({});
|
|
133
|
+
|
|
134
|
+
await flushPromises();
|
|
135
|
+
data = column.getLookupData('name', 'employee 1');
|
|
136
|
+
expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
|
|
137
|
+
expect(httpSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
}, 500);
|
|
136
139
|
});
|
|
137
140
|
|
|
138
141
|
it('should get lookup data using memory', async () => {
|
|
@@ -156,21 +159,24 @@ describe('TekGridColumn', () => {
|
|
|
156
159
|
|
|
157
160
|
it('should get lookup data using filter when storeData is false', async () => {
|
|
158
161
|
const grid = new TekGrid({ name: 'grid', component: 'TekGrid' });
|
|
162
|
+
grid.onCreated();
|
|
159
163
|
baseProps.storeData = false;
|
|
160
164
|
const column = new TekGridColumn(baseProps, grid);
|
|
161
165
|
column.initialize();
|
|
162
166
|
|
|
163
167
|
let data = column.getLookupData('name', 'employee 1');
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
setTimeout(async () => {
|
|
169
|
+
expect(data).toEqual({});
|
|
170
|
+
|
|
171
|
+
await flushPromises();
|
|
172
|
+
data = column.getLookupData('name', 'employee 1');
|
|
173
|
+
expect(data).toEqual({ id: 1, name: 'employee 1', department: 1 });
|
|
174
|
+
expect(httpSpy).toHaveBeenCalledWith('/zeedhi', expect.objectContaining({
|
|
175
|
+
params: expect.objectContaining({
|
|
176
|
+
name: ['employee 1'],
|
|
177
|
+
}),
|
|
178
|
+
}));
|
|
179
|
+
}, 500);
|
|
174
180
|
});
|
|
175
181
|
});
|
|
176
182
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { I18n, Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
2
|
-
import {
|
|
2
|
+
import { Grid, Checkbox } from '@zeedhi/common';
|
|
3
|
+
import { TekGrid, TekGridColumnsButton, TekGridColumnsButtonController, ITekGridProps } from '../../../../src';
|
|
3
4
|
|
|
4
5
|
const setupInstance = (props: Partial<ITekGridProps> = {}) => {
|
|
5
6
|
const instance = new TekGrid({
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Button,
|
|
5
4
|
TekGrid, TekGridColumn,
|
|
6
|
-
ComponentRender,
|
|
7
5
|
ITekGridAtoms,
|
|
8
6
|
TekRestDatasource,
|
|
9
7
|
DynamicFilterDatasourceFactory,
|
|
10
|
-
KeyMapMerger,
|
|
11
8
|
TekMemoryDatasource,
|
|
12
9
|
ITekGridProps,
|
|
13
10
|
} from '../../../../src';
|
|
@@ -19,18 +16,23 @@ import {
|
|
|
19
16
|
Newable,
|
|
20
17
|
} from '@zeedhi/core';
|
|
21
18
|
import {
|
|
19
|
+
Button,
|
|
20
|
+
ComponentRender,
|
|
21
|
+
KeyMapMerger,
|
|
22
22
|
IterableTable,
|
|
23
|
+
TableActionBuilder,
|
|
24
|
+
DataEditorWithAdd,
|
|
25
|
+
ViewNavigator,
|
|
26
|
+
} from '@zeedhi/common';
|
|
27
|
+
import {
|
|
23
28
|
GroupedDataSelector,
|
|
24
29
|
TekGridEvents,
|
|
25
|
-
DataNavigator,
|
|
26
|
-
TableActionBuilder,
|
|
27
30
|
ColumnsSearcher,
|
|
28
31
|
GroupedDataManager,
|
|
29
32
|
TekGridToolbarProvider,
|
|
30
|
-
|
|
31
|
-
DataEditorWithAdd,
|
|
33
|
+
GroupedDataNavigator,
|
|
32
34
|
} from '../../../../src';
|
|
33
|
-
import { createComponent, findComponent, setClick, spyOnAllMethods } from '
|
|
35
|
+
import { createComponent, findComponent, setClick, spyOnAllMethods } from '../../../__helpers__';
|
|
34
36
|
|
|
35
37
|
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
36
38
|
|
|
@@ -688,8 +690,8 @@ describe('TekGrid', () => {
|
|
|
688
690
|
expect(spyObj.selectGroupClick).toHaveBeenCalledWith({ id: 1 }, true, {}, undefined);
|
|
689
691
|
});
|
|
690
692
|
|
|
691
|
-
it('should call
|
|
692
|
-
const spyObj = spyOnAllMethods(
|
|
693
|
+
it('should call GroupedDataNavigator delegation methods', () => {
|
|
694
|
+
const spyObj = spyOnAllMethods(GroupedDataNavigator.prototype);
|
|
693
695
|
const instance = new TekGrid(mockProps);
|
|
694
696
|
|
|
695
697
|
instance.navigatePageUp();
|
|
@@ -702,8 +704,8 @@ describe('TekGrid', () => {
|
|
|
702
704
|
expect(spyObj.navigateDatasource).toHaveBeenCalledWith('up');
|
|
703
705
|
});
|
|
704
706
|
|
|
705
|
-
it('should call
|
|
706
|
-
const spyObj = spyOnAllMethods(
|
|
707
|
+
it('should call ViewNavigator delegation methods', () => {
|
|
708
|
+
const spyObj = spyOnAllMethods(ViewNavigator.prototype);
|
|
707
709
|
const instance = new TekGrid(mockProps);
|
|
708
710
|
|
|
709
711
|
instance.setViewNavigate(() => {});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Loading } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('Loading', () => {
|
|
4
|
+
describe('constructor()', () => {
|
|
5
|
+
it('should create a loading with default values', () => {
|
|
6
|
+
const instance = new Loading({
|
|
7
|
+
name: 'loading',
|
|
8
|
+
component: 'TekLoading',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
expect(instance.text).toBe('');
|
|
12
|
+
expect(instance.image).toMatch(/^data:image\/gif;base64,/);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should replace the default values with provided properties', () => {
|
|
16
|
+
const instance = new Loading({
|
|
17
|
+
name: 'loading',
|
|
18
|
+
component: 'TekLoading',
|
|
19
|
+
image: '/img/zeedhi.svg',
|
|
20
|
+
text: 'zeedhi',
|
|
21
|
+
zIndex: '99',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(instance.image).toBe('/img/zeedhi.svg');
|
|
25
|
+
expect(instance.text).toBe('zeedhi');
|
|
26
|
+
expect(instance.zIndex).toBe('99');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ListItem } from '@zeedhi/common';
|
|
2
|
-
import { Metadata } from '@zeedhi/core';
|
|
2
|
+
import { Loader, Metadata, SimpleControllerBuilder } from '@zeedhi/core';
|
|
3
3
|
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
4
4
|
import { TekUserInfo, TekUserInfoList, type ITekUserInfo } from '../../../../src';
|
|
5
5
|
import { mockCreated } from '../../../__helpers__/mock-created-helper';
|
|
@@ -12,11 +12,18 @@ function instantiateAndCreate(props: ITekUserInfo) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
describe('TekUserInfoList', () => {
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
Loader.setBuilder(new SimpleControllerBuilder());
|
|
17
|
+
});
|
|
18
|
+
|
|
15
19
|
afterEach(() => jest.clearAllMocks());
|
|
16
20
|
|
|
17
21
|
describe('constructor()', () => {
|
|
18
22
|
it('when parent is not defined, should throw', () => {
|
|
19
|
-
expect(() =>
|
|
23
|
+
expect(() => {
|
|
24
|
+
const instance = new TekUserInfoList({ name: 'TekUserInfo', component: 'TekUserInfoList' });
|
|
25
|
+
instance.onCreated();
|
|
26
|
+
}).toThrow();
|
|
20
27
|
});
|
|
21
28
|
|
|
22
29
|
it('when parentName is defined, should call Metadata.getInstance', () => {
|
|
@@ -34,6 +41,7 @@ describe('TekUserInfoList', () => {
|
|
|
34
41
|
});
|
|
35
42
|
|
|
36
43
|
expect(instance).toBeDefined();
|
|
44
|
+
instance.onCreated();
|
|
37
45
|
expect(spy).toHaveBeenCalled();
|
|
38
46
|
});
|
|
39
47
|
});
|
|
@@ -54,6 +62,7 @@ describe('TekUserInfoList', () => {
|
|
|
54
62
|
parentName: 'parent',
|
|
55
63
|
});
|
|
56
64
|
|
|
65
|
+
instance.onCreated();
|
|
57
66
|
const item = new ListItem(instance.items[1]);
|
|
58
67
|
item.click();
|
|
59
68
|
|
|
@@ -77,6 +86,7 @@ describe('TekUserInfoList', () => {
|
|
|
77
86
|
parentName: 'parent',
|
|
78
87
|
});
|
|
79
88
|
|
|
89
|
+
instance.onCreated();
|
|
80
90
|
const item = new ListItem(instance.items[2]);
|
|
81
91
|
item.click();
|
|
82
92
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button, ListItem, type Modal, ModalService,
|
|
3
3
|
} from '@zeedhi/common';
|
|
4
|
-
import { Metadata, Http } from '@zeedhi/core';
|
|
4
|
+
import { Metadata, Http, Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
5
5
|
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
6
6
|
import { type ITekUserInfo, TekUserInfo, TekUserInfoList } from '../../../../src';
|
|
7
7
|
import { mockCreated } from '../../../__helpers__/mock-created-helper';
|
|
8
|
+
import { flushPromises } from '../../../__helpers__';
|
|
8
9
|
|
|
9
10
|
function instantiateAndCreate(props: ITekUserInfo) {
|
|
10
11
|
const instance = new TekUserInfo(props);
|
|
@@ -14,6 +15,10 @@ function instantiateAndCreate(props: ITekUserInfo) {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
describe('TekUserInfo', () => {
|
|
18
|
+
beforeAll(() => {
|
|
19
|
+
Loader.setBuilder(new SimpleControllerBuilder());
|
|
20
|
+
});
|
|
21
|
+
|
|
17
22
|
afterEach(() => jest.clearAllMocks());
|
|
18
23
|
|
|
19
24
|
describe('constructor()', () => {
|
|
@@ -247,16 +252,20 @@ describe('TekUserInfo', () => {
|
|
|
247
252
|
spy.mockClear();
|
|
248
253
|
});
|
|
249
254
|
|
|
250
|
-
it('when send button is clicked, should call onSendReport event', () => {
|
|
251
|
-
|
|
255
|
+
it('when send button is clicked, should call onSendReport event', async () => {
|
|
256
|
+
let onSendReportCalled = false;
|
|
252
257
|
const spy = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => ({
|
|
253
|
-
validate: () =>
|
|
258
|
+
validate: async () => {
|
|
259
|
+
return { valid: true };
|
|
260
|
+
},
|
|
254
261
|
}));
|
|
255
262
|
const instance = instantiateAndCreate({
|
|
256
263
|
name: 'TekUserInfo',
|
|
257
264
|
component: 'TekUserInfo',
|
|
258
265
|
events: {
|
|
259
|
-
onSendReport
|
|
266
|
+
onSendReport: () => {
|
|
267
|
+
onSendReportCalled = true;
|
|
268
|
+
},
|
|
260
269
|
},
|
|
261
270
|
});
|
|
262
271
|
instance.onReportClick();
|
|
@@ -265,7 +274,9 @@ describe('TekUserInfo', () => {
|
|
|
265
274
|
|
|
266
275
|
buttonInstance.click();
|
|
267
276
|
|
|
268
|
-
|
|
277
|
+
await flushPromises();
|
|
278
|
+
|
|
279
|
+
expect(onSendReportCalled).toBeTruthy()
|
|
269
280
|
spy.mockClear();
|
|
270
281
|
});
|
|
271
282
|
|
|
@@ -408,6 +419,7 @@ describe('TekUserInfo', () => {
|
|
|
408
419
|
const spy = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => (instance));
|
|
409
420
|
|
|
410
421
|
const list = new TekUserInfoList({ parentName: 'UserInfo', ...instance.bottomSlot[0] });
|
|
422
|
+
list.onCreated();
|
|
411
423
|
const versionInfo = new ListItem({ ...list.items[0] });
|
|
412
424
|
const about = new ListItem({ ...list.items[1] });
|
|
413
425
|
const reportError = new ListItem({ ...list.items[2] });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const originalWarn = console.warn;
|
|
2
|
+
const originalError = console.error;
|
|
3
|
+
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
jest.spyOn(console, 'warn').mockImplementation((...args) => {
|
|
6
|
+
// Oculta apenas mensagens específicas
|
|
7
|
+
if (args.join(' ').includes('Duplicate component name detected')
|
|
8
|
+
|| args.join(' ').includes('Row datasource do not have a key')
|
|
9
|
+
|| args.join(' ').includes('Nenhum datasource foi passado para o componente')) return;
|
|
10
|
+
return originalWarn(...args);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
14
|
+
// Oculta apenas mensagens específicas
|
|
15
|
+
if (args.join(' ').includes('Controller ') && args.join(' ').includes(' not found')) return;
|
|
16
|
+
return originalError(...args);
|
|
17
|
+
});
|
|
18
|
+
});
|
package/jest.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../../jest.config.js');
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { IEventParam, IDictionary } from '@zeedhi/core';
|
|
2
|
-
import { Direction, IViewNavigator, ViewNavigator } from '@zeedhi/common';
|
|
3
|
-
import { ITekGrid } from './interfaces';
|
|
4
|
-
|
|
5
|
-
export class GroupedViewNavigator implements IViewNavigator {
|
|
6
|
-
private viewNavigator: ViewNavigator;
|
|
7
|
-
|
|
8
|
-
protected grid: ITekGrid;
|
|
9
|
-
|
|
10
|
-
constructor(iterable: ITekGrid) {
|
|
11
|
-
this.viewNavigator = new ViewNavigator();
|
|
12
|
-
this.grid = iterable;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
navigateLeft(param: IEventParam<any>): void {
|
|
16
|
-
this.viewNavigator.navigateLeft(param);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
navigateRight(param: IEventParam<any>): void {
|
|
20
|
-
this.viewNavigator.navigateRight(param);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setViewNavigate(viewNavigate: (direction: Direction, event?: Event) => void): void {
|
|
24
|
-
this.viewNavigator.setViewNavigate(viewNavigate);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private getRowIndex(groupedData: IDictionary[], index?: number) {
|
|
28
|
-
if (index) return index;
|
|
29
|
-
|
|
30
|
-
const { currentRow } = this.grid.datasource;
|
|
31
|
-
return groupedData.findIndex((row) => {
|
|
32
|
-
if (currentRow.group) {
|
|
33
|
-
return row.group && row.groupValue === currentRow.groupValue;
|
|
34
|
-
}
|
|
35
|
-
const rowKey = this.grid.getRowKey(row);
|
|
36
|
-
const currentRowKey = this.grid.getRowKey(currentRow);
|
|
37
|
-
return rowKey && rowKey === currentRowKey;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public navigateUp(index?: number) {
|
|
42
|
-
if (!this.grid.isGrouped() || this.grid.cellSelection) {
|
|
43
|
-
this.viewNavigator.navigateUp();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const groupedData = this.grid.getGroupedData();
|
|
47
|
-
|
|
48
|
-
if (!groupedData.length || index === -1) return;
|
|
49
|
-
|
|
50
|
-
let rowIndex: number = this.getRowIndex(groupedData, index);
|
|
51
|
-
|
|
52
|
-
if (rowIndex === -1) rowIndex = groupedData.length;
|
|
53
|
-
|
|
54
|
-
const newRow = groupedData[rowIndex - 1];
|
|
55
|
-
|
|
56
|
-
if (!newRow || !this.grid.isItemVisible(newRow) || newRow.groupFooter) {
|
|
57
|
-
this.navigateUp(rowIndex - 1);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.grid.setCurrentRow(newRow);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public navigateDown(index?: number) {
|
|
65
|
-
if (!this.grid.isGrouped() || this.grid.cellSelection) {
|
|
66
|
-
this.viewNavigator.navigateDown();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const groupedData = this.grid.getGroupedData();
|
|
70
|
-
|
|
71
|
-
if (!groupedData.length || index === groupedData.length) return;
|
|
72
|
-
|
|
73
|
-
const rowIndex = this.getRowIndex(groupedData, index);
|
|
74
|
-
|
|
75
|
-
const newRow = groupedData[rowIndex + 1];
|
|
76
|
-
|
|
77
|
-
if (!newRow || !this.grid.isItemVisible(newRow) || newRow.groupFooter) {
|
|
78
|
-
this.navigateDown(rowIndex + 1);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.grid.setCurrentRow(newRow);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { CrudAddButton } from '../../../../src';
|
|
2
|
-
|
|
3
|
-
describe('CrudAddButton', () => {
|
|
4
|
-
describe('constructor()', () => {
|
|
5
|
-
it('should create new CrudAddButton with default values', () => {
|
|
6
|
-
const instance = new CrudAddButton({
|
|
7
|
-
name: 'saveButton',
|
|
8
|
-
component: 'TekCrudSaveButton',
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(instance.clickShortcutKey).toBe('f2');
|
|
12
|
-
expect(instance.dark).toBeFalsy();
|
|
13
|
-
expect(instance.disabled).toBeFalsy();
|
|
14
|
-
expect(instance.fab).toBeFalsy();
|
|
15
|
-
expect(instance.fixed).toBeFalsy();
|
|
16
|
-
expect(instance.flat).toBeTruthy();
|
|
17
|
-
expect(instance.href).toBe('');
|
|
18
|
-
expect(instance.icon).toBeTruthy();
|
|
19
|
-
expect(instance.iconName).toBe('plus');
|
|
20
|
-
expect(instance.label).toBe('');
|
|
21
|
-
expect(instance.color).toBe('#666');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should create new CrudAddButton replace default values', () => {
|
|
25
|
-
const instance = new CrudAddButton({
|
|
26
|
-
name: 'saveButton',
|
|
27
|
-
component: 'TekCrudSaveButton',
|
|
28
|
-
clickShortcutKey: 'f3',
|
|
29
|
-
flat: true,
|
|
30
|
-
icon: false,
|
|
31
|
-
color: '#ddd',
|
|
32
|
-
iconName: 'complete',
|
|
33
|
-
});
|
|
34
|
-
expect(instance.clickShortcutKey).toBe('f3');
|
|
35
|
-
expect(instance.color).toBe('#ddd');
|
|
36
|
-
expect(instance.fixed).toBeFalsy();
|
|
37
|
-
expect(instance.flat).toBeTruthy();
|
|
38
|
-
expect(instance.icon).toBeFalsy();
|
|
39
|
-
expect(instance.iconName).toBe('complete');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('click()', () => {
|
|
43
|
-
const method = () => undefined;
|
|
44
|
-
const instance = new CrudAddButton({
|
|
45
|
-
name: 'saveButton',
|
|
46
|
-
component: 'TekCrudSaveButton',
|
|
47
|
-
clickShortcutKey: 'f2',
|
|
48
|
-
events: { click: method },
|
|
49
|
-
});
|
|
50
|
-
const spy = jest.spyOn((instance.events as any), 'click');
|
|
51
|
-
instance.click({} as Event, {} as HTMLElement);
|
|
52
|
-
expect(spy).toHaveBeenCalledWith({ component: instance, event: {}, element: {} });
|
|
53
|
-
spy.mockClear();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { GridEditable } from '@zeedhi/common';
|
|
2
|
-
import { KeyMap } from '@zeedhi/core';
|
|
3
|
-
import { CrudButton, CrudForm } from '../../../../src';
|
|
4
|
-
|
|
5
|
-
const dispatchEvent = (key: string, modifiers: any, repeated = false) => {
|
|
6
|
-
let prevented = false;
|
|
7
|
-
const event = new KeyboardEvent('keydown', modifiers);
|
|
8
|
-
delete (event as any).key;
|
|
9
|
-
Object.defineProperty(event, 'key', { value: key });
|
|
10
|
-
delete (event as any).code;
|
|
11
|
-
Object.defineProperty(event, 'code', { value: key });
|
|
12
|
-
|
|
13
|
-
if (repeated) {
|
|
14
|
-
delete (event as any).repeat;
|
|
15
|
-
Object.defineProperty(event, 'repeat', { value: true });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
delete (event as any).preventDefault;
|
|
19
|
-
Object.defineProperty(event, 'preventDefault', {
|
|
20
|
-
value: () => {
|
|
21
|
-
prevented = true;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
document.dispatchEvent(event);
|
|
25
|
-
return prevented;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
describe('CrudButton', () => {
|
|
29
|
-
describe('constructor()', () => {
|
|
30
|
-
it('should init KeyMap', () => {
|
|
31
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
32
|
-
const element = document.createElement('div');
|
|
33
|
-
expect(instance.initKeyMap(element)).toBe(undefined);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should init shortcutClick', () => {
|
|
37
|
-
let called = false;
|
|
38
|
-
const method = () => { called = true; };
|
|
39
|
-
const keyMap = {
|
|
40
|
-
a: {
|
|
41
|
-
event: method,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const instance = new CrudButton({
|
|
45
|
-
name: 'button',
|
|
46
|
-
component: 'tekCrudButton',
|
|
47
|
-
clickShortcutKey: 'a',
|
|
48
|
-
keyMap,
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
KeyMap.bind(instance.keyMap);
|
|
53
|
-
dispatchEvent('a', {});
|
|
54
|
-
expect(called).toBeFalsy();
|
|
55
|
-
KeyMap.unbind(instance.keyMap);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should init shortcutClick disabled', () => {
|
|
59
|
-
let called = false;
|
|
60
|
-
const method = () => { called = true; };
|
|
61
|
-
const keyMap = {
|
|
62
|
-
a: {
|
|
63
|
-
event: method,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const instance = new CrudButton({
|
|
67
|
-
name: 'button',
|
|
68
|
-
component: 'tekCrudButton',
|
|
69
|
-
clickShortcutKey: 'a',
|
|
70
|
-
disabled: true,
|
|
71
|
-
keyMap,
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
KeyMap.bind(instance.keyMap);
|
|
76
|
-
dispatchEvent('a', {});
|
|
77
|
-
expect(called).toBeFalsy();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('parent instanceof CrudForm', () => {
|
|
81
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
82
|
-
const crudForm = new CrudForm({ name: 'grid', component: 'CrudForm' });
|
|
83
|
-
instance.parent = crudForm;
|
|
84
|
-
expect(instance.parentIsEditing).toBeFalsy();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('parent instanceof GridEditable', () => {
|
|
88
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
89
|
-
const crudForm = new GridEditable({ name: 'grid', component: 'CrudForm' });
|
|
90
|
-
instance.parent = crudForm;
|
|
91
|
-
expect(instance.parentIsEditing).toBeFalsy();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|