From 018d6ae77dacf88d0145d3958ca2579b7a579458 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 6 Apr 2017 18:34:18 +0200 Subject: [PATCH] Debt: Tests for keybinding editor model (Cont...) --- .../common/keybindingsEditorModel.test.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts b/src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts index 7a0c3dc1235..42eb5d74d8f 100644 --- a/src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts +++ b/src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts @@ -214,6 +214,61 @@ suite('Keybindings Editor Model test', () => { }); }); + test('filter by command id', () => { + const id = 'workbench.action.increaseViewSize'; + registerCommandWithTitle(id, 'some title'); + prepareKeybindingService(); + + return testObject.resolve().then(() => { + const actual = testObject.fetch('workbench action view size').filter(element => element.keybindingItem.command === id)[0]; + assert.ok(actual); + }); + }); + + test('filter by command title', () => { + const id = 'a' + uuid.generateUuid(); + registerCommandWithTitle(id, 'Increase view size'); + prepareKeybindingService(); + + return testObject.resolve().then(() => { + const actual = testObject.fetch('increase size').filter(element => element.keybindingItem.command === id)[0]; + assert.ok(actual); + }); + }); + + test('filter by default source', () => { + const command = 'a' + uuid.generateUuid(); + const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape }, when: 'context1 && context2' }); + prepareKeybindingService(expected); + + return testObject.resolve().then(() => { + const actual = testObject.fetch('default').filter(element => element.keybindingItem.command === command)[0]; + assert.ok(actual); + }); + }); + + test('filter by user source', () => { + const command = 'a' + uuid.generateUuid(); + const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape }, when: 'context1 && context2', isDefault: false }); + prepareKeybindingService(expected); + + return testObject.resolve().then(() => { + const actual = testObject.fetch('user').filter(element => element.keybindingItem.command === command)[0]; + assert.ok(actual); + }); + }); + + test('filter by when context', () => { + const command = 'a' + uuid.generateUuid(); + const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape }, when: 'whenContext1 && whenContext2', isDefault: false }); + prepareKeybindingService(expected); + + return testObject.resolve().then(() => { + const actual = testObject.fetch('when context').filter(element => element.keybindingItem.command === command)[0]; + assert.ok(actual); + }); + }); + function prepareKeybindingService(...keybindingItems: ResolvedKeybindingItem[]): ResolvedKeybindingItem[] { instantiationService.stub(IKeybindingService, 'getKeybindings', () => keybindingItems); instantiationService.stub(IKeybindingService, 'getDefaultKeybindings', () => keybindingItems); -- GitLab