@sankhyalabs/core 5.20.0-dev.9 → 5.20.0-rc.10
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/.docs/classes/Change.md +11 -11
- package/.docs/classes/DataUnit.md +145 -115
- package/.docs/classes/ObjectUtils.md +48 -0
- package/.docs/classes/OverflowWatcher.md +310 -46
- package/.docs/classes/SelectionInfo.md +11 -11
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/globals.md +6 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/dist/dataunit/DataUnit.d.ts +7 -2
- package/dist/dataunit/DataUnit.js +31 -20
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +7 -5
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/metadata/DataType.js +3 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/ObjectUtils.d.ts +14 -0
- package/dist/utils/ObjectUtils.js +18 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +35 -7
- package/dist/utils/OverflowWatcher/index.js +140 -59
- package/dist/utils/OverflowWatcher/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +151 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +35 -21
- package/src/dataunit/formatting/PrettyFormatter.ts +6 -5
- package/src/dataunit/metadata/DataType.ts +3 -0
- package/src/dataunit/state/slice/SelectionSlice.ts +1 -1
- package/src/index.ts +6 -3
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/ObjectUtils.ts +20 -0
- package/src/utils/OverflowWatcher/index.ts +170 -78
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- package/test/util/OverflowWatcher.spec.ts +152 -118
|
@@ -1,118 +1,152 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
describe('OverflowWatcher',
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
import OverflowWatcher, { OverFlowWatcherParams, OverflowDirection, OVERFLOWED_CLASS_NAME } from '../../src/utils/OverflowWatcher';
|
|
2
|
+
|
|
3
|
+
describe('OverflowWatcher', () => {
|
|
4
|
+
let mockElement: HTMLElement;
|
|
5
|
+
let mockCallback: jest.Mock;
|
|
6
|
+
let watcherInstance: OverflowWatcher;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockElement = document.createElement('div');
|
|
10
|
+
Object.defineProperty(mockElement, 'clientWidth', { value: 90, configurable: true });
|
|
11
|
+
document.body.appendChild(mockElement);
|
|
12
|
+
mockCallback = jest.fn();
|
|
13
|
+
|
|
14
|
+
const params: OverFlowWatcherParams = {
|
|
15
|
+
element: mockElement,
|
|
16
|
+
callback: mockCallback,
|
|
17
|
+
overFlowDirection: OverflowDirection.HORIZONTAL,
|
|
18
|
+
debounce: 1,
|
|
19
|
+
deltaSize: 1,
|
|
20
|
+
notOverFlow: ['testId'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
watcherInstance = new OverflowWatcher(params);
|
|
24
|
+
mockElement.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(200));
|
|
25
|
+
setPrivateField(watcherInstance, '_lastContainerSize', 100);
|
|
26
|
+
setPrivateField(watcherInstance, '_lastContainerInstance', mockElement);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
watcherInstance.destroy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should initialize with provided parameters', () => {
|
|
34
|
+
expect(watcherInstance).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should disconect ResizeObserver when destroy is called', () => {
|
|
38
|
+
const disconnectSpy = jest.spyOn(ResizeObserver.prototype, 'disconnect');
|
|
39
|
+
watcherInstance.destroy();
|
|
40
|
+
expect(disconnectSpy).toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('Should call callback on forceUpdate', () => {
|
|
44
|
+
appendMockedChildren(mockElement);
|
|
45
|
+
watcherInstance.forceUpdate();
|
|
46
|
+
expect(mockCallback).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('Should call callback on forceUpdate with childSpan', () => {
|
|
50
|
+
appendMockedChildren(mockElement);
|
|
51
|
+
watcherInstance.forceUpdate();
|
|
52
|
+
|
|
53
|
+
const childSpan = mockElement.children[1];
|
|
54
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Should call callback on forceUpdate with childSpan when notOverFlow is empty', () => {
|
|
58
|
+
appendMockedChildren(mockElement);
|
|
59
|
+
|
|
60
|
+
const params: OverFlowWatcherParams = {
|
|
61
|
+
element: mockElement,
|
|
62
|
+
callback: mockCallback,
|
|
63
|
+
overFlowDirection: OverflowDirection.HORIZONTAL,
|
|
64
|
+
debounce: 1,
|
|
65
|
+
deltaSize: 1,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const withNoOverFlow = new OverflowWatcher(params);
|
|
69
|
+
setPrivateField(withNoOverFlow, '_lastContainerSize', 100);
|
|
70
|
+
setPrivateField(withNoOverFlow, '_lastContainerInstance', mockElement);
|
|
71
|
+
|
|
72
|
+
withNoOverFlow.forceUpdate();
|
|
73
|
+
|
|
74
|
+
const childSpan = mockElement.children[1];
|
|
75
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('Should call callback on forceUpdate with childSpan considering overflowed elements', () => {
|
|
79
|
+
appendMockedChildren(mockElement);
|
|
80
|
+
const childButton = mockElement.children[0];
|
|
81
|
+
const childSpan = mockElement.children[1];
|
|
82
|
+
childSpan.classList.add(OVERFLOWED_CLASS_NAME);
|
|
83
|
+
|
|
84
|
+
const hiddemItemsMock: Map<Element, {size: number, margin: number}> = new Map();
|
|
85
|
+
hiddemItemsMock.set(childSpan, {size: 50, margin: 0});
|
|
86
|
+
hiddemItemsMock.set(childButton, {size: 0, margin: 50});
|
|
87
|
+
setPrivateField(watcherInstance, '_hiddenItemsProps', hiddemItemsMock);
|
|
88
|
+
|
|
89
|
+
watcherInstance.forceUpdate();
|
|
90
|
+
|
|
91
|
+
expect(mockCallback).toHaveBeenCalledWith(expect.arrayContaining([childSpan]));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('Should call callback on forceUpdate with empty list', () => {
|
|
95
|
+
appendMockedChildren(mockElement);
|
|
96
|
+
setPrivateField(watcherInstance, '_lastContainerSize', 200);
|
|
97
|
+
watcherInstance.forceUpdate();
|
|
98
|
+
const childButton = mockElement.children[0];
|
|
99
|
+
const childSpan = mockElement.children[1];
|
|
100
|
+
|
|
101
|
+
expect(mockCallback).not.toHaveBeenCalledWith(expect.arrayContaining([childButton, childSpan]));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should ignore elements that can not overflow', () => {
|
|
105
|
+
appendMockedChildren(mockElement);
|
|
106
|
+
|
|
107
|
+
const notOverflowElement = document.createElement('div');
|
|
108
|
+
notOverflowElement.setAttribute('data-element-id', 'testId') ;
|
|
109
|
+
notOverflowElement.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
110
|
+
|
|
111
|
+
const notOverflowElement2 = document.createElement('div');
|
|
112
|
+
notOverflowElement2.setAttribute('data-element-id', 'testId2') ;
|
|
113
|
+
notOverflowElement2.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
114
|
+
|
|
115
|
+
mockElement.appendChild(notOverflowElement);
|
|
116
|
+
mockElement.appendChild(notOverflowElement2);
|
|
117
|
+
|
|
118
|
+
watcherInstance.addNotOverFlowElement('testId');
|
|
119
|
+
watcherInstance.addNotOverFlowElement('testId2');
|
|
120
|
+
|
|
121
|
+
watcherInstance.forceUpdate();
|
|
122
|
+
|
|
123
|
+
expect(mockCallback).not.toHaveBeenCalledWith(expect.arrayContaining([notOverflowElement]));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('Should not call callback on forceUpdate', () => {
|
|
127
|
+
watcherInstance.forceUpdate();
|
|
128
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
function appendMockedChildren(mockElement: HTMLElement) {
|
|
134
|
+
const chilldButton = document.createElement('button');
|
|
135
|
+
const childSpan = document.createElement('span');
|
|
136
|
+
|
|
137
|
+
chilldButton.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
138
|
+
childSpan.getBoundingClientRect = jest.fn().mockReturnValue(getMockedRectClientValue(50));
|
|
139
|
+
|
|
140
|
+
mockElement.appendChild(chilldButton);
|
|
141
|
+
mockElement.appendChild(childSpan);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function getMockedRectClientValue(size: number) {
|
|
145
|
+
return {
|
|
146
|
+
x: 0, y: 0, width: size, height: 10, top: 0, right: 0, bottom: 0, left: 0, toJSON: () => {}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function setPrivateField<T>(instance: T, fieldName: string, value: any): void {
|
|
151
|
+
(instance as any)[fieldName] = value;
|
|
152
|
+
}
|