Path: blob/main/src/vs/editor/standalone/test/browser/standaloneServices.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { KeyCode } from '../../../../base/common/keyCodes.js';7import { DisposableStore } from '../../../../base/common/lifecycle.js';8import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';9import { StandaloneCodeEditorService } from '../../browser/standaloneCodeEditorService.js';10import { StandaloneCommandService, StandaloneConfigurationService, StandaloneKeybindingService, StandaloneNotificationService } from '../../browser/standaloneServices.js';11import { StandaloneThemeService } from '../../browser/standaloneThemeService.js';12import { ContextKeyService } from '../../../../platform/contextkey/browser/contextKeyService.js';13import { InstantiationService } from '../../../../platform/instantiation/common/instantiationService.js';14import { ServiceCollection } from '../../../../platform/instantiation/common/serviceCollection.js';15import { IKeyboardEvent } from '../../../../platform/keybinding/common/keybinding.js';16import { NullLogService } from '../../../../platform/log/common/log.js';17import { NullTelemetryService } from '../../../../platform/telemetry/common/telemetryUtils.js';1819suite('StandaloneKeybindingService', () => {2021ensureNoDisposablesAreLeakedInTestSuite();2223class TestStandaloneKeybindingService extends StandaloneKeybindingService {24public testDispatch(e: IKeyboardEvent): void {25super._dispatch(e, null!);26}27}2829test('issue microsoft/monaco-editor#167', () => {3031const disposables = new DisposableStore();32const serviceCollection = new ServiceCollection();33const instantiationService = new InstantiationService(serviceCollection, true);34const configurationService = new StandaloneConfigurationService(new NullLogService());35const contextKeyService = disposables.add(new ContextKeyService(configurationService));36const commandService = new StandaloneCommandService(instantiationService);37const notificationService = new StandaloneNotificationService();38const standaloneThemeService = disposables.add(new StandaloneThemeService());39const codeEditorService = disposables.add(new StandaloneCodeEditorService(contextKeyService, standaloneThemeService));40const keybindingService = disposables.add(new TestStandaloneKeybindingService(contextKeyService, commandService, NullTelemetryService, notificationService, new NullLogService(), codeEditorService));4142let commandInvoked = false;43disposables.add(keybindingService.addDynamicKeybinding('testCommand', KeyCode.F9, () => {44commandInvoked = true;45}, undefined));4647keybindingService.testDispatch({48_standardKeyboardEventBrand: true,49ctrlKey: false,50shiftKey: false,51altKey: false,52metaKey: false,53altGraphKey: false,54keyCode: KeyCode.F9,55code: null!56});5758assert.ok(commandInvoked, 'command invoked');5960disposables.dispose();61});62});636465