@theia/test 1.43.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/lib/browser/constants.d.ts +46 -0
- package/lib/browser/constants.d.ts.map +1 -0
- package/lib/browser/constants.js +18 -0
- package/lib/browser/constants.js.map +1 -0
- package/lib/browser/test-service.d.ts +150 -0
- package/lib/browser/test-service.d.ts.map +1 -0
- package/lib/browser/test-service.js +240 -0
- package/lib/browser/test-service.js.map +1 -0
- package/lib/browser/view/test-execution-state-manager.d.ts +14 -0
- package/lib/browser/view/test-execution-state-manager.d.ts.map +1 -0
- package/lib/browser/view/test-execution-state-manager.js +174 -0
- package/lib/browser/view/test-execution-state-manager.js.map +1 -0
- package/lib/browser/view/test-output-ui-model.d.ts +46 -0
- package/lib/browser/view/test-output-ui-model.d.ts.map +1 -0
- package/lib/browser/view/test-output-ui-model.js +140 -0
- package/lib/browser/view/test-output-ui-model.js.map +1 -0
- package/lib/browser/view/test-output-view-contribution.d.ts +6 -0
- package/lib/browser/view/test-output-view-contribution.d.ts.map +1 -0
- package/lib/browser/view/test-output-view-contribution.js +48 -0
- package/lib/browser/view/test-output-view-contribution.js.map +1 -0
- package/lib/browser/view/test-output-widget.d.ts +25 -0
- package/lib/browser/view/test-output-widget.d.ts.map +1 -0
- package/lib/browser/view/test-output-widget.js +159 -0
- package/lib/browser/view/test-output-widget.js.map +1 -0
- package/lib/browser/view/test-result-view-contribution.d.ts +6 -0
- package/lib/browser/view/test-result-view-contribution.d.ts.map +1 -0
- package/lib/browser/view/test-result-view-contribution.js +48 -0
- package/lib/browser/view/test-result-view-contribution.js.map +1 -0
- package/lib/browser/view/test-result-widget.d.ts +21 -0
- package/lib/browser/view/test-result-widget.d.ts.map +1 -0
- package/lib/browser/view/test-result-widget.js +109 -0
- package/lib/browser/view/test-result-widget.js.map +1 -0
- package/lib/browser/view/test-run-view-contribution.d.ts +18 -0
- package/lib/browser/view/test-run-view-contribution.d.ts.map +1 -0
- package/lib/browser/view/test-run-view-contribution.js +101 -0
- package/lib/browser/view/test-run-view-contribution.js.map +1 -0
- package/lib/browser/view/test-run-widget.d.ts +59 -0
- package/lib/browser/view/test-run-widget.d.ts.map +1 -0
- package/lib/browser/view/test-run-widget.js +306 -0
- package/lib/browser/view/test-run-widget.js.map +1 -0
- package/lib/browser/view/test-tree-widget.d.ts +68 -0
- package/lib/browser/view/test-tree-widget.d.ts.map +1 -0
- package/lib/browser/view/test-tree-widget.js +387 -0
- package/lib/browser/view/test-tree-widget.js.map +1 -0
- package/lib/browser/view/test-view-contribution.d.ts +46 -0
- package/lib/browser/view/test-view-contribution.d.ts.map +1 -0
- package/lib/browser/view/test-view-contribution.js +289 -0
- package/lib/browser/view/test-view-contribution.js.map +1 -0
- package/lib/browser/view/test-view-frontend-module.d.ts +7 -0
- package/lib/browser/view/test-view-frontend-module.d.ts.map +1 -0
- package/lib/browser/view/test-view-frontend-module.js +120 -0
- package/lib/browser/view/test-view-frontend-module.js.map +1 -0
- package/lib/common/collections.d.ts +47 -0
- package/lib/common/collections.d.ts.map +1 -0
- package/lib/common/collections.js +211 -0
- package/lib/common/collections.js.map +1 -0
- package/lib/common/tree-delta.d.ts +52 -0
- package/lib/common/tree-delta.d.ts.map +1 -0
- package/lib/common/tree-delta.js +241 -0
- package/lib/common/tree-delta.js.map +1 -0
- package/lib/common/tree-delta.spec.d.ts +2 -0
- package/lib/common/tree-delta.spec.d.ts.map +1 -0
- package/lib/common/tree-delta.spec.js +140 -0
- package/lib/common/tree-delta.spec.js.map +1 -0
- package/package.json +53 -0
- package/src/browser/constants.ts +71 -0
- package/src/browser/style/index.css +42 -0
- package/src/browser/test-service.ts +347 -0
- package/src/browser/view/test-execution-state-manager.ts +147 -0
- package/src/browser/view/test-output-ui-model.ts +148 -0
- package/src/browser/view/test-output-view-contribution.ts +34 -0
- package/src/browser/view/test-output-widget.ts +148 -0
- package/src/browser/view/test-result-view-contribution.ts +34 -0
- package/src/browser/view/test-result-widget.ts +92 -0
- package/src/browser/view/test-run-view-contribution.ts +89 -0
- package/src/browser/view/test-run-widget.tsx +266 -0
- package/src/browser/view/test-tree-widget.tsx +360 -0
- package/src/browser/view/test-view-contribution.ts +300 -0
- package/src/browser/view/test-view-frontend-module.ts +132 -0
- package/src/common/collections.ts +223 -0
- package/src/common/tree-delta.spec.ts +166 -0
- package/src/common/tree-delta.ts +259 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import '../../../src/browser/style/index.css';
|
|
18
|
+
|
|
19
|
+
import { interfaces, ContainerModule, Container } from '@theia/core/shared/inversify';
|
|
20
|
+
import {
|
|
21
|
+
bindViewContribution, FrontendApplicationContribution,
|
|
22
|
+
WidgetFactory, ViewContainer,
|
|
23
|
+
WidgetManager, createTreeContainer
|
|
24
|
+
} from '@theia/core/lib/browser';
|
|
25
|
+
import { TestTree, TestTreeWidget } from './test-tree-widget';
|
|
26
|
+
import { TestViewContribution, TEST_VIEW_CONTAINER_ID, TEST_VIEW_CONTAINER_TITLE_OPTIONS, TEST_VIEW_CONTEXT_MENU } from './test-view-contribution';
|
|
27
|
+
import { TestService, TestContribution, DefaultTestService } from '../test-service';
|
|
28
|
+
import { bindContributionProvider } from '@theia/core';
|
|
29
|
+
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
|
30
|
+
import { TestExecutionStateManager } from './test-execution-state-manager';
|
|
31
|
+
import { TestResultWidget } from './test-result-widget';
|
|
32
|
+
import { TestOutputWidget } from './test-output-widget';
|
|
33
|
+
import { TestOutputViewContribution } from './test-output-view-contribution';
|
|
34
|
+
import { TestOutputUIModel } from './test-output-ui-model';
|
|
35
|
+
import { TestRunTree, TestRunTreeWidget } from './test-run-widget';
|
|
36
|
+
import { TestResultViewContribution } from './test-result-view-contribution';
|
|
37
|
+
import { TEST_RUNS_CONTEXT_MENU, TestRunViewContribution } from './test-run-view-contribution';
|
|
38
|
+
|
|
39
|
+
export default new ContainerModule(bind => {
|
|
40
|
+
|
|
41
|
+
bindContributionProvider(bind, TestContribution);
|
|
42
|
+
bind(TestService).to(DefaultTestService).inSingletonScope();
|
|
43
|
+
|
|
44
|
+
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
|
45
|
+
id: TestOutputWidget.ID,
|
|
46
|
+
createWidget: () => container.get<TestOutputWidget>(TestOutputWidget)
|
|
47
|
+
})).inSingletonScope();
|
|
48
|
+
|
|
49
|
+
bind(TestOutputWidget).toSelf();
|
|
50
|
+
|
|
51
|
+
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
|
52
|
+
id: TestResultWidget.ID,
|
|
53
|
+
createWidget: () => container.get<TestResultWidget>(TestResultWidget)
|
|
54
|
+
})).inSingletonScope();
|
|
55
|
+
|
|
56
|
+
bind(TestResultWidget).toSelf();
|
|
57
|
+
|
|
58
|
+
bind(TestTreeWidget).toDynamicValue(({ container }) => {
|
|
59
|
+
const child = createTestTreeContainer(container);
|
|
60
|
+
return child.get(TestTreeWidget);
|
|
61
|
+
});
|
|
62
|
+
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
|
63
|
+
id: TestTreeWidget.ID,
|
|
64
|
+
createWidget: () => container.get<TestTreeWidget>(TestTreeWidget)
|
|
65
|
+
})).inSingletonScope();
|
|
66
|
+
|
|
67
|
+
bind(TestRunTreeWidget).toDynamicValue(({ container }) => {
|
|
68
|
+
const child = createTestRunContainer(container);
|
|
69
|
+
return child.get(TestRunTreeWidget);
|
|
70
|
+
});
|
|
71
|
+
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
|
72
|
+
id: TestRunTreeWidget.ID,
|
|
73
|
+
createWidget: () => container.get<TestRunTreeWidget>(TestRunTreeWidget)
|
|
74
|
+
})).inSingletonScope();
|
|
75
|
+
|
|
76
|
+
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
|
77
|
+
id: TEST_VIEW_CONTAINER_ID,
|
|
78
|
+
createWidget: async () => {
|
|
79
|
+
const viewContainer = container.get<ViewContainer.Factory>(ViewContainer.Factory)({
|
|
80
|
+
id: TEST_VIEW_CONTAINER_ID,
|
|
81
|
+
progressLocationId: 'test'
|
|
82
|
+
});
|
|
83
|
+
viewContainer.setTitleOptions(TEST_VIEW_CONTAINER_TITLE_OPTIONS);
|
|
84
|
+
let widget = await container.get(WidgetManager).getOrCreateWidget(TestTreeWidget.ID);
|
|
85
|
+
viewContainer.addWidget(widget, {
|
|
86
|
+
canHide: false,
|
|
87
|
+
initiallyCollapsed: false
|
|
88
|
+
});
|
|
89
|
+
widget = await container.get(WidgetManager).getOrCreateWidget(TestRunTreeWidget.ID);
|
|
90
|
+
viewContainer.addWidget(widget, {
|
|
91
|
+
canHide: true,
|
|
92
|
+
initiallyCollapsed: false,
|
|
93
|
+
}); return viewContainer;
|
|
94
|
+
}
|
|
95
|
+
})).inSingletonScope();
|
|
96
|
+
|
|
97
|
+
bindViewContribution(bind, TestViewContribution);
|
|
98
|
+
bindViewContribution(bind, TestRunViewContribution);
|
|
99
|
+
bindViewContribution(bind, TestResultViewContribution);
|
|
100
|
+
bindViewContribution(bind, TestOutputViewContribution);
|
|
101
|
+
bind(FrontendApplicationContribution).toService(TestViewContribution);
|
|
102
|
+
bind(TabBarToolbarContribution).toService(TestViewContribution);
|
|
103
|
+
bind(TabBarToolbarContribution).toService(TestRunViewContribution);
|
|
104
|
+
bind(TestExecutionStateManager).toSelf().inSingletonScope();
|
|
105
|
+
bind(TestOutputUIModel).toSelf().inSingletonScope();
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export function createTestTreeContainer(parent: interfaces.Container): Container {
|
|
110
|
+
return createTreeContainer(parent, {
|
|
111
|
+
tree: TestTree,
|
|
112
|
+
props: {
|
|
113
|
+
virtualized: false,
|
|
114
|
+
search: true,
|
|
115
|
+
contextMenuPath: TEST_VIEW_CONTEXT_MENU
|
|
116
|
+
},
|
|
117
|
+
widget: TestTreeWidget,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function createTestRunContainer(parent: interfaces.Container): Container {
|
|
122
|
+
return createTreeContainer(parent, {
|
|
123
|
+
tree: TestRunTree,
|
|
124
|
+
props: {
|
|
125
|
+
virtualized: false,
|
|
126
|
+
search: true,
|
|
127
|
+
multiSelect: false,
|
|
128
|
+
contextMenuPath: TEST_RUNS_CONTEXT_MENU
|
|
129
|
+
},
|
|
130
|
+
widget: TestRunTreeWidget
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { Event } from '@theia/core';
|
|
18
|
+
import { CollectionDelta, TreeDeltaBuilder } from './tree-delta';
|
|
19
|
+
import { Emitter } from '@theia/core/shared/vscode-languageserver-protocol';
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
export function observableProperty(observationFunction: string): (target: any, property: string) => any {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
return (target: any, property: string): any => {
|
|
25
|
+
Reflect.defineProperty(target, property, {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
get(): unknown { return this['_' + property]; },
|
|
28
|
+
set(v: unknown): void {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
this[observationFunction](property, v);
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
this['_' + property] = v;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class ChangeBatcher {
|
|
39
|
+
private handle: NodeJS.Timeout | undefined;
|
|
40
|
+
private startTime: number | undefined;
|
|
41
|
+
constructor(private emitBatch: () => void, readonly timeoutMs: number) {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
changeOccurred(): void {
|
|
45
|
+
if (!this.startTime) {
|
|
46
|
+
this.startTime = Date.now();
|
|
47
|
+
this.handle = setTimeout(() => {
|
|
48
|
+
this.flush();
|
|
49
|
+
}, this.timeoutMs);
|
|
50
|
+
} else {
|
|
51
|
+
if (Date.now() - this.startTime > this.timeoutMs) {
|
|
52
|
+
this.flush();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
flush(): void {
|
|
57
|
+
if (this.handle) {
|
|
58
|
+
clearTimeout(this.handle);
|
|
59
|
+
this.handle = undefined;
|
|
60
|
+
}
|
|
61
|
+
this.startTime = undefined;
|
|
62
|
+
this.emitBatch();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class SimpleObservableCollection<V> {
|
|
67
|
+
private _values: V[] = [];
|
|
68
|
+
|
|
69
|
+
constructor(private equals: (left: V, right: V) => boolean = (left, right) => left === right) {
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
add(value: V): boolean {
|
|
73
|
+
if (!this._values.find(v => this.equals(v, value))) {
|
|
74
|
+
this._values.push(value);
|
|
75
|
+
this.onChangeEmitter.fire({ added: [value] });
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
remove(value: V): boolean {
|
|
82
|
+
const index = this._values.findIndex(v => this.equals(v, value));
|
|
83
|
+
if (index >= 0) {
|
|
84
|
+
this._values.splice(index, 1);
|
|
85
|
+
this.onChangeEmitter.fire({ removed: [value] });
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private onChangeEmitter = new Emitter<CollectionDelta<V, V>>();
|
|
92
|
+
onChanged: Event<CollectionDelta<V, V>> = this.onChangeEmitter.event;
|
|
93
|
+
get values(): readonly V[] {
|
|
94
|
+
return this._values;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
clear(): void {
|
|
98
|
+
const copy = this._values;
|
|
99
|
+
this._values = [];
|
|
100
|
+
this.onChangeEmitter.fire({ removed: copy });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
abstract class AbstractIndexedCollection<K, T> {
|
|
105
|
+
private keys: Map<K, T> = new Map();
|
|
106
|
+
private _values: T[] | undefined;
|
|
107
|
+
|
|
108
|
+
abstract add(item: T): T | undefined;
|
|
109
|
+
|
|
110
|
+
get values(): readonly T[] {
|
|
111
|
+
if (!this._values) {
|
|
112
|
+
this._values = [...this.keys.values()];
|
|
113
|
+
}
|
|
114
|
+
return this._values;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get size(): number {
|
|
118
|
+
return this.keys.size;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
has(key: K): boolean {
|
|
122
|
+
return this.keys.has(key);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get(key: K): T | undefined {
|
|
126
|
+
return this.keys.get(key);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected doAdd(key: K, value: T): T | undefined {
|
|
130
|
+
const previous = this.keys.get(key);
|
|
131
|
+
if (previous !== undefined) {
|
|
132
|
+
return previous;
|
|
133
|
+
} else {
|
|
134
|
+
this.keys.set(key, value);
|
|
135
|
+
this._values = undefined;
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
remove(key: K): T | undefined {
|
|
141
|
+
const previous = this.keys.get(key);
|
|
142
|
+
if (previous !== undefined) {
|
|
143
|
+
this.keys.delete(key);
|
|
144
|
+
this._values = undefined;
|
|
145
|
+
return previous;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class TreeCollection<K, T, P> extends AbstractIndexedCollection<K, T> implements Iterable<[K, T]> {
|
|
152
|
+
|
|
153
|
+
constructor(protected readonly owner: T | P,
|
|
154
|
+
protected readonly pathOf: (v: T) => K[],
|
|
155
|
+
protected readonly deltaBuilder: (v: T | undefined) => TreeDeltaBuilder<K, T> | undefined) {
|
|
156
|
+
super();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
add(item: T): T | undefined {
|
|
160
|
+
const path = this.pathOf(item);
|
|
161
|
+
const previous = this.doAdd(path[path.length - 1], item);
|
|
162
|
+
const deltaBuilder = this.deltaBuilder(item);
|
|
163
|
+
if (deltaBuilder) {
|
|
164
|
+
if (previous) {
|
|
165
|
+
deltaBuilder.reportChanged(path, item);
|
|
166
|
+
} else {
|
|
167
|
+
deltaBuilder.reportAdded(path, item);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return previous;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
override remove(key: K): T | undefined {
|
|
174
|
+
const toRemove = this.get(key);
|
|
175
|
+
if (toRemove) {
|
|
176
|
+
const deltaBuilder = this.deltaBuilder(toRemove);
|
|
177
|
+
const path = this.pathOf(toRemove);
|
|
178
|
+
super.remove(key);
|
|
179
|
+
if (deltaBuilder) {
|
|
180
|
+
deltaBuilder.reportRemoved(path);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return toRemove;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
entries(): Iterator<[K, T], unknown, undefined> {
|
|
187
|
+
return this[Symbol.iterator]();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
[Symbol.iterator](): Iterator<[K, T], unknown, undefined> {
|
|
191
|
+
const iter = this.values.entries();
|
|
192
|
+
const that = this;
|
|
193
|
+
return {
|
|
194
|
+
next(..._args): IteratorResult<[K, T]> {
|
|
195
|
+
const res = iter.next();
|
|
196
|
+
if (res.done) {
|
|
197
|
+
return { done: true, value: res.value };
|
|
198
|
+
} else {
|
|
199
|
+
const path = that.pathOf(res.value[1]);
|
|
200
|
+
const result: [K, T] = [path[path.length - 1], res.value[1]];
|
|
201
|
+
return {
|
|
202
|
+
done: false,
|
|
203
|
+
value: result
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export function groupBy<K, T>(items: Iterable<T>, keyOf: (item: T) => K): Map<K, T[]> {
|
|
212
|
+
const result = new Map<K, T[]>();
|
|
213
|
+
for (const item of items) {
|
|
214
|
+
const key = keyOf(item);
|
|
215
|
+
let values = result.get(key);
|
|
216
|
+
if (!values) {
|
|
217
|
+
values = [];
|
|
218
|
+
result.set(key, values);
|
|
219
|
+
}
|
|
220
|
+
values.push(item);
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
|
|
16
|
+
import { DeltaKind, TreeDelta, TreeDeltaBuilderImpl } from './tree-delta';
|
|
17
|
+
import * as chai from 'chai';
|
|
18
|
+
|
|
19
|
+
const expect = chai.expect;
|
|
20
|
+
|
|
21
|
+
interface TestType {
|
|
22
|
+
id: string;
|
|
23
|
+
prop: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('TreeDeltaBuilder tests', () => {
|
|
27
|
+
|
|
28
|
+
it('should split paths', () => {
|
|
29
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
30
|
+
|
|
31
|
+
builder.reportAdded(['a', 'b', 'c'], {
|
|
32
|
+
id: 'c',
|
|
33
|
+
prop: 17
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
builder.reportRemoved(['a', 'b', 'd', 'e']);
|
|
37
|
+
|
|
38
|
+
const expected: TreeDelta<string, TestType> = {
|
|
39
|
+
path: ['a', 'b'],
|
|
40
|
+
type: DeltaKind.NONE,
|
|
41
|
+
childDeltas: [
|
|
42
|
+
{
|
|
43
|
+
path: ['d', 'e'],
|
|
44
|
+
type: DeltaKind.REMOVED,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: DeltaKind.ADDED,
|
|
48
|
+
path: ['c'],
|
|
49
|
+
value: { id: 'c', prop: 17 },
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
expect(builder.currentDelta).deep.equal([
|
|
55
|
+
expected
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should merge add/remove child', () => {
|
|
60
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
61
|
+
|
|
62
|
+
builder.reportAdded(['a', 'b', 'c'], {
|
|
63
|
+
id: 'c',
|
|
64
|
+
prop: 17
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
builder.reportRemoved(['a', 'b', 'c', 'd']);
|
|
68
|
+
|
|
69
|
+
expect(builder.currentDelta).deep.equal([{
|
|
70
|
+
path: ['a', 'b', 'c'],
|
|
71
|
+
type: DeltaKind.ADDED,
|
|
72
|
+
value: { id: 'c', prop: 17 },
|
|
73
|
+
}]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should merge change', () => {
|
|
77
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
78
|
+
|
|
79
|
+
builder.reportChanged(['a', 'b', 'c'], { id: 'c', prop: 17 });
|
|
80
|
+
builder.reportChanged(['a', 'b', 'c'], { prop: 18 });
|
|
81
|
+
builder.reportChanged(['a', 'b', 'c'], { prop: 19 });
|
|
82
|
+
|
|
83
|
+
expect(builder.currentDelta).deep.equal([
|
|
84
|
+
{
|
|
85
|
+
type: DeltaKind.CHANGED,
|
|
86
|
+
path: ['a', 'b', 'c'],
|
|
87
|
+
value: { id: 'c', prop: 19 },
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should merge add/change', () => {
|
|
93
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
94
|
+
|
|
95
|
+
const obj = {
|
|
96
|
+
id: 'c',
|
|
97
|
+
prop: 17
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
builder.reportAdded(['a', 'b', 'c'], obj);
|
|
101
|
+
|
|
102
|
+
obj.prop = 18;
|
|
103
|
+
|
|
104
|
+
builder.reportChanged(['a', 'b', 'c'], { prop: 18 });
|
|
105
|
+
|
|
106
|
+
expect(builder.currentDelta).deep.equal([
|
|
107
|
+
{
|
|
108
|
+
type: DeltaKind.ADDED,
|
|
109
|
+
path: ['a', 'b', 'c'],
|
|
110
|
+
value: { id: 'c', prop: 18 },
|
|
111
|
+
}
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should handle adds/delete', () => {
|
|
116
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
117
|
+
builder.reportAdded(['a', 'b'], { id: 'c', prop: 14 });
|
|
118
|
+
builder.reportRemoved(['a', 'b']);
|
|
119
|
+
expect(builder.currentDelta).deep.equal([]);
|
|
120
|
+
builder.reportAdded(['a', 'b'], { id: 'c', prop: 20 });
|
|
121
|
+
expect(builder.currentDelta).deep.equal([{
|
|
122
|
+
path: ['a', 'b'],
|
|
123
|
+
type: DeltaKind.ADDED,
|
|
124
|
+
value: { id: 'c', prop: 20 }
|
|
125
|
+
}]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should handle delete/add', () => {
|
|
129
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
130
|
+
builder.reportRemoved(['a', 'b']);
|
|
131
|
+
builder.reportAdded(['a', 'b'], { id: 'c', prop: 14 });
|
|
132
|
+
expect(builder.currentDelta).deep.equal([{
|
|
133
|
+
path: ['a', 'b'],
|
|
134
|
+
type: DeltaKind.CHANGED,
|
|
135
|
+
value: { id: 'c', prop: 14 }
|
|
136
|
+
}]);
|
|
137
|
+
builder.reportRemoved(['a', 'b']);
|
|
138
|
+
expect(builder.currentDelta).deep.equal([{
|
|
139
|
+
path: ['a', 'b'],
|
|
140
|
+
type: DeltaKind.REMOVED,
|
|
141
|
+
}]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should handle changed below changed', () => {
|
|
145
|
+
const builder = new TreeDeltaBuilderImpl<string, TestType>();
|
|
146
|
+
builder.reportChanged(['a', 'b', 'c', 'e'], { id: 'e', prop: 14 });
|
|
147
|
+
builder.reportChanged(['a', 'b', 'c', 'd'], { id: 'd', prop: 23 });
|
|
148
|
+
builder.reportChanged(['a', 'b', 'c'], { id: 'c', prop: 27 });
|
|
149
|
+
expect(builder.currentDelta).deep.equal([{
|
|
150
|
+
path: ['a', 'b', 'c'],
|
|
151
|
+
type: DeltaKind.CHANGED,
|
|
152
|
+
value: { id: 'c', prop: 27 },
|
|
153
|
+
childDeltas: [
|
|
154
|
+
{
|
|
155
|
+
path: ['d'],
|
|
156
|
+
type: DeltaKind.CHANGED,
|
|
157
|
+
value: { id: 'd', prop: 23 }
|
|
158
|
+
}, {
|
|
159
|
+
path: ['e'],
|
|
160
|
+
type: DeltaKind.CHANGED,
|
|
161
|
+
value: { id: 'e', prop: 14 }
|
|
162
|
+
}]
|
|
163
|
+
}]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
});
|