@eclipse-glsp/server 1.1.0-next.3d7585d.42 → 1.1.0-next.44aae0c.44
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/common/command/command-stack.d.ts +45 -14
- package/lib/common/command/command-stack.d.ts.map +1 -1
- package/lib/common/command/command-stack.js +78 -9
- package/lib/common/command/command-stack.js.map +1 -1
- package/lib/common/command/command-stack.spec.d.ts +2 -0
- package/lib/common/command/command-stack.spec.d.ts.map +1 -0
- package/lib/common/command/command-stack.spec.js +207 -0
- package/lib/common/command/command-stack.spec.js.map +1 -0
- package/lib/common/command/command.d.ts +34 -7
- package/lib/common/command/command.d.ts.map +1 -1
- package/lib/common/command/command.js +73 -0
- package/lib/common/command/command.js.map +1 -1
- package/lib/common/command/command.spec.d.ts +2 -0
- package/lib/common/command/command.spec.d.ts.map +1 -0
- package/lib/common/command/command.spec.js +86 -0
- package/lib/common/command/command.spec.js.map +1 -0
- package/lib/common/command/recording-command.d.ts +75 -0
- package/lib/common/command/recording-command.d.ts.map +1 -0
- package/lib/common/command/recording-command.js +99 -0
- package/lib/common/command/recording-command.js.map +1 -0
- package/lib/common/command/recording-command.spec.d.ts +17 -0
- package/lib/common/command/recording-command.spec.d.ts.map +1 -0
- package/lib/common/command/recording-command.spec.js +62 -0
- package/lib/common/command/recording-command.spec.js.map +1 -0
- package/lib/common/command/undo-redo-action-handler.d.ts +28 -0
- package/lib/common/command/undo-redo-action-handler.d.ts.map +1 -0
- package/lib/common/command/undo-redo-action-handler.js +72 -0
- package/lib/common/command/undo-redo-action-handler.js.map +1 -0
- package/lib/common/di/diagram-module.d.ts +3 -0
- package/lib/common/di/diagram-module.d.ts.map +1 -1
- package/lib/common/di/diagram-module.js +12 -0
- package/lib/common/di/diagram-module.js.map +1 -1
- package/lib/common/features/contextactions/tool-palette-item-provider.d.ts +1 -1
- package/lib/common/features/contextactions/tool-palette-item-provider.d.ts.map +1 -1
- package/lib/common/features/contextactions/tool-palette-item-provider.js +2 -4
- package/lib/common/features/contextactions/tool-palette-item-provider.js.map +1 -1
- package/lib/common/{gmodel → features/layout}/computed-bounds-action-handler.d.ts +8 -3
- package/lib/common/features/layout/computed-bounds-action-handler.d.ts.map +1 -0
- package/lib/common/{gmodel → features/layout}/computed-bounds-action-handler.js +8 -3
- package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -0
- package/lib/common/features/layout/layout-operation-handler.d.ts +12 -3
- package/lib/common/features/layout/layout-operation-handler.d.ts.map +1 -1
- package/lib/common/features/layout/layout-operation-handler.js +26 -10
- package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
- package/lib/common/features/model/model-state.d.ts +0 -2
- package/lib/common/features/model/model-state.d.ts.map +1 -1
- package/lib/common/features/model/model-state.js +0 -1
- package/lib/common/features/model/model-state.js.map +1 -1
- package/lib/common/features/model/model-submission-handler.d.ts +2 -0
- package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
- package/lib/common/features/model/model-submission-handler.js +7 -2
- package/lib/common/features/model/model-submission-handler.js.map +1 -1
- package/lib/common/features/model/save-model-action-handler.d.ts +2 -2
- package/lib/common/features/model/save-model-action-handler.d.ts.map +1 -1
- package/lib/common/features/model/save-model-action-handler.js +5 -5
- package/lib/common/features/model/save-model-action-handler.js.map +1 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.d.ts +4 -5
- package/lib/common/gmodel/apply-label-edit-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.js +12 -21
- package/lib/common/gmodel/apply-label-edit-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-bounds-operation-handler.d.ts +9 -6
- package/lib/common/gmodel/change-bounds-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/change-bounds-operation-handler.js +14 -14
- package/lib/common/gmodel/change-bounds-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.d.ts +5 -5
- package/lib/common/gmodel/change-routing-points-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js +11 -14
- package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
- package/lib/common/{operations → gmodel}/cut-operation-handler.d.ts +5 -4
- package/lib/common/gmodel/cut-operation-handler.d.ts.map +1 -0
- package/lib/common/{operations → gmodel}/cut-operation-handler.js +13 -11
- package/lib/common/gmodel/cut-operation-handler.js.map +1 -0
- package/lib/common/gmodel/delete-operation-handler.d.ts +6 -6
- package/lib/common/gmodel/delete-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/delete-operation-handler.js +13 -10
- package/lib/common/gmodel/delete-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts +11 -7
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js +12 -13
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts +32 -5
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js +45 -3
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-diagram-module.d.ts +8 -8
- package/lib/common/gmodel/gmodel-diagram-module.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-diagram-module.js +15 -21
- package/lib/common/gmodel/gmodel-diagram-module.js.map +1 -1
- package/lib/common/gmodel/gmodel-operation-handler.d.ts +23 -0
- package/lib/common/gmodel/gmodel-operation-handler.d.ts.map +1 -0
- package/lib/common/gmodel/gmodel-operation-handler.js +43 -0
- package/lib/common/gmodel/gmodel-operation-handler.js.map +1 -0
- package/lib/common/gmodel/index.d.ts +2 -1
- package/lib/common/gmodel/index.d.ts.map +1 -1
- package/lib/common/gmodel/index.js +2 -1
- package/lib/common/gmodel/index.js.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.d.ts +7 -6
- package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.js +20 -15
- package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.d.ts +5 -5
- package/lib/common/gmodel/reconnect-edge-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.js +11 -14
- package/lib/common/gmodel/reconnect-edge-operation-handler.js.map +1 -1
- package/lib/common/index.d.ts +2 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/operations/compound-operation-handler.d.ts +5 -5
- package/lib/common/operations/compound-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/compound-operation-handler.js +37 -9
- package/lib/common/operations/compound-operation-handler.js.map +1 -1
- package/lib/common/operations/create-operation-handler.d.ts +8 -40
- package/lib/common/operations/create-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/create-operation-handler.js +26 -85
- package/lib/common/operations/create-operation-handler.js.map +1 -1
- package/lib/common/operations/operation-action-handler.d.ts +10 -1
- package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-action-handler.js +37 -22
- package/lib/common/operations/operation-action-handler.js.map +1 -1
- package/lib/common/operations/operation-handler-registry.d.ts +11 -2
- package/lib/common/operations/operation-handler-registry.d.ts.map +1 -1
- package/lib/common/operations/operation-handler-registry.js +31 -2
- package/lib/common/operations/operation-handler-registry.js.map +1 -1
- package/lib/common/operations/operation-handler.d.ts +28 -11
- package/lib/common/operations/operation-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-handler.js +50 -1
- package/lib/common/operations/operation-handler.js.map +1 -1
- package/lib/common/test/mock-util.d.ts +14 -1
- package/lib/common/test/mock-util.d.ts.map +1 -1
- package/lib/common/test/mock-util.js +42 -37
- package/lib/common/test/mock-util.js.map +1 -1
- package/package.json +4 -3
- package/src/common/command/command-stack.spec.ts +239 -0
- package/src/common/command/command-stack.ts +106 -20
- package/src/common/command/command.spec.ts +92 -0
- package/src/common/command/command.ts +96 -7
- package/src/common/command/recording-command.spec.ts +74 -0
- package/src/common/command/recording-command.ts +119 -0
- package/src/common/command/undo-redo-action-handler.ts +57 -0
- package/src/common/di/diagram-module.ts +13 -0
- package/src/common/features/contextactions/tool-palette-item-provider.ts +2 -4
- package/src/common/{gmodel → features/layout}/computed-bounds-action-handler.ts +9 -4
- package/src/common/features/layout/layout-operation-handler.ts +26 -11
- package/src/common/features/model/model-state.ts +0 -3
- package/src/common/features/model/model-submission-handler.ts +6 -2
- package/src/common/features/model/save-model-action-handler.ts +5 -6
- package/src/common/gmodel/apply-label-edit-operation-handler.ts +13 -15
- package/src/common/gmodel/change-bounds-operation-handler.ts +12 -8
- package/src/common/gmodel/change-routing-points-operation-handler.ts +8 -7
- package/src/common/{operations → gmodel}/cut-operation-handler.ts +9 -8
- package/src/common/gmodel/delete-operation-handler.ts +16 -10
- package/src/common/gmodel/gmodel-create-edge-operation-handler.ts +16 -10
- package/src/common/gmodel/gmodel-create-node-operation-handler.ts +54 -6
- package/src/common/gmodel/gmodel-diagram-module.ts +22 -27
- package/src/common/gmodel/gmodel-operation-handler.ts +31 -0
- package/src/common/gmodel/index.ts +2 -1
- package/src/common/gmodel/paste-operation-handler.ts +19 -11
- package/src/common/gmodel/reconnect-edge-operation-handler.ts +8 -7
- package/src/common/index.ts +2 -1
- package/src/common/operations/compound-operation-handler.ts +14 -12
- package/src/common/operations/create-operation-handler.ts +17 -74
- package/src/common/operations/operation-action-handler.ts +51 -27
- package/src/common/operations/operation-handler-registry.ts +18 -3
- package/src/common/operations/operation-handler.ts +38 -13
- package/src/common/test/mock-util.ts +42 -36
- package/lib/common/gmodel/apply-label-edit-operation-handler.spec.d.ts +0 -2
- package/lib/common/gmodel/apply-label-edit-operation-handler.spec.d.ts.map +0 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.spec.js +0 -38
- package/lib/common/gmodel/apply-label-edit-operation-handler.spec.js.map +0 -1
- package/lib/common/gmodel/computed-bounds-action-handler.d.ts.map +0 -1
- package/lib/common/gmodel/computed-bounds-action-handler.js.map +0 -1
- package/lib/common/operations/cut-operation-handler.d.ts.map +0 -1
- package/lib/common/operations/cut-operation-handler.js.map +0 -1
- package/src/common/gmodel/apply-label-edit-operation-handler.spec.ts +0 -40
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
*
|
|
15
15
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
16
|
********************************************************************************/
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
17
18
|
// Stub-implementation classes used for unit testing
|
|
18
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.StubClientSessionInitializer = exports.stubActionHandlerFactory = exports.TestContextEditValidator = exports.TestLabelEditValidator = exports.StubDiagramConfiguration = exports.StubGLSPServerListener = exports.StubGLSPClientProxy = exports.StubClientSessionListener = exports.StubLogger = exports.StubClientSessionManager = exports.StubClientSessionFactory = exports.StubActionDispatcher = exports.StubCreateEdgeOperationHandler = exports.StubCreateNodeOperationHandler = exports.StubActionHandler = exports.createClientSession = exports.delay = void 0;
|
|
20
|
+
exports.StubCommand = exports.StubClientSessionInitializer = exports.stubActionHandlerFactory = exports.TestContextEditValidator = exports.TestLabelEditValidator = exports.StubDiagramConfiguration = exports.StubGLSPServerListener = exports.StubGLSPClientProxy = exports.StubClientSessionListener = exports.StubLogger = exports.StubClientSessionManager = exports.StubClientSessionFactory = exports.StubActionDispatcher = exports.StubCreateEdgeOperationHandler = exports.StubCreateNodeOperationHandler = exports.StubActionHandler = exports.createClientSession = exports.expectToThrowAsync = exports.delay = void 0;
|
|
20
21
|
const graph_1 = require("@eclipse-glsp/graph");
|
|
21
22
|
const protocol_1 = require("@eclipse-glsp/protocol");
|
|
23
|
+
const chai_1 = require("chai");
|
|
22
24
|
const inversify_1 = require("inversify");
|
|
23
25
|
const diagram_configuration_1 = require("../diagram/diagram-configuration");
|
|
24
26
|
const label_edit_validator_1 = require("../features/directediting/label-edit-validator");
|
|
@@ -28,6 +30,27 @@ async function delay(ms) {
|
|
|
28
30
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
29
31
|
}
|
|
30
32
|
exports.delay = delay;
|
|
33
|
+
/**
|
|
34
|
+
* Consumes a maybe async function and checks for error
|
|
35
|
+
* @param method - The function to check
|
|
36
|
+
* @param message - Optional message to match with error message
|
|
37
|
+
*/
|
|
38
|
+
async function expectToThrowAsync(toEvaluate, message) {
|
|
39
|
+
let err = undefined;
|
|
40
|
+
try {
|
|
41
|
+
await toEvaluate();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
err = error;
|
|
45
|
+
}
|
|
46
|
+
if (message) {
|
|
47
|
+
(0, chai_1.expect)(err === null || err === void 0 ? void 0 : err.message).to.be.equal(message);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
(0, chai_1.expect)(err).to.be.an('Error');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.expectToThrowAsync = expectToThrowAsync;
|
|
31
54
|
function createClientSession(id, diagramType, container = new inversify_1.Container(), actionDispatcher = new StubActionDispatcher()) {
|
|
32
55
|
return {
|
|
33
56
|
id,
|
|
@@ -72,9 +95,7 @@ class StubCreateEdgeOperationHandler extends index_1.GModelCreateEdgeOperationHa
|
|
|
72
95
|
}
|
|
73
96
|
exports.StubCreateEdgeOperationHandler = StubCreateEdgeOperationHandler;
|
|
74
97
|
class StubActionDispatcher {
|
|
75
|
-
dispatchAfterNextUpdate(...actions) {
|
|
76
|
-
// NO-OP
|
|
77
|
-
}
|
|
98
|
+
dispatchAfterNextUpdate(...actions) { }
|
|
78
99
|
dispatch(action) {
|
|
79
100
|
return Promise.resolve();
|
|
80
101
|
}
|
|
@@ -121,45 +142,25 @@ class StubLogger extends logger_1.Logger {
|
|
|
121
142
|
this.logLevel = logger_1.LogLevel.none;
|
|
122
143
|
this.caller = undefined;
|
|
123
144
|
}
|
|
124
|
-
info(message, ...params) {
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// no-op
|
|
129
|
-
}
|
|
130
|
-
error(message, ...params) {
|
|
131
|
-
// no-op
|
|
132
|
-
}
|
|
133
|
-
debug(message, ...params) {
|
|
134
|
-
// no-op
|
|
135
|
-
}
|
|
145
|
+
info(message, ...params) { }
|
|
146
|
+
warn(message, ...params) { }
|
|
147
|
+
error(message, ...params) { }
|
|
148
|
+
debug(message, ...params) { }
|
|
136
149
|
}
|
|
137
150
|
exports.StubLogger = StubLogger;
|
|
138
151
|
class StubClientSessionListener {
|
|
139
|
-
sessionCreated(clientSession) {
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
sessionDisposed(clientSession) {
|
|
143
|
-
// no-op
|
|
144
|
-
}
|
|
152
|
+
sessionCreated(clientSession) { }
|
|
153
|
+
sessionDisposed(clientSession) { }
|
|
145
154
|
}
|
|
146
155
|
exports.StubClientSessionListener = StubClientSessionListener;
|
|
147
156
|
class StubGLSPClientProxy {
|
|
148
|
-
connect(connection) {
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
process(message) {
|
|
152
|
-
// no-op
|
|
153
|
-
}
|
|
157
|
+
connect(connection) { }
|
|
158
|
+
process(message) { }
|
|
154
159
|
}
|
|
155
160
|
exports.StubGLSPClientProxy = StubGLSPClientProxy;
|
|
156
161
|
class StubGLSPServerListener {
|
|
157
|
-
serverInitialized(server) {
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
serverShutDown(server) {
|
|
161
|
-
// no-op
|
|
162
|
-
}
|
|
162
|
+
serverInitialized(server) { }
|
|
163
|
+
serverShutDown(server) { }
|
|
163
164
|
}
|
|
164
165
|
exports.StubGLSPServerListener = StubGLSPServerListener;
|
|
165
166
|
class StubDiagramConfiguration {
|
|
@@ -203,9 +204,13 @@ exports.TestContextEditValidator = TestContextEditValidator;
|
|
|
203
204
|
const stubActionHandlerFactory = constructor => new constructor();
|
|
204
205
|
exports.stubActionHandlerFactory = stubActionHandlerFactory;
|
|
205
206
|
class StubClientSessionInitializer {
|
|
206
|
-
initialize(args) {
|
|
207
|
-
// no-op
|
|
208
|
-
}
|
|
207
|
+
initialize(args) { }
|
|
209
208
|
}
|
|
210
209
|
exports.StubClientSessionInitializer = StubClientSessionInitializer;
|
|
210
|
+
class StubCommand {
|
|
211
|
+
execute() { }
|
|
212
|
+
undo() { }
|
|
213
|
+
redo() { }
|
|
214
|
+
}
|
|
215
|
+
exports.StubCommand = StubCommand;
|
|
211
216
|
//# sourceMappingURL=mock-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-util.js","sourceRoot":"","sources":["../../../src/common/test/mock-util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;AAClF,oDAAoD;;;AAEpD,+CAA4F;AAC5F,
|
|
1
|
+
{"version":3,"file":"mock-util.js","sourceRoot":"","sources":["../../../src/common/test/mock-util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;AAClF,yDAAyD;AACzD,oDAAoD;;;AAEpD,+CAA4F;AAC5F,qDAagC;AAChC,+BAA8B;AAC9B,yCAAsC;AAKtC,4EAA0F;AAE1F,yFAAoF;AACpF,2CAAqG;AASrG,4CAAmD;AAE5C,KAAK,UAAU,KAAK,CAAC,EAAU;IAClC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAFD,sBAEC;AAED;;;;GAIG;AACI,KAAK,UAAU,kBAAkB,CAAC,UAAoC,EAAE,OAAgB;IAC3F,IAAI,GAAG,GAAsB,SAAS,CAAC;IACvC,IAAI;QACA,MAAM,UAAU,EAAE,CAAC;KACtB;IAAC,OAAO,KAAU,EAAE;QACjB,GAAG,GAAG,KAAK,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AO,EAAE,QAAQ,EAAE,2BAAgB,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrE,CAAC;CACJ;AAVD,wDAUC;AAED,MAAa,wBAAwB;IACjC,IAAI,SAAS;QACT,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,MAAmC;QACxC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE;YACzB,OAAO,EAAE,QAAQ,EAAE,2BAAgB,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;SAC1E;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;YAC3B,OAAO,EAAE,QAAQ,EAAE,2BAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;SAC9E;QACD,OAAO,EAAE,QAAQ,EAAE,2BAAgB,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrE,CAAC;CACJ;AAdD,4DAcC;AAEM,MAAM,wBAAwB,GAAyB,WAAW,CAAC,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC;AAAlF,QAAA,wBAAwB,4BAA0D;AAE/F,MAAa,4BAA4B;IACrC,UAAU,CAAC,IAAW,IAAS,CAAC;CACnC;AAFD,oEAEC;AAED,MAAa,WAAW;IACpB,OAAO,KAAU,CAAC;IAClB,IAAI,KAAU,CAAC;IACf,IAAI,KAAU,CAAC;CAElB;AALD,kCAKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eclipse-glsp/server",
|
|
3
|
-
"version": "1.1.0-next.
|
|
3
|
+
"version": "1.1.0-next.44aae0c.44+44aae0c",
|
|
4
4
|
"description": "A js server framework for Eclipse GLSP",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eclipse",
|
|
@@ -59,10 +59,11 @@
|
|
|
59
59
|
"watch": "tsc -w"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@eclipse-glsp/graph": "1.1.0-next.
|
|
62
|
+
"@eclipse-glsp/graph": "1.1.0-next.44aae0c.44+44aae0c",
|
|
63
63
|
"@eclipse-glsp/protocol": "next",
|
|
64
64
|
"@types/uuid": "8.3.1",
|
|
65
65
|
"commander": "^8.3.0",
|
|
66
|
+
"fast-json-patch": "^3.1.0",
|
|
66
67
|
"inversify": "^5.1.1",
|
|
67
68
|
"winston": "^3.3.3"
|
|
68
69
|
},
|
|
@@ -72,5 +73,5 @@
|
|
|
72
73
|
"publishConfig": {
|
|
73
74
|
"access": "public"
|
|
74
75
|
},
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "44aae0ca2380fe42eb95aac54d2d4e45e187d14f"
|
|
76
77
|
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2023 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, ContainerModule } from 'inversify';
|
|
18
|
+
import * as sinon from 'sinon';
|
|
19
|
+
import { expectToThrowAsync, StubCommand, StubLogger } from '../test/mock-util';
|
|
20
|
+
import { Logger } from '../utils/logger';
|
|
21
|
+
import { DefaultCommandStack } from './command-stack';
|
|
22
|
+
|
|
23
|
+
describe('test DefaultCommandStack', () => {
|
|
24
|
+
const sandbox = sinon.createSandbox();
|
|
25
|
+
const container = new Container();
|
|
26
|
+
|
|
27
|
+
const command1 = sandbox.stub(new StubCommand());
|
|
28
|
+
const command2 = sandbox.stub(new StubCommand());
|
|
29
|
+
let commandStack: DefaultCommandStack;
|
|
30
|
+
|
|
31
|
+
container.load(
|
|
32
|
+
new ContainerModule(bind => {
|
|
33
|
+
bind(Logger).toConstantValue(new StubLogger());
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
commandStack = container.resolve(DefaultCommandStack);
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
sandbox.reset();
|
|
40
|
+
commandStack = container.resolve(DefaultCommandStack);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('execute', () => {
|
|
44
|
+
it('should execute the given command and become dirty', async () => {
|
|
45
|
+
expect(commandStack.isDirty).to.be.false;
|
|
46
|
+
await commandStack.execute(command1);
|
|
47
|
+
expect(command1.execute.calledOnce).to.be.true;
|
|
48
|
+
expect(commandStack.isDirty).to.be.true;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should execute the given commands in order and become dirty', async () => {
|
|
52
|
+
expect(commandStack.isDirty).to.be.false;
|
|
53
|
+
await commandStack.execute(command1);
|
|
54
|
+
await commandStack.execute(command2);
|
|
55
|
+
|
|
56
|
+
expect(command1.execute.calledOnce).to.be.true;
|
|
57
|
+
expect(command2.execute.calledOnce).to.be.true;
|
|
58
|
+
expect(command2.execute.calledAfter(command1.execute)).to.be.true;
|
|
59
|
+
expect(commandStack.isDirty).to.be.true;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should be able to undo after execute', async () => {
|
|
63
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
64
|
+
await commandStack.execute(command1);
|
|
65
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should clear the redo stack after execution', async () => {
|
|
69
|
+
commandStack['commands'].push(command2);
|
|
70
|
+
commandStack['top'] = -1;
|
|
71
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
72
|
+
|
|
73
|
+
await commandStack.execute(command1);
|
|
74
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should flush the stack in case of an execution error', async () => {
|
|
78
|
+
command2.execute.throwsException();
|
|
79
|
+
const flushSpy = sandbox.spy(commandStack, 'flush');
|
|
80
|
+
|
|
81
|
+
await expectToThrowAsync(() => commandStack.execute(command2));
|
|
82
|
+
expect(command2.execute.calledOnce).to.be.true;
|
|
83
|
+
expect(flushSpy.calledOnce).to.be.true;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('undo', () => {
|
|
88
|
+
it('should do nothing if the command stack is empty', async () => {
|
|
89
|
+
expect(commandStack.isDirty).to.be.false;
|
|
90
|
+
|
|
91
|
+
await commandStack.undo();
|
|
92
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
93
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
94
|
+
expect(commandStack.isDirty).to.be.false;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should undo the command and become non-dirty again', async () => {
|
|
98
|
+
commandStack['commands'].push(command1);
|
|
99
|
+
commandStack['top'] = 0;
|
|
100
|
+
expect(commandStack.isDirty).to.be.true;
|
|
101
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
102
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
103
|
+
|
|
104
|
+
await commandStack.undo();
|
|
105
|
+
expect(command1.undo.calledOnce).to.be.true;
|
|
106
|
+
expect(commandStack.isDirty).to.be.false;
|
|
107
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
108
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should undo multiple command and become non-dirty again', async () => {
|
|
112
|
+
commandStack['commands'].push(command1, command2);
|
|
113
|
+
commandStack['top'] = 1;
|
|
114
|
+
expect(commandStack.isDirty).to.be.true;
|
|
115
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
116
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
117
|
+
|
|
118
|
+
await commandStack.undo();
|
|
119
|
+
expect(command2.undo.calledOnce).to.be.true;
|
|
120
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
121
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
122
|
+
expect(commandStack.isDirty).to.be.true;
|
|
123
|
+
|
|
124
|
+
await commandStack.undo();
|
|
125
|
+
expect(command1.undo.calledOnce).to.be.true;
|
|
126
|
+
expect(command1.undo.calledAfter(command2.undo)).to.be.true;
|
|
127
|
+
expect(commandStack.isDirty).to.be.false;
|
|
128
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
129
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
130
|
+
});
|
|
131
|
+
it('should flush the stack in case of an execution error', async () => {
|
|
132
|
+
command2.undo.throwsException();
|
|
133
|
+
const flushSpy = sandbox.spy(commandStack, 'flush');
|
|
134
|
+
commandStack['commands'].push(command2);
|
|
135
|
+
commandStack['top'] = 0;
|
|
136
|
+
|
|
137
|
+
await expectToThrowAsync(() => commandStack.undo());
|
|
138
|
+
expect(command2.undo.calledOnce).to.be.true;
|
|
139
|
+
expect(flushSpy.calledOnce).to.be.true;
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('redo', () => {
|
|
144
|
+
it('should do nothing if the command stack is empty', async () => {
|
|
145
|
+
expect(commandStack.isDirty).to.be.false;
|
|
146
|
+
|
|
147
|
+
await commandStack.redo();
|
|
148
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
149
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
150
|
+
expect(commandStack.isDirty).to.be.false;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('should redo the command and become dirty again', async () => {
|
|
154
|
+
commandStack['commands'].push(command1);
|
|
155
|
+
commandStack['top'] = -1;
|
|
156
|
+
expect(commandStack.isDirty).to.be.false;
|
|
157
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
158
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
159
|
+
|
|
160
|
+
await commandStack.redo();
|
|
161
|
+
expect(command1.redo.calledOnce).to.be.true;
|
|
162
|
+
expect(commandStack.isDirty).to.be.true;
|
|
163
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
164
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should undo multiple command and become non-dirty again', async () => {
|
|
168
|
+
commandStack['commands'].push(command2, command1);
|
|
169
|
+
commandStack['top'] = -1;
|
|
170
|
+
commandStack['saveIndex'] = -1;
|
|
171
|
+
expect(commandStack.isDirty).to.be.false;
|
|
172
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
173
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
174
|
+
|
|
175
|
+
await commandStack.redo();
|
|
176
|
+
expect(command2.redo.calledOnce).to.be.true;
|
|
177
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
178
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
179
|
+
expect(commandStack.isDirty).to.be.true;
|
|
180
|
+
|
|
181
|
+
await commandStack.redo();
|
|
182
|
+
expect(command1.redo.calledOnce).to.be.true;
|
|
183
|
+
expect(command1.redo.calledAfter(command2.redo)).to.be.true;
|
|
184
|
+
expect(commandStack.isDirty).to.be.true;
|
|
185
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
186
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
187
|
+
});
|
|
188
|
+
it('should flush the stack in case of an execution error', async () => {
|
|
189
|
+
command2.redo.throwsException();
|
|
190
|
+
const flushSpy = sandbox.spy(commandStack, 'flush');
|
|
191
|
+
commandStack['commands'].push(command2);
|
|
192
|
+
commandStack['top'] = -1;
|
|
193
|
+
|
|
194
|
+
await expectToThrowAsync(() => commandStack.redo());
|
|
195
|
+
expect(command2.redo.calledOnce).to.be.true;
|
|
196
|
+
expect(flushSpy.calledOnce).to.be.true;
|
|
197
|
+
});
|
|
198
|
+
it('should be able to undo after redo', async () => {
|
|
199
|
+
commandStack['commands'].push(command1);
|
|
200
|
+
commandStack['top'] = -1;
|
|
201
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
202
|
+
await commandStack.redo();
|
|
203
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('flush', () => {
|
|
208
|
+
it('should reset the internal state of the command stack', () => {
|
|
209
|
+
commandStack['commands'].push(command1, command1);
|
|
210
|
+
commandStack['top'] = 0;
|
|
211
|
+
|
|
212
|
+
commandStack.flush();
|
|
213
|
+
expect(commandStack.isDirty).to.be.false;
|
|
214
|
+
expect(commandStack.canUndo()).to.be.false;
|
|
215
|
+
expect(commandStack.canRedo()).to.be.false;
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('isSaveDone', () => {
|
|
220
|
+
it('should become non-dirty after execution', () => {
|
|
221
|
+
commandStack['commands'].push(command1);
|
|
222
|
+
commandStack['top'] = 0;
|
|
223
|
+
expect(commandStack.isDirty).to.be.true;
|
|
224
|
+
|
|
225
|
+
commandStack.saveIsDone();
|
|
226
|
+
expect(commandStack.isDirty).to.be.false;
|
|
227
|
+
});
|
|
228
|
+
it('should maintain undo/redo history after execution', () => {
|
|
229
|
+
commandStack['commands'].push(command1, command2);
|
|
230
|
+
commandStack['top'] = 0;
|
|
231
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
232
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
233
|
+
|
|
234
|
+
commandStack.saveIsDone();
|
|
235
|
+
expect(commandStack.canUndo()).to.be.true;
|
|
236
|
+
expect(commandStack.canRedo()).to.be.true;
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -13,62 +13,148 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { injectable } from 'inversify';
|
|
16
|
+
import { inject, injectable } from 'inversify';
|
|
17
|
+
import { MaybePromise } from '..';
|
|
18
|
+
import { Logger } from '../utils/logger';
|
|
17
19
|
import { Command } from './command';
|
|
18
20
|
|
|
19
21
|
export const CommandStack = Symbol('CommandStack');
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
|
-
* A
|
|
23
|
-
*
|
|
24
|
+
* A command stack keeps track of {@link Command commands} that have been executed.
|
|
25
|
+
* Executed commands can be undone in the reverse order of their original execution.
|
|
26
|
+
* Unless a new command has been executed after an undo operation, commands can be
|
|
27
|
+
* redone in the original order of their execution.
|
|
28
|
+
*
|
|
24
29
|
*/
|
|
25
30
|
export interface CommandStack {
|
|
26
31
|
/**
|
|
27
|
-
* Clears any redoable commands not yet redone, adds the command
|
|
32
|
+
* Clears any redoable commands not yet redone, adds the command to the stack and then invokes {@link Command.execute}.
|
|
28
33
|
* @param command the command to execute.
|
|
29
34
|
*/
|
|
30
|
-
execute(command: Command): void
|
|
35
|
+
execute(command: Command): MaybePromise<void>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Removes the topmost (i.e. last executed) command from the stack and invokes {@link Command.undo}.
|
|
39
|
+
*/
|
|
40
|
+
undo(): MaybePromise<void>;
|
|
31
41
|
|
|
32
42
|
/**
|
|
33
|
-
*
|
|
43
|
+
* Returns `true` if the top command on the stack can be undone.
|
|
34
44
|
*/
|
|
35
|
-
|
|
45
|
+
canUndo(): boolean;
|
|
36
46
|
|
|
37
47
|
/**
|
|
38
|
-
*
|
|
48
|
+
* Re-adds the last undo command on top of the stack and invokes {@link Command.redo}
|
|
39
49
|
*/
|
|
40
|
-
redo(): void
|
|
50
|
+
redo(): MaybePromise<void>;
|
|
41
51
|
|
|
42
52
|
/**
|
|
43
|
-
*
|
|
53
|
+
* Returns `true` if there are redoable commands in the stack.
|
|
44
54
|
*/
|
|
45
|
-
|
|
55
|
+
canRedo(): boolean;
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
58
|
* Called after a save has been successfully performed.
|
|
49
59
|
*/
|
|
50
60
|
saveIsDone(): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Indicates wether the command stack has unsaved changes.
|
|
64
|
+
*/
|
|
65
|
+
readonly isDirty: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Disposes all the commands in the stack.
|
|
69
|
+
*/
|
|
70
|
+
flush(): void;
|
|
51
71
|
}
|
|
52
72
|
|
|
53
73
|
@injectable()
|
|
54
74
|
export class DefaultCommandStack implements CommandStack {
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
@inject(Logger)
|
|
76
|
+
protected logger: Logger;
|
|
77
|
+
|
|
78
|
+
protected commands: Command[] = [];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The current position within the command list from which the next execute, undo, or redo, will be performed.
|
|
82
|
+
*/
|
|
83
|
+
protected top = -1;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The current position within the command list when {@link DefaultCommandStack.saveIsDone} is called.
|
|
87
|
+
*/
|
|
88
|
+
protected saveIndex = -1;
|
|
89
|
+
|
|
90
|
+
async execute(command: Command): Promise<void> {
|
|
91
|
+
try {
|
|
92
|
+
await command.execute();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.handleError(error);
|
|
95
|
+
}
|
|
96
|
+
// Clear the command list past the top (i.e. the old redo list)
|
|
97
|
+
this.commands = this.commands.slice(0, this.top + 1);
|
|
98
|
+
this.commands.push(command);
|
|
99
|
+
++this.top;
|
|
100
|
+
|
|
101
|
+
// if the saveIndex points to the old redo list we can never reach a state again
|
|
102
|
+
// where save is not necessary. => ensure that `isDirty` always returns true
|
|
103
|
+
if (this.saveIndex >= this.top) {
|
|
104
|
+
this.saveIndex = -2;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async undo(): Promise<void> {
|
|
109
|
+
if (this.canUndo()) {
|
|
110
|
+
const command = this.commands[this.top--];
|
|
111
|
+
try {
|
|
112
|
+
await command.undo();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
this.handleError(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
57
117
|
}
|
|
58
118
|
|
|
59
|
-
|
|
60
|
-
|
|
119
|
+
canUndo(): boolean {
|
|
120
|
+
return this.top !== -1 //
|
|
121
|
+
? Command.canUndo(this.commands[this.top])
|
|
122
|
+
: false;
|
|
61
123
|
}
|
|
62
124
|
|
|
63
|
-
redo(): void {
|
|
64
|
-
|
|
125
|
+
async redo(): Promise<void> {
|
|
126
|
+
if (this.canRedo()) {
|
|
127
|
+
const command = this.commands[++this.top];
|
|
128
|
+
try {
|
|
129
|
+
await command.redo();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
this.handleError(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
65
134
|
}
|
|
66
135
|
|
|
67
|
-
|
|
68
|
-
return
|
|
136
|
+
canRedo(): boolean {
|
|
137
|
+
return this.top < this.commands.length - 1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get isDirty(): boolean {
|
|
141
|
+
return this.saveIndex !== this.top;
|
|
69
142
|
}
|
|
70
143
|
|
|
71
144
|
saveIsDone(): void {
|
|
72
|
-
|
|
145
|
+
this.saveIndex = this.top;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
flush(): void {
|
|
149
|
+
this.commands = [];
|
|
150
|
+
this.top = -1;
|
|
151
|
+
this.saveIndex = -1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
protected handleError(error: any): never {
|
|
155
|
+
// if an error occurred during the command execution the stack might be in an erroneous state => we have to flush the command stack
|
|
156
|
+
this.flush();
|
|
157
|
+
this.logger.error('An error occurred during command execution. CommandStack will be flushed!', error);
|
|
158
|
+
throw error;
|
|
73
159
|
}
|
|
74
160
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2023 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 * as sinon from 'sinon';
|
|
18
|
+
import { expectToThrowAsync, StubCommand } from '../test/mock-util';
|
|
19
|
+
import { CompoundCommand } from './command';
|
|
20
|
+
|
|
21
|
+
describe('CompoundCommand', () => {
|
|
22
|
+
const sandbox = sinon.createSandbox();
|
|
23
|
+
|
|
24
|
+
const command1 = sandbox.stub(new StubCommand());
|
|
25
|
+
const command2 = sandbox.stub(new StubCommand());
|
|
26
|
+
const command3 = sandbox.stub(new StubCommand());
|
|
27
|
+
|
|
28
|
+
const compoundCommand = new CompoundCommand(command1, command2, command3);
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
sandbox.reset();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('execute', () => {
|
|
35
|
+
it('Should execute the subcommands in order', async () => {
|
|
36
|
+
await compoundCommand.execute();
|
|
37
|
+
expect(command1.execute.calledOnce).to.be.true;
|
|
38
|
+
expect(command2.execute.calledOnce).to.be.true;
|
|
39
|
+
expect(command3.execute.calledOnce).to.be.true;
|
|
40
|
+
expect(command1.execute.calledBefore(command2.execute)).to.be.true;
|
|
41
|
+
expect(command2.execute.calledBefore(command3.execute)).to.be.true;
|
|
42
|
+
});
|
|
43
|
+
it('Should undo partially executed subcommands in case of an error', async () => {
|
|
44
|
+
command3.execute.throwsException();
|
|
45
|
+
|
|
46
|
+
await expectToThrowAsync(() => compoundCommand.execute());
|
|
47
|
+
|
|
48
|
+
expect(command1.execute.calledOnce).to.be.true;
|
|
49
|
+
expect(command2.execute.calledOnce).to.be.true;
|
|
50
|
+
expect(command3.execute.calledOnce).to.be.true;
|
|
51
|
+
expect(command1.undo.calledOnce).to.be.true;
|
|
52
|
+
expect(command2.undo.calledOnce).to.be.true;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('undo', () => {
|
|
57
|
+
it('Should undo the subcommands in reverse order', async () => {
|
|
58
|
+
await compoundCommand.undo();
|
|
59
|
+
expect(command1.undo.calledOnce).to.be.true;
|
|
60
|
+
expect(command2.undo.calledOnce).to.be.true;
|
|
61
|
+
expect(command3.undo.calledOnce).to.be.true;
|
|
62
|
+
expect(command1.undo.calledAfter(command2.undo)).to.be.true;
|
|
63
|
+
expect(command2.undo.calledAfter(command3.undo)).to.be.true;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('Should redo partially undone subcommands in case of an error', async () => {
|
|
67
|
+
command1.undo.throwsException();
|
|
68
|
+
await expectToThrowAsync(() => compoundCommand.undo());
|
|
69
|
+
|
|
70
|
+
expect(command1.undo.calledOnce).to.be.true;
|
|
71
|
+
expect(command2.undo.calledOnce).to.be.true;
|
|
72
|
+
expect(command3.undo.calledOnce).to.be.true;
|
|
73
|
+
expect(command3.redo.calledOnce).to.be.true;
|
|
74
|
+
expect(command2.redo.calledOnce).to.be.true;
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('canUndo', () => {
|
|
79
|
+
it('should return true if all subcommands can be undone', () => {
|
|
80
|
+
command1.canUndo?.returns(true);
|
|
81
|
+
command2.canUndo?.returns(true);
|
|
82
|
+
command3.canUndo?.returns(true);
|
|
83
|
+
expect(compoundCommand.canUndo()).to.be.true;
|
|
84
|
+
});
|
|
85
|
+
it('should return true if anyof the subcommands cannot be undone', () => {
|
|
86
|
+
command1.canUndo?.returns(true);
|
|
87
|
+
command2.canUndo?.returns(false);
|
|
88
|
+
command3.canUndo?.returns(true);
|
|
89
|
+
expect(compoundCommand.canUndo()).to.be.true;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|