From 423921905fcf7386bdd3105362fe28d21fd02a86 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 5 Jan 2018 14:08:46 -0800 Subject: [PATCH] Fix terminal config tests --- .../electron-browser/terminalConfigHelper.ts | 16 +- .../terminalConfigHelper.test.ts | 149 +++++++----------- .../electron-browser/terminalInstance.test.ts | 4 + 3 files changed, 69 insertions(+), 100 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts index 19e0a0b02fa..24a10026878 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts @@ -16,10 +16,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; import Severity from 'vs/base/common/severity'; import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal'; -interface IEditorConfiguration { - editor: IEditorOptions; -} - const DEFAULT_LINE_HEIGHT = 1.0; const MINIMUM_FONT_SIZE = 6; @@ -90,21 +86,19 @@ export class TerminalConfigHelper implements ITerminalConfigHelper { * terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties */ public getFont(excludeDimensions?: boolean): ITerminalFont { - const config = this._configurationService.getValue(); - const editorConfig = (config).editor; - const terminalConfig = this.config; + const editorConfig = this._configurationService.getValue('editor'); - let fontFamily = terminalConfig.fontFamily || editorConfig.fontFamily; + let fontFamily = this.config.fontFamily || editorConfig.fontFamily; // Work around bad font on Fedora - if (!terminalConfig.fontFamily) { + if (!this.config.fontFamily) { if (isFedora) { fontFamily = '\'DejaVu Sans Mono\''; } } - let fontSize = this._toInteger(terminalConfig.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize); - const lineHeight = terminalConfig.lineHeight ? Math.max(terminalConfig.lineHeight, 1) : DEFAULT_LINE_HEIGHT; + let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize); + const lineHeight = this.config.lineHeight ? Math.max(this.config.lineHeight, 1) : DEFAULT_LINE_HEIGHT; if (excludeDimensions) { return { diff --git a/src/vs/workbench/parts/terminal/test/electron-browser/terminalConfigHelper.test.ts b/src/vs/workbench/parts/terminal/test/electron-browser/terminalConfigHelper.test.ts index caef93152b9..62a853a848f 100644 --- a/src/vs/workbench/parts/terminal/test/electron-browser/terminalConfigHelper.test.ts +++ b/src/vs/workbench/parts/terminal/test/electron-browser/terminalConfigHelper.test.ts @@ -11,6 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper'; import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions'; import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal'; +import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; class MockConfigurationService implements IConfigurationService { public _serviceBrand: any; @@ -33,33 +34,17 @@ suite('Workbench - TerminalConfigHelper', () => { }); test('TerminalConfigHelper - getFont fontFamily', function () { - let configurationService: IConfigurationService; - let configHelper: TerminalConfigHelper; - - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo' - }, - terminal: { - integrated: { - fontFamily: 'bar' - } - } - }); - configHelper = new TerminalConfigHelper(configurationService, null, null, null); + const configurationService = new TestConfigurationService(); + configurationService.setUserConfiguration('editor', { fontFamily: 'foo' }); + configurationService.setUserConfiguration('terminal', { integrated: { fontFamily: 'bar' } }); + + let configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; assert.equal(configHelper.getFont().fontFamily, 'bar', 'terminal.integrated.fontFamily should be selected over editor.fontFamily'); - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo' - }, - terminal: { - integrated: { - fontFamily: 0 - } - } - }); + configurationService.setUserConfiguration('terminal', { integrated: { fontFamily: null } }); + + // Recreate config helper as onDidChangeConfiguration isn't implemented in TestConfigurationService configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; if (isFedora) { @@ -70,64 +55,55 @@ suite('Workbench - TerminalConfigHelper', () => { }); test('TerminalConfigHelper - getFont fontSize', function () { - let configurationService: IConfigurationService; - let configHelper: TerminalConfigHelper; - - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo', - fontSize: 9 - }, - terminal: { - integrated: { - fontFamily: 'bar', - fontSize: 10 - } + const configurationService = new TestConfigurationService(); + + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo', + fontSize: 9 + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: 'bar', + fontSize: 10 } }); - configHelper = new TerminalConfigHelper(configurationService, null, null, null); + let configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; assert.equal(configHelper.getFont().fontSize, 10, 'terminal.integrated.fontSize should be selected over editor.fontSize'); - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo' - }, - terminal: { - integrated: { - fontFamily: 0, - fontSize: 0 - } + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo' + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: null, + fontSize: 0 } }); configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; assert.equal(configHelper.getFont().fontSize, 6, 'The minimum terminal font size should be used when terminal.integrated.fontSize less than it'); - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo' - }, - terminal: { - integrated: { - fontFamily: 0, - fontSize: 1500 - } + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo' + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: 0, + fontSize: 1500 } }); configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; assert.equal(configHelper.getFont().fontSize, 25, 'The maximum terminal font size should be used when terminal.integrated.fontSize more than it'); - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo', - }, - terminal: { - integrated: { - fontFamily: 0, - fontSize: null - } + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo' + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: 0, + fontSize: null } }); configHelper = new TerminalConfigHelper(configurationService, null, null, null); @@ -136,35 +112,30 @@ suite('Workbench - TerminalConfigHelper', () => { }); test('TerminalConfigHelper - getFont lineHeight', function () { - let configurationService: IConfigurationService; - let configHelper: TerminalConfigHelper; - - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo', - lineHeight: 1 - }, - terminal: { - integrated: { - fontFamily: 0, - lineHeight: 2 - } + const configurationService = new TestConfigurationService(); + + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo', + lineHeight: 1 + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: 0, + lineHeight: 2 } }); - configHelper = new TerminalConfigHelper(configurationService, null, null, null); + let configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper.panelContainer = fixture; assert.equal(configHelper.getFont().lineHeight, 2, 'terminal.integrated.lineHeight should be selected over editor.lineHeight'); - configurationService = new MockConfigurationService({ - editor: { - fontFamily: 'foo', - lineHeight: 1 - }, - terminal: { - integrated: { - fontFamily: 0, - lineHeight: 0 - } + configurationService.setUserConfiguration('editor', { + fontFamily: 'foo', + lineHeight: 1 + }); + configurationService.setUserConfiguration('terminal', { + integrated: { + fontFamily: 0, + lineHeight: 0 } }); configHelper = new TerminalConfigHelper(configurationService, null, null, null); diff --git a/src/vs/workbench/parts/terminal/test/electron-browser/terminalInstance.test.ts b/src/vs/workbench/parts/terminal/test/electron-browser/terminalInstance.test.ts index a7f066b25bd..1dadac1f411 100644 --- a/src/vs/workbench/parts/terminal/test/electron-browser/terminalInstance.test.ts +++ b/src/vs/workbench/parts/terminal/test/electron-browser/terminalInstance.test.ts @@ -21,8 +21,11 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { TPromise } from 'vs/base/common/winjs.base'; +import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; class TestTerminalInstance extends TerminalInstance { + public _getCwd(shell: IShellLaunchConfig, root: Uri): string { return super._getCwd(shell, root); } @@ -152,6 +155,7 @@ suite('Workbench - TerminalInstance', () => { let keybindingService = new MockKeybindingService(); let terminalFocusContextKey = contextKeyService.createKey('test', false); instantiationService = new TestInstantiationService(); + instantiationService.stub(IConfigurationService, new TestConfigurationService()); instantiationService.stub(IMessageService, new TestMessageService()); instantiationService.stub(IWorkspaceContextService, new TestContextService()); instantiationService.stub(IKeybindingService, keybindingService); -- GitLab