Skip to content

Commit 48bc0dc

Browse files
author
Benjamin Pasero
committed
editors - add test for new close() method
1 parent 2f9b780 commit 48bc0dc

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ suite('EditorGroupsService', () => {
449449
assert.equal(editorCloseCounter1, 1);
450450
assert.equal(editorWillCloseCounter, 1);
451451

452+
assert.ok(inputInactive.gotClosed);
453+
assert.equal(inputInactive.gotClosed?.group, group.id);
454+
assert.equal(inputInactive.gotClosed?.openedInOtherGroups, false);
455+
452456
assert.equal(group.activeEditor, input);
453457

454458
assert.equal(editorStickyCounter, 0);
@@ -482,10 +486,44 @@ suite('EditorGroupsService', () => {
482486
assert.equal(group.getEditorByIndex(1), inputInactive);
483487

484488
await group.closeEditors([input, inputInactive]);
489+
490+
assert.ok(input.gotClosed);
491+
assert.equal(input.gotClosed?.group, group.id);
492+
assert.equal(input.gotClosed?.openedInOtherGroups, false);
493+
assert.ok(inputInactive.gotClosed);
494+
assert.equal(inputInactive.gotClosed?.group, group.id);
495+
assert.equal(inputInactive.gotClosed?.openedInOtherGroups, false);
496+
485497
assert.equal(group.isEmpty, true);
486498
part.dispose();
487499
});
488500

501+
test('closeEditors (one, opened in multiple groups)', async () => {
502+
const [part] = createPart();
503+
const group = part.activeGroup;
504+
assert.equal(group.isEmpty, true);
505+
506+
const rightGroup = part.addGroup(group, GroupDirection.RIGHT);
507+
508+
const input = new TestFileEditorInput(URI.file('foo/bar'), TEST_EDITOR_INPUT_ID);
509+
const inputInactive = new TestFileEditorInput(URI.file('foo/bar/inactive'), TEST_EDITOR_INPUT_ID);
510+
511+
await group.openEditors([{ editor: input, options: { pinned: true } }, { editor: inputInactive }]);
512+
await rightGroup.openEditors([{ editor: input, options: { pinned: true } }, { editor: inputInactive }]);
513+
514+
await rightGroup.closeEditor(input);
515+
516+
assert.ok(input.gotClosed);
517+
assert.equal(input.gotClosed?.group, rightGroup.id);
518+
assert.equal(input.gotClosed?.openedInOtherGroups, true);
519+
520+
await group.closeEditor(input);
521+
522+
assert.ok(input.gotClosed);
523+
assert.equal(input.gotClosed?.group, group.id);
524+
assert.equal(input.gotClosed?.openedInOtherGroups, false);
525+
});
526+
489527
test('closeEditors (except one)', async () => {
490528
const [part] = createPart();
491529
const group = part.activeGroup;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
10601060
gotSaved = false;
10611061
gotSavedAs = false;
10621062
gotReverted = false;
1063+
gotClosed: { group: GroupIdentifier, openedInOtherGroups: boolean } | undefined = undefined;
10631064
dirty = false;
10641065
private fails = false;
10651066

@@ -1106,6 +1107,10 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
11061107
return false;
11071108
}
11081109
isResolved(): boolean { return false; }
1110+
close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
1111+
this.gotClosed = { group, openedInOtherGroups };
1112+
super.close(group, openedInOtherGroups);
1113+
}
11091114
dispose(): void {
11101115
super.dispose();
11111116
this.gotDisposed = true;

0 commit comments

Comments
 (0)