@zeedhi/teknisa-components-common 3.0.0 → 3.0.1
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/.package.json +4 -1
- package/dist/teknisa-components-common.js +3722 -32
- package/dist/teknisa-components-common.min.js +3722 -32
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
- package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
- package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
- package/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
- package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
- package/dist/types/components/tek-grid/index.d.ts +18 -0
- package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
- package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
- package/dist/types/components/tek-grid/layout-options.d.ts +39 -0
- package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
- package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
- package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
- package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
- package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
- package/dist/types/error/teknisa-common-error.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/config/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
- package/dist/types/utils/is-nil.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/index.ts +5 -12
- package/src/components/tek-datasource/index.ts +3 -0
- package/src/components/tek-datasource/interfaces.ts +36 -0
- package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
- package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
- package/src/components/tek-grid/columns-searcher.ts +22 -0
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
- package/src/components/tek-grid/filter-helper.ts +20 -0
- package/src/components/tek-grid/grid-filter-button.ts +419 -0
- package/src/components/tek-grid/grouped-data-manager.ts +448 -0
- package/src/components/tek-grid/grouped-data-selector.ts +40 -0
- package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
- package/src/components/tek-grid/index.ts +18 -0
- package/src/components/tek-grid/interfaces.ts +329 -0
- package/src/components/tek-grid/keymap-grouped.ts +20 -0
- package/src/components/tek-grid/layout-options.ts +248 -0
- package/src/components/tek-grid/tek-grid-column.ts +193 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
- package/src/components/tek-grid/tek-grid-controller.ts +140 -0
- package/src/components/tek-grid/tek-grid-events.ts +105 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
- package/src/components/tek-grid/tek-grid.ts +1118 -0
- package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
- package/src/components/tek-user-info/interfaces.ts +21 -0
- package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
- package/src/components/tek-user-info/tek-user-info.ts +337 -0
- package/src/error/tek-grid-delete-rows-error.ts +15 -0
- package/src/error/teknisa-common-error.ts +8 -0
- package/src/index.ts +1 -0
- package/src/utils/config/config.ts +8 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/is-filled-object/is-filled-object.ts +5 -0
- package/src/utils/is-nil.ts +3 -0
- package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +110 -241
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
- package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +77 -35
- package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
- package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +48 -6
- package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
- package/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { GroupedDataSelector } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('GroupedDataSelector', () => {
|
|
4
|
+
let groupedDataSelector: GroupedDataSelector;
|
|
5
|
+
let mockIterable: any;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
mockIterable = {
|
|
9
|
+
selectionState: { allSelected: false, except: [] },
|
|
10
|
+
selectedRows: [],
|
|
11
|
+
selectable: true,
|
|
12
|
+
isGrouped: jest.fn(),
|
|
13
|
+
getGroupedData: jest.fn(),
|
|
14
|
+
getData: jest.fn(),
|
|
15
|
+
getRowKey: jest.fn((row) => row.id),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
groupedDataSelector = new GroupedDataSelector(mockIterable);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('selectAll', () => {
|
|
22
|
+
it('should do nothing if iterable is not selectable', () => {
|
|
23
|
+
mockIterable.selectable = false;
|
|
24
|
+
groupedDataSelector.selectAll(true);
|
|
25
|
+
expect(mockIterable.selectionState).toEqual({ allSelected: false, except: [] });
|
|
26
|
+
expect(mockIterable.selectedRows).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const testData = [
|
|
30
|
+
{ id: 1, name: 'Item 1' },
|
|
31
|
+
{ id: 2, name: 'Item 2' },
|
|
32
|
+
{ id: 3, name: 'Item 3' },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
it('when selecting all, should set selectionState and add all rows to selectedRows', () => {
|
|
36
|
+
mockIterable.getData = jest.fn(() => testData);
|
|
37
|
+
groupedDataSelector.selectAll(true);
|
|
38
|
+
|
|
39
|
+
expect(mockIterable.selectionState).toEqual({ allSelected: true, except: [] });
|
|
40
|
+
expect(mockIterable.selectedRows).toEqual(testData);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('when selecting all, should skip rows where callDisableSelection returns true', () => {
|
|
44
|
+
mockIterable.getData = jest.fn(() => testData);
|
|
45
|
+
groupedDataSelector.callDisableSelection = jest.fn((row) => row.id === 2);
|
|
46
|
+
|
|
47
|
+
groupedDataSelector.selectAll(true);
|
|
48
|
+
|
|
49
|
+
expect(mockIterable.selectedRows).toEqual([
|
|
50
|
+
{ id: 1, name: 'Item 1' },
|
|
51
|
+
{ id: 3, name: 'Item 3' },
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('when selecting all, should skip rows that are already selected', () => {
|
|
56
|
+
mockIterable.getData = jest.fn(() => testData);
|
|
57
|
+
mockIterable.selectedRows = [testData[0]];
|
|
58
|
+
|
|
59
|
+
groupedDataSelector.selectAll(true);
|
|
60
|
+
|
|
61
|
+
expect(mockIterable.selectedRows).toEqual(testData); // should not duplicate
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('when selecting all, should work with grouped data', () => {
|
|
65
|
+
const groupedData = [
|
|
66
|
+
{ id: 1, group: '1' }, { id: 2, group: '1' }, { id: 3, group: '2' },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
mockIterable.isGrouped = jest.fn(() => true);
|
|
70
|
+
mockIterable.getGroupedData = jest.fn(() => groupedData);
|
|
71
|
+
|
|
72
|
+
groupedDataSelector.selectAll(true);
|
|
73
|
+
|
|
74
|
+
expect(mockIterable.selectedRows).toEqual(groupedData);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('when deselecting all, should set selectionState and remove all rows from selectedRows', () => {
|
|
78
|
+
mockIterable.getData = jest.fn(() => testData);
|
|
79
|
+
mockIterable.selectedRows = [...testData];
|
|
80
|
+
groupedDataSelector.selectAll(false);
|
|
81
|
+
|
|
82
|
+
expect(mockIterable.selectionState).toEqual({ allSelected: false, except: [] });
|
|
83
|
+
expect(mockIterable.selectedRows).toEqual([]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('when deselecting all, should only remove rows that exist in the data', () => {
|
|
87
|
+
mockIterable.getData = jest.fn(() => []);
|
|
88
|
+
mockIterable.selectedRows.push({ id: 99, name: 'Extra item' });
|
|
89
|
+
|
|
90
|
+
groupedDataSelector.selectAll(false);
|
|
91
|
+
|
|
92
|
+
expect(mockIterable.selectedRows).toEqual([{ id: 99, name: 'Extra item' }]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('when deselecting all, should work with grouped data', () => {
|
|
96
|
+
const groupedData = [
|
|
97
|
+
{ id: 1, group: '1' }, { id: 2, group: '1' }, { id: 3, group: '2' },
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
mockIterable.isGrouped = jest.fn(() => true);
|
|
101
|
+
mockIterable.getGroupedData = jest.fn(() => groupedData);
|
|
102
|
+
|
|
103
|
+
groupedDataSelector.selectAll(false);
|
|
104
|
+
|
|
105
|
+
expect(mockIterable.selectedRows).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('getData', () => {
|
|
110
|
+
it('should call getGroupedData when iterable is grouped', () => {
|
|
111
|
+
mockIterable.isGrouped.mockReturnValue(true);
|
|
112
|
+
const expectedData = [{ group: 'Test', items: [] }];
|
|
113
|
+
mockIterable.getGroupedData.mockReturnValue(expectedData);
|
|
114
|
+
|
|
115
|
+
// @ts-ignore - access private method for testing
|
|
116
|
+
const result = groupedDataSelector.getData();
|
|
117
|
+
|
|
118
|
+
expect(result).toEqual(expectedData);
|
|
119
|
+
expect(mockIterable.isGrouped).toHaveBeenCalled();
|
|
120
|
+
expect(mockIterable.getGroupedData).toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should call getData when iterable is not grouped', () => {
|
|
124
|
+
mockIterable.isGrouped.mockReturnValue(false);
|
|
125
|
+
const expectedData = [{ id: 1 }, { id: 2 }];
|
|
126
|
+
mockIterable.getData.mockReturnValue(expectedData);
|
|
127
|
+
|
|
128
|
+
// @ts-ignore - access private method for testing
|
|
129
|
+
const result = groupedDataSelector.getData();
|
|
130
|
+
|
|
131
|
+
expect(result).toEqual(expectedData);
|
|
132
|
+
expect(mockIterable.isGrouped).toHaveBeenCalled();
|
|
133
|
+
expect(mockIterable.getData).toHaveBeenCalled();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { IEventParam } from '@zeedhi/core';
|
|
2
|
+
import { GroupedViewNavigator, ViewNavigator } from '../../../../src';
|
|
3
|
+
import { spyOnAllMethods } from '../../__helpers__';
|
|
4
|
+
|
|
5
|
+
describe('GroupedViewNavigator', () => {
|
|
6
|
+
let navigator: GroupedViewNavigator;
|
|
7
|
+
let mockGrid: any;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockGrid = {
|
|
11
|
+
isGrouped: jest.fn(),
|
|
12
|
+
cellSelection: false,
|
|
13
|
+
getGroupedData: jest.fn(),
|
|
14
|
+
datasource: { currentRow: {} } as any,
|
|
15
|
+
getRowKey: jest.fn(),
|
|
16
|
+
isItemVisible: jest.fn().mockReturnValue(true),
|
|
17
|
+
setCurrentRow: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
navigator = new GroupedViewNavigator(mockGrid);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
jest.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('constructor', () => {
|
|
28
|
+
it('should initialize with the provided grid', () => {
|
|
29
|
+
expect(navigator).toBeInstanceOf(GroupedViewNavigator);
|
|
30
|
+
// @ts-ignore - access protected property for testing
|
|
31
|
+
expect(navigator.grid).toBe(mockGrid);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('basic navigation methods', () => {
|
|
36
|
+
it('should delegate to ViewNavigator', () => {
|
|
37
|
+
const spyObj = spyOnAllMethods(ViewNavigator.prototype);
|
|
38
|
+
|
|
39
|
+
const param = {} as IEventParam<any>;
|
|
40
|
+
navigator.navigateLeft(param);
|
|
41
|
+
expect(spyObj.navigateLeft).toHaveBeenCalledWith(param);
|
|
42
|
+
|
|
43
|
+
navigator.navigateRight(param);
|
|
44
|
+
expect(spyObj.navigateRight).toHaveBeenCalledWith(param);
|
|
45
|
+
|
|
46
|
+
const fn = jest.fn();
|
|
47
|
+
navigator.setViewNavigate(fn);
|
|
48
|
+
expect(spyObj.setViewNavigate).toHaveBeenCalledWith(fn);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('getRowIndex', () => {
|
|
53
|
+
const groupedData = [
|
|
54
|
+
{ group: true, groupValue: 'Group1' },
|
|
55
|
+
{ id: 1, name: 'Item1' },
|
|
56
|
+
{ id: 2, name: 'Item2' },
|
|
57
|
+
{ group: true, groupValue: 'Group2' },
|
|
58
|
+
{ id: 3, name: 'Item3' },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
it('should return provided index if given', () => {
|
|
62
|
+
// @ts-ignore - access private method for testing
|
|
63
|
+
const result = navigator.getRowIndex(groupedData, 2);
|
|
64
|
+
expect(result).toBe(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should find index by groupValue when currentRow is a group', () => {
|
|
68
|
+
mockGrid.datasource.currentRow = { group: true, groupValue: 'Group2' };
|
|
69
|
+
// @ts-ignore - access private method for testing
|
|
70
|
+
const result = navigator.getRowIndex(groupedData);
|
|
71
|
+
expect(result).toBe(3);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should find index by rowKey when currentRow is not a group', () => {
|
|
75
|
+
mockGrid.datasource.currentRow = { id: 2, name: 'Item2' };
|
|
76
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
77
|
+
// @ts-ignore - access private method for testing
|
|
78
|
+
const result = navigator.getRowIndex(groupedData);
|
|
79
|
+
expect(result).toBe(2);
|
|
80
|
+
expect(mockGrid.getRowKey).toHaveBeenCalledWith({ id: 2, name: 'Item2' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should return -1 when row not found', () => {
|
|
84
|
+
mockGrid.datasource.currentRow = { id: 99, name: 'NotFound' };
|
|
85
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
86
|
+
// @ts-ignore - access private method for testing
|
|
87
|
+
const result = navigator.getRowIndex(groupedData);
|
|
88
|
+
expect(result).toBe(-1);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('navigateUp', () => {
|
|
93
|
+
const groupedData = [
|
|
94
|
+
{ group: true, groupValue: 'Group1' },
|
|
95
|
+
{ id: 1, name: 'Item1' },
|
|
96
|
+
{ id: 2, name: 'Item2' },
|
|
97
|
+
{ group: true, groupValue: 'Group2' },
|
|
98
|
+
{ id: 3, name: 'Item3' },
|
|
99
|
+
{ groupFooter: true, groupValue: 'Group2' },
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
mockGrid.getGroupedData.mockReturnValue(groupedData);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should delegate to ViewNavigator when not grouped or cellSelection is true', () => {
|
|
107
|
+
const spyObj = spyOnAllMethods(ViewNavigator.prototype);
|
|
108
|
+
|
|
109
|
+
mockGrid.isGrouped.mockReturnValue(false);
|
|
110
|
+
navigator.navigateUp();
|
|
111
|
+
expect(spyObj.navigateUp).toHaveBeenCalled();
|
|
112
|
+
|
|
113
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
114
|
+
mockGrid.cellSelection = true;
|
|
115
|
+
navigator.navigateUp();
|
|
116
|
+
expect(spyObj.navigateUp).toHaveBeenCalledTimes(2);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should do nothing when groupedData is empty', () => {
|
|
120
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
121
|
+
mockGrid.getGroupedData.mockReturnValue([]);
|
|
122
|
+
navigator.navigateUp();
|
|
123
|
+
expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should navigate to previous visible row', () => {
|
|
127
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
128
|
+
mockGrid.datasource.currentRow = groupedData[2]; // Item2
|
|
129
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
130
|
+
|
|
131
|
+
navigator.navigateUp();
|
|
132
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[1]); // Item1
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should skip group footers and invisible items', () => {
|
|
136
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
137
|
+
mockGrid.datasource.currentRow = groupedData[4]; // Item3
|
|
138
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
139
|
+
mockGrid.isItemVisible.mockImplementation((row: any) => !row.groupFooter);
|
|
140
|
+
|
|
141
|
+
navigator.navigateUp();
|
|
142
|
+
// Should skip groupFooter and land on Group2
|
|
143
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[3]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should recursively find previous visible item', () => {
|
|
147
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
148
|
+
mockGrid.datasource.currentRow = groupedData[4]; // Item3
|
|
149
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
150
|
+
// Make Group2 invisible
|
|
151
|
+
mockGrid.isItemVisible.mockImplementation((row: any) => row !== groupedData[3]);
|
|
152
|
+
|
|
153
|
+
navigator.navigateUp();
|
|
154
|
+
// Should skip invisible Group2 and land on Item2
|
|
155
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[2]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should stop at beginning of list', () => {
|
|
159
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
160
|
+
mockGrid.datasource.currentRow = groupedData[0]; // Group1
|
|
161
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.groupValue);
|
|
162
|
+
|
|
163
|
+
navigator.navigateUp();
|
|
164
|
+
expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should navigate to last row when currentRow is not defined', () => {
|
|
168
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
169
|
+
mockGrid.datasource.currentRow = {};
|
|
170
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
171
|
+
|
|
172
|
+
navigator.navigateUp();
|
|
173
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[4]);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('navigateDown', () => {
|
|
178
|
+
const groupedData = [
|
|
179
|
+
{ group: true, groupValue: 'Group1' },
|
|
180
|
+
{ id: 1, name: 'Item1' },
|
|
181
|
+
{ id: 2, name: 'Item2' },
|
|
182
|
+
{ group: true, groupValue: 'Group2' },
|
|
183
|
+
{ id: 3, name: 'Item3' }
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
mockGrid.getGroupedData.mockReturnValue(groupedData);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should delegate to ViewNavigator when not grouped or cellSelection is true', () => {
|
|
191
|
+
const spyObj = spyOnAllMethods(ViewNavigator.prototype);
|
|
192
|
+
|
|
193
|
+
mockGrid.isGrouped.mockReturnValue(false);
|
|
194
|
+
navigator.navigateDown();
|
|
195
|
+
expect(spyObj.navigateDown).toHaveBeenCalled();
|
|
196
|
+
|
|
197
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
198
|
+
mockGrid.cellSelection = true;
|
|
199
|
+
navigator.navigateDown();
|
|
200
|
+
expect(spyObj.navigateDown).toHaveBeenCalledTimes(2);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should navigate to next visible row', () => {
|
|
204
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
205
|
+
mockGrid.datasource.currentRow = groupedData[1]; // Item1
|
|
206
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
207
|
+
|
|
208
|
+
navigator.navigateDown();
|
|
209
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[2]); // Item2
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should skip group footers and invisible items', () => {
|
|
213
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
214
|
+
mockGrid.datasource.currentRow = groupedData[3]; // Group2
|
|
215
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.groupValue);
|
|
216
|
+
mockGrid.isItemVisible.mockImplementation((row: any) => !row.groupFooter);
|
|
217
|
+
|
|
218
|
+
navigator.navigateDown();
|
|
219
|
+
// Should skip groupFooter and land on Item3
|
|
220
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[4]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should recursively find next visible item', () => {
|
|
224
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
225
|
+
mockGrid.datasource.currentRow = groupedData[1]; // Item1
|
|
226
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
227
|
+
// Make Item2 invisible
|
|
228
|
+
mockGrid.isItemVisible.mockImplementation((row: any) => row !== groupedData[2]);
|
|
229
|
+
|
|
230
|
+
navigator.navigateDown();
|
|
231
|
+
// Should skip invisible Item2 and land on Group2
|
|
232
|
+
expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[3]);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should do nothing when at end of list', () => {
|
|
236
|
+
mockGrid.isGrouped.mockReturnValue(true);
|
|
237
|
+
mockGrid.datasource.currentRow = groupedData[4];
|
|
238
|
+
mockGrid.getRowKey.mockImplementation((row: any) => row.id);
|
|
239
|
+
|
|
240
|
+
navigator.navigateDown();
|
|
241
|
+
expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KeyMapGrouped } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('KeyMapGrouped', () => {
|
|
4
|
+
it('should return a keymap', () => {
|
|
5
|
+
const instance = { directionalLeft: jest.fn(), directionalRight: jest.fn() } as any;
|
|
6
|
+
const keyMap = new KeyMapGrouped().getMap(instance);
|
|
7
|
+
expect(keyMap).toEqual(expect.objectContaining({
|
|
8
|
+
left: {
|
|
9
|
+
event: expect.any(Function),
|
|
10
|
+
stop: true,
|
|
11
|
+
active: true,
|
|
12
|
+
},
|
|
13
|
+
right: {
|
|
14
|
+
event: expect.any(Function),
|
|
15
|
+
stop: true,
|
|
16
|
+
active: true,
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
});
|