@eclipse-glsp/client 2.8.0-next.12 → 2.8.0-next.14

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.
Files changed (26) hide show
  1. package/lib/base/model/glsp-model-source.d.ts +1 -1
  2. package/lib/base/model/glsp-model-source.d.ts.map +1 -1
  3. package/lib/features/tool-palette/tool-palette.d.ts.map +1 -1
  4. package/lib/features/tool-palette/tool-palette.js +2 -4
  5. package/lib/features/tool-palette/tool-palette.js.map +1 -1
  6. package/package.json +7 -7
  7. package/src/base/model/glsp-model-source.ts +1 -1
  8. package/src/features/tool-palette/tool-palette.ts +2 -4
  9. package/src/base/action-dispatcher.spec.ts +0 -366
  10. package/src/base/feedback/feedback-emitter.spec.ts +0 -176
  11. package/src/base/model/model-initialization-constraint.spec.ts +0 -95
  12. package/src/base/selection-service.spec.ts +0 -318
  13. package/src/default-modules.spec.ts +0 -56
  14. package/src/features/bounds/freeform-layout.spec.ts +0 -216
  15. package/src/features/bounds/hbox-layout.spec.ts +0 -170
  16. package/src/features/bounds/layouter-test-util.spec.ts +0 -127
  17. package/src/features/bounds/vbox-layout.spec.ts +0 -170
  18. package/src/features/change-bounds/point-position-updater.spec.ts +0 -81
  19. package/src/features/grid/grid-snapper.spec.ts +0 -30
  20. package/src/features/hints/type-hint-provider.spec.ts +0 -360
  21. package/src/features/layout/layout-elements-action.spec.ts +0 -426
  22. package/src/features/navigation/navigation-target-resolver.spec.ts +0 -56
  23. package/src/features/routing/sticky-manhattan-edge-router.spec.ts +0 -212
  24. package/src/features/tools/marquee-selection/marquee-behavior.spec.ts +0 -176
  25. package/src/features/validation/marker-navigator.spec.ts +0 -183
  26. package/src/utils/gmodel-util.spec.ts +0 -221
