UNPKG

3.04 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const command_1 = require("../command");
19const menu_model_registry_1 = require("./menu-model-registry");
20const chai = require("chai");
21const expect = chai.expect;
22describe('menu-model-registry', () => {
23 describe('01 #register', () => {
24 it('Should allow to register menu actions.', () => {
25 const fileMenu = ['main', 'File'];
26 const fileOpenMenu = [...fileMenu, '0_open'];
27 const service = createMenuRegistry({
28 registerMenus(menuRegistry) {
29 menuRegistry.registerSubmenu(fileMenu, 'File');
30 menuRegistry.registerMenuAction(fileOpenMenu, {
31 commandId: 'open'
32 });
33 menuRegistry.registerMenuAction(fileOpenMenu, {
34 commandId: 'open.with'
35 });
36 }
37 }, {
38 registerCommands(reg) {
39 reg.registerCommand({
40 id: 'open',
41 label: 'A'
42 });
43 reg.registerCommand({
44 id: 'open.with',
45 label: 'B'
46 });
47 }
48 });
49 const all = service.getMenu();
50 const main = all.children[0];
51 expect(main.children.length).equals(1);
52 expect(main.id, 'main');
53 expect(all.children.length).equals(1);
54 const file = main.children[0];
55 expect(file.children.length).equals(1);
56 expect(file.label, 'File');
57 const openGroup = file.children[0];
58 expect(openGroup.children.length).equals(2);
59 expect(openGroup.label).undefined;
60 });
61 });
62});
63function createMenuRegistry(menuContrib, commandContrib) {
64 const cmdReg = new command_1.CommandRegistry({ getContributions: () => [commandContrib] });
65 cmdReg.onStart();
66 const menuReg = new menu_model_registry_1.MenuModelRegistry({ getContributions: () => [menuContrib] }, cmdReg);
67 menuReg.onStart();
68 return menuReg;
69}
70//# sourceMappingURL=menu.spec.js.map
\No newline at end of file