-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added api tests for monaco resolveKeybinding exposed api
Signed-off-by: Anton Kosyakov <[email protected]>
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
// @ts-check | ||
/// <reference types='@theia/monaco/src/typings/monaco'/> | ||
describe('Monaco API', async function () { | ||
|
||
const { assert } = chai; | ||
|
||
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager'); | ||
const Uri = require('@theia/core/lib/common/uri'); | ||
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service'); | ||
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor'); | ||
const { MonacoResolvedKeybinding } = require('@theia/monaco/lib/browser/monaco-resolved-keybinding'); | ||
|
||
/** @type {import('inversify').Container} */ | ||
const container = window['theia'].container; | ||
const editorManager = container.get(EditorManager); | ||
const workspaceService = container.get(WorkspaceService); | ||
|
||
/** @type {MonacoEditor} */ | ||
let monacoEditor; | ||
|
||
before(async () => { | ||
const root = workspaceService.tryGetRoots()[0]; | ||
const editor = await editorManager.open(new Uri.default(root.uri).resolve('package.json'), { | ||
mode: 'reveal' | ||
}); | ||
monacoEditor = MonacoEditor.get(editor); | ||
}); | ||
|
||
it('KeybindingService.resolveKeybinding', () => { | ||
const simpleKeybinding = new monaco.keybindings.SimpleKeybinding(true, true, true, true, monaco.KeyCode.KEY_K); | ||
const chordKeybinding = simpleKeybinding.toChord(); | ||
assert.equal(chordKeybinding.parts.length, 1); | ||
assert.equal(chordKeybinding.parts[0], simpleKeybinding); | ||
|
||
const resolvedKeybindings = monacoEditor.getControl()._standaloneKeybindingService.resolveKeybinding(chordKeybinding); | ||
assert.equal(resolvedKeybindings.length, 1); | ||
|
||
const resolvedKeybinding = resolvedKeybindings[0]; | ||
if (resolvedKeybinding instanceof MonacoResolvedKeybinding) { | ||
const label = resolvedKeybinding.getLabel(); | ||
const ariaLabel = resolvedKeybinding.getAriaLabel(); | ||
const electronAccelerator = resolvedKeybinding.getElectronAccelerator(); | ||
const userSettingsLabel = resolvedKeybinding.getUserSettingsLabel(); | ||
const WYSIWYG = resolvedKeybinding.isWYSIWYG(); | ||
const chord = resolvedKeybinding.isChord(); | ||
const parts = resolvedKeybinding.getParts(); | ||
const dispatchParts = resolvedKeybinding.getDispatchParts(); | ||
assert.deepStrictEqual({ | ||
label, ariaLabel, electronAccelerator, userSettingsLabel, WYSIWYG, chord, parts, dispatchParts | ||
}, { | ||
label: "Ctrl+Shift+Alt+K", | ||
ariaLabel: "Ctrl+Shift+Alt+K", | ||
electronAccelerator: null, | ||
userSettingsLabel: "ctrl+shift+alt+K", | ||
WYSIWYG: true, | ||
chord: false, | ||
parts: [{ | ||
altKey: true, | ||
ctrlKey: true, | ||
keyAriaLabel: "K", | ||
keyLabel: "K", | ||
metaKey: false, | ||
shiftKey: true | ||
}], | ||
dispatchParts: [ | ||
"ctrl+shift+alt+K" | ||
] | ||
}); | ||
} else { | ||
assert.fail(`resolvedKeybinding must be of ${MonacoResolvedKeybinding.name} type`); | ||
} | ||
}); | ||
|
||
}); |