Skip to content

Commit

Permalink
added api tests for monaco resolveKeybinding exposed api
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Jan 22, 2020
1 parent 64e055a commit 2ec041b
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions examples/api-tests/src/monaco-api.spec.js
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`);
}
});

});

0 comments on commit 2ec041b

Please sign in to comment.