Skip to content

Commit 7c045e7

Browse files
committed
Add more undo-redo tests
1 parent 7e0da93 commit 7c045e7

21 files changed

Lines changed: 98 additions & 21 deletions

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"vs/nls",
186186
"**/vs/base/common/**",
187187
"**/vs/base/parts/*/common/**",
188+
"**/vs/base/test/common/**",
188189
"**/vs/platform/*/common/**",
189190
"**/vs/platform/*/test/common/**"
190191
]

src/vs/platform/undoRedo/test/common/undoRedoService.test.ts

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import { TestDialogService } from 'vs/platform/dialogs/test/common/testDialogSer
99
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
1010
import { UndoRedoElementType, IUndoRedoElement } from 'vs/platform/undoRedo/common/undoRedo';
1111
import { URI } from 'vs/base/common/uri';
12+
import { mock } from 'vs/base/test/common/mock';
13+
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
1214

1315
suite('UndoRedoService', () => {
1416

15-
function createUndoRedoService(): UndoRedoService {
16-
const dialogService = new TestDialogService();
17+
function createUndoRedoService(dialogService: IDialogService = new TestDialogService()): UndoRedoService {
1718
const notificationService = new TestNotificationService();
1819
return new UndoRedoService(dialogService, notificationService);
1920
}
2021

21-
test('simple single element', () => {
22+
test('simple single resource elements', () => {
2223
const resource = URI.file('test.txt');
2324
const service = createUndoRedoService();
2425

@@ -128,4 +129,79 @@ suite('UndoRedoService', () => {
128129
assert.ok(service.getLastElement(resource) === null);
129130
});
130131

132+
test('multi resource elements', async () => {
133+
const resource1 = URI.file('test1.txt');
134+
const resource2 = URI.file('test2.txt');
135+
const service = createUndoRedoService(new class extends mock<IDialogService>() {
136+
async show() {
137+
return {
138+
choice: 0 // confirm!
139+
};
140+
}
141+
});
142+
143+
let undoCall1 = 0, undoCall11 = 0, undoCall12 = 0;
144+
let redoCall1 = 0, redoCall11 = 0, redoCall12 = 0;
145+
const element1: IUndoRedoElement = {
146+
type: UndoRedoElementType.Workspace,
147+
resources: [resource1, resource2],
148+
label: 'typing 1',
149+
undo: () => { undoCall1++; },
150+
redo: () => { redoCall1++; },
151+
split: () => {
152+
return [
153+
{
154+
type: UndoRedoElementType.Resource,
155+
resource: resource1,
156+
label: 'typing 1.1',
157+
undo: () => { undoCall11++; },
158+
redo: () => { redoCall11++; }
159+
},
160+
{
161+
type: UndoRedoElementType.Resource,
162+
resource: resource2,
163+
label: 'typing 1.2',
164+
undo: () => { undoCall12++; },
165+
redo: () => { redoCall12++; }
166+
}
167+
];
168+
}
169+
};
170+
service.pushElement(element1);
171+
172+
assert.equal(service.canUndo(resource1), true);
173+
assert.equal(service.canRedo(resource1), false);
174+
assert.equal(service.hasElements(resource1), true);
175+
assert.ok(service.getLastElement(resource1) === element1);
176+
assert.equal(service.canUndo(resource2), true);
177+
assert.equal(service.canRedo(resource2), false);
178+
assert.equal(service.hasElements(resource2), true);
179+
assert.ok(service.getLastElement(resource2) === element1);
180+
181+
await service.undo(resource1);
182+
183+
assert.equal(undoCall1, 1);
184+
assert.equal(redoCall1, 0);
185+
assert.equal(service.canUndo(resource1), false);
186+
assert.equal(service.canRedo(resource1), true);
187+
assert.equal(service.hasElements(resource1), true);
188+
assert.ok(service.getLastElement(resource1) === null);
189+
assert.equal(service.canUndo(resource2), false);
190+
assert.equal(service.canRedo(resource2), true);
191+
assert.equal(service.hasElements(resource2), true);
192+
assert.ok(service.getLastElement(resource2) === null);
193+
194+
await service.redo(resource2);
195+
assert.equal(undoCall1, 1);
196+
assert.equal(redoCall1, 1);
197+
assert.equal(service.canUndo(resource1), true);
198+
assert.equal(service.canRedo(resource1), false);
199+
assert.equal(service.hasElements(resource1), true);
200+
assert.ok(service.getLastElement(resource1) === element1);
201+
assert.equal(service.canUndo(resource2), true);
202+
assert.equal(service.canRedo(resource2), false);
203+
assert.equal(service.hasElements(resource2), true);
204+
assert.ok(service.getLastElement(resource2) === element1);
205+
206+
});
131207
});

src/vs/workbench/test/browser/api/extHostApiCommands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ITextModel } from 'vs/editor/common/model';
3030
import { nullExtensionDescription, IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
3131
import { dispose } from 'vs/base/common/lifecycle';
3232
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
33-
import { mock } from 'vs/workbench/test/browser/api/mock';
33+
import { mock } from 'vs/base/test/common/mock';
3434
import { NullApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
3535
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
3636
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';

src/vs/workbench/test/browser/api/extHostCommands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
88
import { MainThreadCommandsShape } from 'vs/workbench/api/common/extHost.protocol';
99
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1010
import { SingleProxyRPCProtocol } from './testRPCProtocol';
11-
import { mock } from 'vs/workbench/test/browser/api/mock';
11+
import { mock } from 'vs/base/test/common/mock';
1212
import { NullLogService } from 'vs/platform/log/common/log';
1313

1414
suite('ExtHostCommands', function () {

src/vs/workbench/test/browser/api/extHostConfiguration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfigurat
1010
import { MainThreadConfigurationShape, IConfigurationInitData } from 'vs/workbench/api/common/extHost.protocol';
1111
import { ConfigurationModel, ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels';
1212
import { TestRPCProtocol } from './testRPCProtocol';
13-
import { mock } from 'vs/workbench/test/browser/api/mock';
13+
import { mock } from 'vs/base/test/common/mock';
1414
import { IWorkspaceFolder, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
1515
import { ConfigurationTarget, IConfigurationModel, IConfigurationChange } from 'vs/platform/configuration/common/configuration';
1616
import { NullLogService } from 'vs/platform/log/common/log';

src/vs/workbench/test/browser/api/extHostDiagnostics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DiagnosticCollection, ExtHostDiagnostics } from 'vs/workbench/api/commo
99
import { Diagnostic, DiagnosticSeverity, Range, DiagnosticRelatedInformation, Location } from 'vs/workbench/api/common/extHostTypes';
1010
import { MainThreadDiagnosticsShape, IMainContext } from 'vs/workbench/api/common/extHost.protocol';
1111
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
12-
import { mock } from 'vs/workbench/test/browser/api/mock';
12+
import { mock } from 'vs/base/test/common/mock';
1313
import { Emitter, Event } from 'vs/base/common/event';
1414
import { NullLogService } from 'vs/platform/log/common/log';
1515
import type * as vscode from 'vscode';

src/vs/workbench/test/browser/api/extHostDocumentData.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Position } from 'vs/workbench/api/common/extHostTypes';
1010
import { Range } from 'vs/editor/common/core/range';
1111
import { MainThreadDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
1212
import { IModelChangedEvent } from 'vs/editor/common/model/mirrorTextModel';
13-
import { mock } from 'vs/workbench/test/browser/api/mock';
13+
import { mock } from 'vs/base/test/common/mock';
1414

1515

1616
suite('ExtHostDocumentData', () => {

src/vs/workbench/test/browser/api/extHostDocumentSaveParticipant.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/common/extHostD
1212
import { SingleProxyRPCProtocol } from './testRPCProtocol';
1313
import { SaveReason } from 'vs/workbench/common/editor';
1414
import type * as vscode from 'vscode';
15-
import { mock } from 'vs/workbench/test/browser/api/mock';
15+
import { mock } from 'vs/base/test/common/mock';
1616
import { NullLogService } from 'vs/platform/log/common/log';
1717
import { timeout } from 'vs/base/common/async';
1818
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';

src/vs/workbench/test/browser/api/extHostLanguageFeatures.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { getColors } from 'vs/editor/contrib/colorPicker/color';
4343
import { CancellationToken } from 'vs/base/common/cancellation';
4444
import { nullExtensionDescription as defaultExtension } from 'vs/workbench/services/extensions/common/extensions';
4545
import { provideSelectionRanges } from 'vs/editor/contrib/smartSelect/smartSelect';
46-
import { mock } from 'vs/workbench/test/browser/api/mock';
46+
import { mock } from 'vs/base/test/common/mock';
4747
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
4848
import { dispose } from 'vs/base/common/lifecycle';
4949
import { withNullAsUndefined } from 'vs/base/common/types';

0 commit comments

Comments
 (0)