@@ -1,176 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2024 EclipseSource 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { Action, Command, CommandExecutionContext, Disposable } from '@eclipse-glsp/sprotty';
17
- import { expect } from 'chai';
18
- import { IFeedbackActionDispatcher, IFeedbackEmitter } from './feedback-action-dispatcher';
19
- import { FeedbackEmitter } from './feedback-emitter';
20
-
21
- class MockFeedbackActionDispatcher implements IFeedbackActionDispatcher {
22
- protected feedbackEmitters: Map<IFeedbackEmitter, Action[]> = new Map();
23
-
24
- registerFeedback(feedbackEmitter: IFeedbackEmitter, actions: Action[]): Disposable {
25
- this.feedbackEmitters.set(feedbackEmitter, actions);
26
- return Disposable.create(() => this.deregisterFeedback(feedbackEmitter));
27
- }
28
-
29
- deregisterFeedback(feedbackEmitter: IFeedbackEmitter, _actions?: Action[]): void {
30
- this.feedbackEmitters.delete(feedbackEmitter);
31
- }
32
-
33
- getRegisteredFeedback(): Action[] {
34
- const result: Action[] = [];
35
- this.feedbackEmitters.forEach((value, key) => result.push(...value));
36
- return result;
37
- }
38
-
39
- getFeedbackCommands(): Command[] {
40
- return [];
41
- }
42
-
43
- createEmitter(): FeedbackEmitter {
44
- return new FeedbackEmitter(this);
45
- }
46
-
47
- async applyFeedbackCommands(context: CommandExecutionContext): Promise<void> {}
48
- }
49
-
50
- describe('FeedbackEmitter', () => {
51
- describe('Initial State', () => {
52
- it('On creation nothing should be submitted.', () => {
53
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
54
- const feedback = feedbackActionDispatcher.createEmitter();
55
- feedback.submit();
56
- expect(feedbackActionDispatcher['feedbackEmitters']).to.be.empty;
57
- });
58
- });
59
-
60
- describe('Adding Feedback', () => {
61
- it('Should add an action as part of the emitter feedback.', () => {
62
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
63
- const feedback = feedbackActionDispatcher.createEmitter();
64
- const action: Action = { kind: 'action' };
65
- feedback.add(action);
66
- expect(feedback['feedbackActions']).to.deep.equal([action]);
67
- });
68
-
69
- it('Should add an action and cleanup action as part of the emitter feedback.', () => {
70
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
71
- const feedback = feedbackActionDispatcher.createEmitter();
72
- const action: Action = { kind: 'action' };
73
- const cleanupAction: Action = { kind: 'cleanup' };
74
- feedback.add(action, cleanupAction);
75
- expect(feedback['feedbackActions']).to.deep.equal([action]);
76
- expect(feedback['cleanupActions']).to.deep.equal([cleanupAction]);
77
- });
78
- });
79
-
80
- describe('Merging Feedback', () => {
81
- it('Should merge the feedback of another emitter into this emitter.', () => {
82
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
83
- const feedback1 = feedbackActionDispatcher.createEmitter();
84
- const feedback2 = feedbackActionDispatcher.createEmitter();
85
- const action1: Action = { kind: 'action1' };
86
- const action2: Action = { kind: 'action2' };
87
- feedback1.add(action1);
88
- feedback2.add(action2);
89
- feedback1.merge(feedback2);
90
- expect(feedback1['feedbackActions']).to.deep.equal([action1, action2]);
91
- });
92
- });
93
-
94
- describe('Removing Feedback', () => {
95
- it('Should remove the action from the emitter feedback.', () => {
96
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
97
- const feedback = feedbackActionDispatcher.createEmitter();
98
- const action: Action = { kind: 'action' };
99
- feedback.add(action);
100
- feedback.remove(action);
101
- expect(feedback['feedbackActions']).to.be.empty;
102
- });
103
-
104
- it('Should remove the action together with the cleanup action from the emitter feedback.', () => {
105
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
106
- const feedback = feedbackActionDispatcher.createEmitter();
107
- const action: Action = { kind: 'action' };
108
- const cleanupAction: Action = { kind: 'cleanup' };
109
- feedback.add(action, cleanupAction);
110
- feedback.remove(action);
111
- expect(feedback['feedbackActions']).to.be.empty;
112
- expect(feedback['cleanupActions']).to.be.empty;
113
- });
114
- });
115
-
116
- describe('Clearing Feedback', () => {
117
- it('Should clear any pending feedback actions and cleanup actions.', () => {
118
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
119
- const feedback = feedbackActionDispatcher.createEmitter();
120
- const action: Action = { kind: 'action' };
121
- const cleanupAction: Action = { kind: 'cleanup' };
122
- feedback.add(action, cleanupAction);
123
- feedback.clear();
124
- expect(feedback['feedbackActions']).to.be.empty;
125
- expect(feedback['cleanupActions']).to.be.empty;
126
- });
127
- });
128
-
129
- describe('Submitting Feedback', () => {
130
- it('Should register any pending actions as feedback.', () => {
131
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
132
- const feedback = feedbackActionDispatcher.createEmitter();
133
- const action: Action = { kind: 'action' };
134
- feedback.add(action);
135
- feedback.submit();
136
- expect(feedbackActionDispatcher['feedbackEmitters'].size).to.equal(1);
137
- expect(feedbackActionDispatcher['feedbackEmitters'].get(feedback)).to.deep.equal([action]);
138
- });
139
- });
140
-
141
- describe('Discarding Feedback', () => {
142
- it('Should remove the registered feedback without calling any cleanup actions.', () => {
143
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
144
- const feedback = feedbackActionDispatcher.createEmitter();
145
- const action: Action = { kind: 'action' };
146
- feedback.add(action);
147
- feedback.submit();
148
- feedback.discard();
149
- expect(feedbackActionDispatcher['feedbackEmitters']).to.be.empty;
150
- });
151
- });
152
-
153
- describe('Reverting Feedback', () => {
154
- it('Should remove the registered feedback and call the registered cleanup actions.', () => {
155
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
156
- const feedback = feedbackActionDispatcher.createEmitter();
157
- const action: Action = { kind: 'action' };
158
- const cleanupAction: Action = { kind: 'cleanup' };
159
- feedback.add(action, cleanupAction);
160
- feedback.submit();
161
- feedback.revert();
162
- expect(feedbackActionDispatcher['feedbackEmitters']).to.be.empty;
163
- });
164
- });
165
-
166
- describe('Disposing Feedback', () => {
167
- it('Should dispose the registered feedback and any pending feedback actions.', () => {
168
- const feedbackActionDispatcher = new MockFeedbackActionDispatcher();
169
- const feedback = feedbackActionDispatcher.createEmitter();
170
- const action: Action = { kind: 'action' };
171
- feedback.add(action);
172
- feedback.dispose();
173
- expect(feedbackActionDispatcher['feedbackEmitters']).to.be.empty;
174
- });
175
- });
176
- });
@@ -1,95 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2023-2026 EclipseSource 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { expect } from 'chai';
17
- import { Container } from 'inversify';
18
- import 'reflect-metadata';
19
- import * as sinon from 'sinon';
20
- import { Deferred, EMPTY_ROOT, InitializeCanvasBoundsAction, SetModelAction, UpdateModelAction } from '@eclipse-glsp/sprotty';
21
- import { DefaultModelInitializationConstraint, ModelInitializationConstraint } from './model-initialization-constraint';
22
- const sandbox = sinon.createSandbox();
23
- const container = new Container();
24
- let constraint: ModelInitializationConstraint;
25
-
26
- const listener = sandbox.spy((): void => {});
27
-
28
- describe('DefaultModelInitializationConstraint', () => {
29
- beforeEach(() => {
30
- constraint = container.resolve(DefaultModelInitializationConstraint);
31
- sandbox.reset();
32
- });
33
- it('should complete after dispatching non empty SetModelAction and `InitializeCanvasBoundsAction`', () => {
34
- expect(constraint.isCompleted).to.be.false;
35
- constraint.notifyDispatched(SetModelAction.create({ id: 'model', type: 'graph' }));
36
- expect(constraint.isCompleted).to.be.false;
37
- constraint.notifyDispatched({ kind: InitializeCanvasBoundsAction.KIND });
38
- expect(constraint.isCompleted).to.be.true;
39
- });
40
- it('should complete after dispatching non empty UpdateModelAction and `InitializeCanvasBoundsAction`', () => {
41
- expect(constraint.isCompleted).to.be.false;
42
- constraint.notifyDispatched(UpdateModelAction.create({ id: 'model', type: 'graph' }));
43
- expect(constraint.isCompleted).to.be.false;
44
- constraint.notifyDispatched({ kind: InitializeCanvasBoundsAction.KIND });
45
- expect(constraint.isCompleted).to.be.true;
46
- });
47
- it('should note complete after dispatching empty SetModelAction and `InitializeCanvasBoundsAction` ', () => {
48
- expect(constraint.isCompleted).to.be.false;
49
- constraint.notifyDispatched(SetModelAction.create(EMPTY_ROOT));
50
- expect(constraint.isCompleted).to.be.false;
51
- constraint.notifyDispatched({ kind: InitializeCanvasBoundsAction.KIND });
52
- expect(constraint.isCompleted).to.be.false;
53
- });
54
- it('should note complete after dispatching empty UpdateModelAction and `InitializeCanvasBoundsAction ', () => {
55
- expect(constraint.isCompleted).to.be.false;
56
- constraint.notifyDispatched(UpdateModelAction.create(EMPTY_ROOT));
57
- expect(constraint.isCompleted).to.be.false;
58
- constraint.notifyDispatched({ kind: InitializeCanvasBoundsAction.KIND });
59
- expect(constraint.isCompleted).to.be.false;
60
- });
61
- describe('onInitialized', () => {
62
- it('returned promise should resolve once the constraint is initialized', async () => {
63
- const initializeDeferred = new Deferred<void>();
64
- const initializePromise = constraint.onInitialized();
65
- initializePromise.then(() => initializeDeferred.resolve());
66
- expect(initializeDeferred.state).to.be.equal('unresolved');
67
- // Directly trigger the completion method simplify test logic
68
- constraint['setCompleted']();
69
- // Short delay of test execution to ensure that the deferred state is updated.
70
- await new Promise(resolve => setTimeout(resolve, 5));
71
- expect(initializeDeferred.state).to.be.equal('resolved');
72
- });
73
- it('registered listener should be invoked once the constraint is initialized', () => {
74
- constraint.onInitialized(listener);
75
- expect(listener.called).to.be.false;
76
- // Directly trigger the completion method simplify test logic
77
- constraint['setCompleted']();
78
- expect(listener.called).to.be.true;
79
- });
80
- it('registered listener should be invoked directly on registration if the constraint is already initialized', () => {
81
- // Directly trigger the completion method simplify test logic
82
- constraint['setCompleted']();
83
- constraint.onInitialized(listener);
84
- expect(listener.called).to.be.true;
85
- });
86
- it('Disposed listener should not be invoked once the constraint is initialized', () => {
87
- const toDispose = constraint.onInitialized(listener);
88
- expect(listener.called).to.be.false;
89
- toDispose.dispose();
90
- // Directly trigger the completion method simplify test logic
91
- constraint['setCompleted']();
92
- expect(listener.called).to.be.false;
93
- });
94
- });
95
- });
@@ -1,318 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2020-2026 EclipseSource 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { Action, Command, CommandExecutionContext, Disposable, GModelRoot, GNode, TYPES, initializeContainer } from '@eclipse-glsp/sprotty';
17
- import { AssertionError, expect } from 'chai';
18
- import { Container, injectable } from 'inversify';
19
- import * as sinon from 'sinon';
20
- import { defaultModule } from './default.module';
21
- import { IFeedbackActionDispatcher, IFeedbackEmitter } from './feedback/feedback-action-dispatcher';
22
- import { FeedbackEmitter } from './feedback/feedback-emitter';
23
- import { ISelectionListener, SelectFeedbackAction, SelectionService } from './selection-service';
24
-
25
- @injectable()
26
- class MockFeedbackActionDispatcher implements IFeedbackActionDispatcher {
27
- protected feedbackEmitters: Map<IFeedbackEmitter, Action[]> = new Map();
28
-
29
- registerFeedback(feedbackEmitter: IFeedbackEmitter, actions: Action[]): Disposable {
30
- this.feedbackEmitters.set(feedbackEmitter, actions);
31
- return Disposable.create(() => this.deregisterFeedback(feedbackEmitter));
32
- }
33
-
34
- deregisterFeedback(feedbackEmitter: IFeedbackEmitter, _actions?: Action[]): void {
35
- this.feedbackEmitters.delete(feedbackEmitter);
36
- }
37
-
38
- getRegisteredFeedback(): Action[] {
39
- const result: Action[] = [];
40
- this.feedbackEmitters.forEach((value, key) => result.push(...value));
41
- return result;
42
- }
43
-
44
- getSingleFeedbackAction(): SelectFeedbackAction | undefined {
45
- const actions = this.getRegisteredFeedback();
46
- return actions.length === 1 ? (actions[0] as SelectFeedbackAction) : undefined;
47
- }
48
-
49
- getFeedbackCommands(): Command[] {
50
- return [];
51
- }
52
-
53
- createEmitter(): FeedbackEmitter {
54
- return new FeedbackEmitter(this);
55
- }
56
-
57
- async applyFeedbackCommands(context: CommandExecutionContext): Promise<void> {}
58
- }
59
-
60
- class MockSelectionListener implements ISelectionListener {
61
- selectionChanged(root: Readonly<GModelRoot>, selectedElements: string[], deselectedElements: string[] | undefined): void {
62
- // no.op
63
- }
64
- }
65
-
66
- function createContainer(): Container {
67
- const container = initializeContainer(new Container(), defaultModule);
68
-
69
- container.rebind(TYPES.IFeedbackActionDispatcher).to(MockFeedbackActionDispatcher).inSingletonScope();
70
- return container;
71
- }
72
-
73
- describe('SelectionService', () => {
74
- let root: GModelRoot;
75
- let selectionService: SelectionService;
76
- let feedbackDispatcher: MockFeedbackActionDispatcher;
77
-
78
- beforeEach(() => {
79
- const container = createContainer();
80
-
81
- root = createRoot('node1', 'node2', 'node3', 'node4', 'node5');
82
- selectionService = container.get<SelectionService>(SelectionService);
83
- feedbackDispatcher = container.get<MockFeedbackActionDispatcher>(TYPES.IFeedbackActionDispatcher);
84
- });
85
-
86
- describe('Initial State', () => {
87
- it('On creation nothing should be selected and no feedback should be dispatched.', () => {
88
- assertSelectionAndFeedback([], []);
89
- });
90
- });
91
- describe('Single Selection', () => {
92
- it('Selecting a single element should be tracked correctly and trigger feedback.', () => {
93
- assertSelectionAndFeedback([], []);
94
- selectionService.updateSelection(root, ['node1'], []);
95
- assertSelectionAndFeedback(['node1'], []);
96
- });
97
- it('Selecting the same element twice in one operation should not make a difference.', () => {
98
- assertSelectionAndFeedback([], []);
99
- selectionService.updateSelection(root, ['node1', 'node1'], []);
100
- assertSelectionAndFeedback(['node1'], []);
101
- });
102
- it('Selecting and then deselecting the same element should result in an empty selection.', () => {
103
- assertSelectionAndFeedback([], []);
104
- selectionService.updateSelection(root, ['node1'], []);
105
- selectionService.updateSelection(root, [], ['node1']);
106
- assertSelectionAndFeedback([], ['node1']);
107
- });
108
- it('Selecting and deselecting the same element in the same operation should have no effect.', () => {
109
- assertSelectionAndFeedback([], []);
110
- selectionService.updateSelection(root, ['node1'], ['node1']);
111
- assertSelectionAndFeedback([], []);
112
- });
113
- it('Selecting and deselecting not-existing nodes should have no effect.', () => {
114
- assertSelectionAndFeedback([], []);
115
- selectionService.updateSelection(root, ['not-existing'], []);
116
- assertSelectionAndFeedback([], []);
117
- selectionService.updateSelection(root, [], ['not-existing']);
118
- assertSelectionAndFeedback([], []);
119
- });
120
- });
121
- describe('Multi Selection', () => {
122
- it('Selecting multiple elements should be tracked correctly and trigger feedback.', () => {
123
- assertSelectionAndFeedback([], []);
124
- selectionService.updateSelection(root, ['node1', 'node2'], []);
125
- assertSelectionAndFeedback(['node1', 'node2'], []);
126
- });
127
- it('Selecting multiple elements should have the selection order in the dispatched feedback.', () => {
128
- assertSelectionAndFeedback([], []);
129
- selectionService.updateSelection(root, ['node2', 'node1'], []);
130
- expect(() => assertSelectionAndFeedback(['node1', 'node2'], [])).to.throw(AssertionError, 'ordered members');
131
- });
132
- it('Selecting the same elements twice in one operation should not make a difference.', () => {
133
- assertSelectionAndFeedback([], []);
134
- selectionService.updateSelection(root, ['node1', 'node1', 'node2', 'node2'], []);
135
- assertSelectionAndFeedback(['node1', 'node2'], []);
136
- });
137
- it('Selecting and then deselecting the same elements should result in an empty selection.', () => {
138
- assertSelectionAndFeedback([], []);
139
- selectionService.updateSelection(root, ['node1', 'node2'], []);
140
- selectionService.updateSelection(root, [], ['node1', 'node2']);
141
- assertSelectionAndFeedback([], ['node1', 'node2']);
142
- });
143
- it('Selecting and deselecting the same elements in one operation should have no effect.', () => {
144
- assertSelectionAndFeedback([], []);
145
- selectionService.updateSelection(root, ['node1', 'node2'], ['node1', 'node2']);
146
- assertSelectionAndFeedback([], []);
147
- selectionService.updateSelection(root, ['node1', 'node2', 'node3'], ['node1', 'node2']);
148
- assertSelectionAndFeedback(['node3'], []);
149
- });
150
- it('Selecting three elements and deselecting one should result in two selected and one deselected element.', () => {
151
- assertSelectionAndFeedback([], []);
152
- selectionService.updateSelection(root, ['node1', 'node2', 'node3'], []);
153
- assertSelectionAndFeedback(['node1', 'node2', 'node3'], []);
154
- selectionService.updateSelection(root, [], ['node2']);
155
- assertSelectionAndFeedback(['node1', 'node3'], ['node2']);
156
- });
157
- it('A series of selection and deselection operations should be tracked correctly.', () => {
158
- assertSelectionAndFeedback([], []);
159
- selectionService.updateSelection(root, ['node1', 'node2', 'node3'], []);
160
- assertSelectionAndFeedback(['node1', 'node2', 'node3'], []);
161
- selectionService.updateSelection(root, ['node4'], ['node2']);
162
- assertSelectionAndFeedback(['node1', 'node3', 'node4'], ['node2']);
163
- selectionService.updateSelection(root, ['node3', 'node1'], ['node2', 'node4']);
164
- assertSelectionAndFeedback(['node1', 'node3'], ['node4']);
165
- selectionService.updateSelection(root, ['node3'], ['node3']);
166
- assertSelectionAndFeedback(['node1', 'node3'], ['node4']);
167
- });
168
- });
169
- describe('Changing Root', () => {
170
- it('Changing root deselects all selected elements if there are no matching elements.', () => {
171
- assertSelectionAndFeedback([], []);
172
- selectionService.updateSelection(root, ['node1'], []);
173
- assertSelectionAndFeedback(['node1'], []);
174
-
175
- const newRoot = createRoot('newNode1', 'newNode2', 'newNode3');
176
- selectionService.modelRootChanged(newRoot);
177
- assertSelectionAndFeedback([], ['node1']);
178
- });
179
- it('Changing root keeps selected elements if there are matching elements.', () => {
180
- assertSelectionAndFeedback([], []);
181
- selectionService.updateSelection(root, ['node1', 'node2'], []);
182
- assertSelectionAndFeedback(['node1', 'node2'], []);
183
-
184
- const newRoot = createRoot('node1', 'newNode2', 'newNode3');
185
- selectionService.modelRootChanged(newRoot);
186
- assertSelectionAndFeedback(['node1'], ['node2']);
187
- });
188
- it('Changing root with new selection correctly selects matching elements and deselects not matching elements.', () => {
189
- assertSelectionAndFeedback([], []);
190
- selectionService.updateSelection(root, ['node1', 'node2'], []);
191
- assertSelectionAndFeedback(['node1', 'node2'], []);
192
-
193
- const newRoot = createRoot('newNode1', 'newNode2', 'newNode3');
194
- selectionService.updateSelection(newRoot, ['newNode1'], []);
195
- assertSelectionAndFeedback(['newNode1'], ['node1', 'node2']);
196
- });
197
- });
198
- describe('Listeners', () => {
199
- const sandbox = sinon.createSandbox();
200
- const listener = sandbox.createStubInstance(MockSelectionListener);
201
-
202
- beforeEach(() => {
203
- selectionService.onSelectionChanged(change =>
204
- listener.selectionChanged(change.root, change.selectedElements, change.deselectedElements)
205
- );
206
- });
207
-
208
- afterEach(() => {
209
- selectionService.dispose();
210
- sandbox.reset();
211
- });
212
- it('A registered listener should be notified of a single selection change.', () => {
213
- selectionService.updateSelection(root, ['node1', 'node1'], []);
214
- assertListener(listener, root, ['node1'], [], 1);
215
- });
216
- it('A registered listener should be notified of a multi-selection change.', () => {
217
- selectionService.updateSelection(root, ['node1', 'node2', 'node3'], []);
218
- assertListener(listener, root, ['node1', 'node2', 'node3'], [], 1);
219
- });
220
- it('A registered listener should be notified of series of selection changes.', () => {
221
- selectionService.updateSelection(root, ['node1'], []);
222
- assertListener(listener, root, ['node1'], [], 1);
223
- selectionService.updateSelection(root, ['node2'], ['node1']);
224
- assertListener(listener, root, ['node2'], ['node1'], 2);
225
- selectionService.updateSelection(root, ['node3', 'node4'], []);
226
- assertListener(listener, root, ['node2', 'node3', 'node4'], [], 3);
227
- selectionService.updateSelection(root, [], ['node4']);
228
- assertListener(listener, root, ['node2', 'node3'], ['node4'], 4);
229
- });
230
- it('A registered listener should NOT be notified of root changes.', () => {
231
- selectionService.updateSelection(root, [], []);
232
- assertListener(listener, root, [], [], 0);
233
-
234
- const newRoot = createRoot('node1', 'newNode2', 'newNode3');
235
- selectionService.updateSelection(newRoot, [], []);
236
- assertListener(listener, newRoot, [], [], 0);
237
- });
238
- it('Selecting the same elements consecutively should not trigger a listener update.', () => {
239
- selectionService.updateSelection(root, ['node1'], []);
240
- assertListener(listener, root, ['node1'], [], 1);
241
- selectionService.updateSelection(root, ['node1'], []);
242
- assertListener(listener, root, ['node1'], [], 1);
243
- });
244
- it('Selecting a not-existing elements should not trigger a listener update.', () => {
245
- selectionService.updateSelection(root, ['node1'], []);
246
- assertListener(listener, root, ['node1'], [], 1);
247
- selectionService.updateSelection(root, ['not-existing'], []);
248
- assertListener(listener, root, ['node1'], [], 1);
249
- });
250
- it('Bindings of TYPES.ISelectionListener should be registered as listener in `preLoadDiagram`', () => {
251
- const container = createContainer();
252
- const selectionListener = sandbox.createStubInstance(MockSelectionListener);
253
- container.bind(TYPES.ISelectionListener).toConstantValue(selectionListener);
254
- const testSelectionService = container.get<SelectionService>(SelectionService);
255
- testSelectionService.preLoadDiagram();
256
- testSelectionService.updateSelection(root, ['node1', 'node1'], []);
257
- assertListener(selectionListener, root, ['node1'], [], 1);
258
- });
259
- });
260
-
261
- function createRoot(...nodes: string[]): GModelRoot {
262
- const model = new GModelRoot();
263
- model.id = 'selection-service-spec';
264
- model.type = 'graph';
265
- nodes.forEach(id => {
266
- const node = new GNode();
267
- node.type = 'node:circle';
268
- node.id = id;
269
- model.add(node);
270
- });
271
- return model;
272
- }
273
-
274
- function assertSelectionAndFeedback(expectedSelection: string[], expectedDeselection: string[]): void {
275
- assertSelectionService(expectedSelection);
276
- assertDispatchedFeedback(expectedSelection, expectedDeselection);
277
- }
278
-
279
- function assertSelectionService(expectedSelection: string[]): void {
280
- expect(selectionService.isSingleSelection()).to.equal(expectedSelection.length === 1);
281
- expect(selectionService.isMultiSelection()).to.equal(expectedSelection.length > 1);
282
- expect(selectionService.hasSelectedElements()).to.equal(expectedSelection.length > 0);
283
- expect(selectionService.getSelectedElementIDs()).to.have.lengthOf(expectedSelection.length);
284
- if (expectedSelection.length > 0) {
285
- expect(selectionService.getSelectedElementIDs()).to.have.ordered.members(expectedSelection);
286
- }
287
- }
288
-
289
- function assertDispatchedFeedback(expectedSelection: string[], expectedDeselection: string[]): void {
290
- // a single feedback action reflects aggregated selection/deselection
291
- const hasFeedback = expectedSelection.length > 0 || expectedDeselection.length > 0;
292
- if (hasFeedback) {
293
- expect(feedbackDispatcher.getRegisteredFeedback()).to.have.lengthOf(1);
294
- expect(feedbackDispatcher.getSingleFeedbackAction()!.selectedElementsIDs).to.have.lengthOf(expectedSelection.length);
295
- expect(feedbackDispatcher.getSingleFeedbackAction()!.selectedElementsIDs).to.have.ordered.members(expectedSelection);
296
- expect(feedbackDispatcher.getSingleFeedbackAction()!.deselectedElementsIDs).to.have.lengthOf(expectedDeselection.length);
297
- expect(feedbackDispatcher.getSingleFeedbackAction()!.deselectedElementsIDs).to.have.ordered.members(expectedDeselection);
298
- } else {
299
- expect(feedbackDispatcher.getRegisteredFeedback()).to.have.lengthOf(0);
300
- expect(feedbackDispatcher.getSingleFeedbackAction()).to.be.undefined;
301
- }
302
- }
303
-
304
- function assertListener(
305
- listener: sinon.SinonStubbedInstance<MockSelectionListener>,
306
- expectedRoot: GModelRoot | undefined,
307
- expectedSelection: string[],
308
- expectedDeselection: string[],
309
- expectedCalled: number
310
- ): void {
311
- expect(listener.selectionChanged.callCount).to.be.equal(expectedCalled);
312
- if (expectedCalled > 0) {
313
- expect(listener.selectionChanged.lastCall.args[0]).to.be.deep.equals(expectedRoot);
314
- expect(listener.selectionChanged.lastCall.args[1]).to.be.deep.equals(expectedSelection);
315
- expect(listener.selectionChanged.lastCall.args[2]).to.be.deep.equals(expectedDeselection);
316
- }
317
- }
318
- });
@@ -1,56 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2024-2026 EclipseSource 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { FeatureModule } from '@eclipse-glsp/sprotty';
17
- import { expect } from 'chai';
18
- import { Container } from 'inversify';
19
- import * as sinon from 'sinon';
20
- import { defaultModule } from './base/default.module';
21
- import { DEFAULT_MODULES, initializeDiagramContainer } from './default-modules';
22
-
23
- describe('default-modules', () => {
24
- // InitializeDiagramContainer internally uses `resolveContainerConfiguration` so we only test functionality
25
- // that is not covered by the tests of `resolveContainerConfiguration`.
26
- describe('initializeDiagramContainer', () => {
27
- const sandbox = sinon.createSandbox();
28
- const container = new Container();
29
- const loadSpy = sandbox.spy(container, 'load');
30
- container.snapshot();
31
-
32
- beforeEach(() => {
33
- sandbox.reset();
34
- container.restore();
35
- container.snapshot();
36
- });
37
- it('should initialize the diagram container with the default modules in addition to the given config and load them first', () => {
38
- const extraModule = new FeatureModule(() => {});
39
- initializeDiagramContainer(container, { add: extraModule });
40
- expect(loadSpy.calledOnce).to.be.true;
41
- const callArgs = loadSpy.firstCall.args;
42
- const lastModule = callArgs.pop();
43
- expect(callArgs).to.be.deep.equal(DEFAULT_MODULES).ordered;
44
- expect(lastModule).to.be.equal(extraModule);
45
- });
46
- it('should throw an error if the base (default) module is removed via configuration', () => {
47
- expect(() => initializeDiagramContainer(container, { remove: defaultModule })).to.throw(/Invalid module configuration/);
48
- });
49
-
50
- it('should throw an error if the base (default) module is not the first module of the resolved configured (removed and added again)', () => {
51
- expect(() => initializeDiagramContainer(container, { remove: defaultModule, add: defaultModule })).to.throw(
52
- /Invalid module configuration/
53
- );
54
- });
55
- });
56
- });