Skip to content

Commit 06e56a4

Browse files
committed
added saveall untitled options tests
1 parent dbcf355 commit 06e56a4

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/vs/workbench/services/editor/test/browser/editorService.test.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import * as assert from 'assert';
77
import { EditorActivation, IResourceEditorInput } from 'vs/platform/editor/common/editor';
88
import { URI } from 'vs/base/common/uri';
99
import { Event } from 'vs/base/common/event';
10-
import { DEFAULT_EDITOR_ASSOCIATION, EditorCloseContext, EditorsOrder, IEditorCloseEvent, EditorInputWithOptions, IEditorPane, IResourceDiffEditorInput, isEditorInputWithOptions, IUntitledTextResourceEditorInput, IUntypedEditorInput, SideBySideEditor, isEditorInput } from 'vs/workbench/common/editor';
10+
import { DEFAULT_EDITOR_ASSOCIATION, EditorCloseContext, EditorsOrder, IEditorCloseEvent, EditorInputWithOptions, IEditorPane, IResourceDiffEditorInput, isEditorInputWithOptions, IUntitledTextResourceEditorInput, IUntypedEditorInput, SideBySideEditor, isEditorInput, EditorInputCapabilities } from 'vs/workbench/common/editor';
1111
import { workbenchInstantiationService, TestServiceAccessor, registerTestEditor, TestFileEditorInput, ITestInstantiationService, registerTestResourceEditor, registerTestSideBySideEditor, createEditorPart, registerTestFileEditor, TestTextFileEditor, TestSingletonFileEditorInput } from 'vs/workbench/test/browser/workbenchTestServices';
1212
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
1313
import { IEditorGroup, IEditorGroupsService, GroupDirection, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
1414
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
15-
import { ACTIVE_GROUP, IEditorService, PreferredGroup, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
15+
import { ACTIVE_GROUP, IBaseSaveRevertAllEditorOptions, IEditorService, PreferredGroup, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
1616
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1717
import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput';
1818
import { timeout } from 'vs/base/common/async';
@@ -2173,6 +2173,61 @@ suite('EditorService', () => {
21732173
assert.strictEqual(sameInput1.gotSaved, true);
21742174
});
21752175

2176+
test('saveAll, revertAll untitled (exclude untitled)', async function () {
2177+
await testSaveRevertUntitled({}, false, false);
2178+
await testSaveRevertUntitled({ includeUntitled: false }, false, false);
2179+
});
2180+
2181+
test('saveAll, revertAll untitled (include untitled)', async function () {
2182+
await testSaveRevertUntitled({ includeUntitled: true }, true, false);
2183+
await testSaveRevertUntitled({ includeUntitled: { includeScratchpad: false } }, true, false);
2184+
});
2185+
2186+
test('saveAll, revertAll untitled (include scratchpad)', async function () {
2187+
await testSaveRevertUntitled({ includeUntitled: { includeScratchpad: true } }, true, true);
2188+
});
2189+
2190+
async function testSaveRevertUntitled(options: IBaseSaveRevertAllEditorOptions, expectUntitled: boolean, expectScratchpad: boolean) {
2191+
const [, service] = await createEditorService();
2192+
const input1 = new TestFileEditorInput(URI.parse('my://resource1'), TEST_EDITOR_INPUT_ID);
2193+
input1.dirty = true;
2194+
const untitledInput = new TestFileEditorInput(URI.parse('my://resource2'), TEST_EDITOR_INPUT_ID);
2195+
untitledInput.dirty = true;
2196+
untitledInput.capabilities = EditorInputCapabilities.Untitled;
2197+
const scratchpadInput = new TestFileEditorInput(URI.parse('my://resource3'), TEST_EDITOR_INPUT_ID);
2198+
scratchpadInput.modified = true;
2199+
scratchpadInput.capabilities = EditorInputCapabilities.Scratchpad | EditorInputCapabilities.Untitled;
2200+
2201+
await service.openEditor(input1, { pinned: true, sticky: true });
2202+
await service.openEditor(untitledInput, { pinned: true });
2203+
await service.openEditor(scratchpadInput, { pinned: true });
2204+
2205+
const revertRes = await service.revertAll(options);
2206+
assert.strictEqual(revertRes, true);
2207+
assert.strictEqual(input1.gotReverted, true);
2208+
assert.strictEqual(untitledInput.gotReverted, expectUntitled);
2209+
assert.strictEqual(scratchpadInput.gotReverted, expectScratchpad);
2210+
2211+
input1.gotSaved = false;
2212+
untitledInput.gotSavedAs = false;
2213+
scratchpadInput.gotReverted = false;
2214+
2215+
input1.gotSaved = false;
2216+
untitledInput.gotSavedAs = false;
2217+
scratchpadInput.gotReverted = false;
2218+
2219+
input1.dirty = true;
2220+
untitledInput.dirty = true;
2221+
scratchpadInput.modified = true;
2222+
2223+
const saveRes = await service.saveAll(options);
2224+
assert.strictEqual(saveRes.success, true);
2225+
assert.strictEqual(saveRes.editors.length, expectScratchpad ? 3 : expectUntitled ? 2 : 1);
2226+
assert.strictEqual(input1.gotSaved, true);
2227+
assert.strictEqual(untitledInput.gotSaved, expectUntitled);
2228+
assert.strictEqual(scratchpadInput.gotSaved, expectScratchpad);
2229+
}
2230+
21762231
test('file delete closes editor', async function () {
21772232
return testFileDeleteEditorClose(false);
21782233
});

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
16001600
gotSavedAs = false;
16011601
gotReverted = false;
16021602
dirty = false;
1603+
modified: boolean | undefined;
16031604
private fails = false;
16041605

16051606
disableToUntyped = false;
@@ -1667,6 +1668,10 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
16671668
}
16681669
return { resource: this.resource };
16691670
}
1671+
setModified(): void { this.modified = true; }
1672+
override isModified(): boolean {
1673+
return this.modified === undefined ? this.dirty : this.modified;
1674+
}
16701675
setDirty(): void { this.dirty = true; }
16711676
override isDirty(): boolean {
16721677
return this.dirty;

0 commit comments

Comments
 (0)