add test for label change event

This commit is contained in:
Benjamin Pasero 2016-09-12 13:59:33 +02:00
parent 176f350454
commit 2db4e12808
2 changed files with 22 additions and 3 deletions

View file

@ -749,11 +749,13 @@ export function getUntitledOrFileResource(input: IEditorInput, supportDiff?: boo
// File
let fileInput = asFileEditorInput(input, supportDiff);
return fileInput && fileInput && fileInput.getResource();
return fileInput && fileInput.getResource();
}
// TODO@Ben every editor should have an associated resource
export function getResource(input: IEditorInput): URI {
if (input && typeof (<any>input).getResource === 'function') {
if (input instanceof EditorInput && typeof (<any>input).getResource === 'function') {
let candidate = (<any>input).getResource();
if (candidate instanceof URI) {
return candidate;

View file

@ -111,6 +111,10 @@ class TestEditorInput extends EditorInput {
public setDirty(): void {
this._onDidChangeDirty.fire();
}
public setLabel(): void {
this._onDidChangeLabel.fire();
}
}
class NonSerializableTestEditorInput extends EditorInput {
@ -1641,7 +1645,7 @@ suite('Editor Stacks Model', () => {
assert.equal(input1.isDisposed(), false);
});
test('Stack - Multiple Editors - Editor Emits Dirty', function () {
test('Stack - Multiple Editors - Editor Emits Dirty and Label Changed', function () {
const model = create();
const group1 = model.openGroup('group1');
@ -1658,25 +1662,38 @@ suite('Editor Stacks Model', () => {
dirtyCounter++;
});
let labelChangeCounter = 0;
model.onEditorLabelChange(() => {
labelChangeCounter++;
});
(<TestEditorInput>input1).setDirty();
(<TestEditorInput>input1).setLabel();
assert.equal(dirtyCounter, 1);
assert.equal(labelChangeCounter, 1);
(<TestEditorInput>input2).setDirty();
(<TestEditorInput>input2).setLabel();
assert.equal(dirtyCounter, 2);
assert.equal(labelChangeCounter, 2);
group2.closeAllEditors();
(<TestEditorInput>input2).setDirty();
(<TestEditorInput>input2).setLabel();
assert.equal(dirtyCounter, 2);
assert.equal(labelChangeCounter, 2);
model.closeGroups();
(<TestEditorInput>input1).setDirty();
(<TestEditorInput>input1).setLabel();
assert.equal(dirtyCounter, 2);
assert.equal(labelChangeCounter, 2);
});
test('Groups - Model change events (structural vs state)', function () {