Mailspring/spec/menu-manager-spec.coffee
Ben Gotow a48ddd51f8 refactor(menus): Major prune of keymaps/commands, real conditional menus
Summary:
Keymaps & menus CSON => JSON, remove AtomKeymaps, CommandRegistry use of CSS selectors, use Mousetrap instead

Important Notes:

- The `application:` prefix is reserved for commands which are handled in the application process. Don't use it for other things. You will not receive the events in the window.

- Maintaining dynamic menus seems to come with quite an overhead, because Electron updates the entire menu every time. In the future, we'll need https://github.com/electron/electron/issues/528 to really make things nice. I will be tracking this upstream.

- The format for keyboard shortcuts has changed. `cmd-X` is now `command+shift+x`

Test Plan: Run tests

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2917
2016-04-24 12:16:25 -05:00

49 lines
1.9 KiB
CoffeeScript

MenuManager = require '../src/menu-manager'
describe "MenuManager", ->
menu = null
beforeEach ->
menu = new MenuManager(resourcePath: NylasEnv.getLoadSettings().resourcePath)
menu.template = []
describe "::add(items)", ->
it "can add new menus that can be removed with the returned disposable", ->
disposable = menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
expect(menu.template).toEqual [{label: "A", submenu: [{label: "B", command: "b"}]}]
disposable.dispose()
expect(menu.template).toEqual []
it "can add submenu items to existing menus that can be removed with the returned disposable", ->
disposable1 = menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
disposable2 = menu.add [{label: "A", submenu: [{label: "C", submenu: [{label: "D", command: 'd'}]}]}]
disposable3 = menu.add [{label: "A", submenu: [{label: "C", submenu: [{label: "E", command: 'e'}]}]}]
expect(menu.template).toEqual [{
label: "A",
submenu: [
{label: "B", command: "b"},
{label: "C", submenu: [{label: 'D', command: 'd'}, {label: 'E', command: 'e'}]}
]
}]
disposable3.dispose()
expect(menu.template).toEqual [{
label: "A",
submenu: [
{label: "B", command: "b"},
{label: "C", submenu: [{label: 'D', command: 'd'}]}
]
}]
disposable2.dispose()
expect(menu.template).toEqual [{label: "A", submenu: [{label: "B", command: "b"}]}]
disposable1.dispose()
expect(menu.template).toEqual []
it "does not add duplicate labels to the same menu", ->
originalItemCount = menu.template.length
menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
expect(menu.template[originalItemCount]).toEqual {label: "A", submenu: [{label: "B", command: "b"}]}