2015-05-28 23:58:29 +03:00
|
|
|
path = require 'path'
|
2014-09-29 21:45:01 +04:00
|
|
|
MenuManager = require '../src/menu-manager'
|
|
|
|
|
2014-09-29 20:34:50 +04:00
|
|
|
describe "MenuManager", ->
|
2014-09-29 21:45:01 +04:00
|
|
|
menu = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
menu = new MenuManager(resourcePath: atom.getLoadSettings().resourcePath)
|
|
|
|
|
2014-09-29 20:34:50 +04:00
|
|
|
describe "::add(items)", ->
|
|
|
|
it "can add new menus that can be removed with the returned disposable", ->
|
2014-09-29 21:45:01 +04:00
|
|
|
disposable = menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
|
|
|
|
expect(menu.template).toEqual [{label: "A", submenu: [{label: "B", command: "b"}]}]
|
2014-09-29 20:34:50 +04:00
|
|
|
disposable.dispose()
|
2014-09-29 21:45:01 +04:00
|
|
|
expect(menu.template).toEqual []
|
2014-09-29 20:34:50 +04:00
|
|
|
|
2014-09-29 21:11:10 +04:00
|
|
|
it "can add submenu items to existing menus that can be removed with the returned disposable", ->
|
2014-09-29 21:45:01 +04:00
|
|
|
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'}]}]}]
|
2014-09-29 20:34:50 +04:00
|
|
|
|
2014-09-29 21:45:01 +04:00
|
|
|
expect(menu.template).toEqual [{
|
2014-09-29 20:34:50 +04:00
|
|
|
label: "A",
|
|
|
|
submenu: [
|
|
|
|
{label: "B", command: "b"},
|
|
|
|
{label: "C", submenu: [{label: 'D', command: 'd'}, {label: 'E', command: 'e'}]}
|
|
|
|
]
|
2014-09-29 21:45:01 +04:00
|
|
|
}]
|
2014-09-29 20:34:50 +04:00
|
|
|
|
|
|
|
disposable3.dispose()
|
2014-09-29 21:45:01 +04:00
|
|
|
expect(menu.template).toEqual [{
|
2014-09-29 20:34:50 +04:00
|
|
|
label: "A",
|
|
|
|
submenu: [
|
|
|
|
{label: "B", command: "b"},
|
|
|
|
{label: "C", submenu: [{label: 'D', command: 'd'}]}
|
|
|
|
]
|
2014-09-29 21:45:01 +04:00
|
|
|
}]
|
2014-09-29 20:34:50 +04:00
|
|
|
|
|
|
|
disposable2.dispose()
|
2014-09-29 21:45:01 +04:00
|
|
|
expect(menu.template).toEqual [{label: "A", submenu: [{label: "B", command: "b"}]}]
|
2014-09-29 20:34:50 +04:00
|
|
|
|
|
|
|
disposable1.dispose()
|
2014-09-29 21:45:01 +04:00
|
|
|
expect(menu.template).toEqual []
|
2014-09-29 21:11:36 +04:00
|
|
|
|
|
|
|
it "does not add duplicate labels to the same menu", ->
|
2014-09-29 21:45:01 +04:00
|
|
|
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"}]}
|
2015-05-28 23:58:29 +03:00
|
|
|
|
|
|
|
describe "::update()", ->
|
|
|
|
it "sends the current menu template and associated key bindings to the browser process", ->
|
|
|
|
spyOn(menu, 'sendToBrowserProcess')
|
|
|
|
menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
|
|
|
|
atom.keymap.add 'test', 'atom-workspace': 'ctrl-b': 'b'
|
|
|
|
menu.update()
|
|
|
|
|
|
|
|
waits 1
|
|
|
|
|
|
|
|
runs -> expect(menu.sendToBrowserProcess.argsForCall[0][1]['b']).toEqual ['ctrl-b']
|
|
|
|
|
|
|
|
it "omits key bindings that are mapped to unset! in any context", ->
|
|
|
|
# it would be nice to be smarter about omitting, but that would require a much
|
|
|
|
# more dynamic interaction between the currently focused element and the menu
|
|
|
|
spyOn(menu, 'sendToBrowserProcess')
|
|
|
|
menu.add [{label: "A", submenu: [{label: "B", command: "b"}]}]
|
|
|
|
atom.keymap.add 'test', 'atom-workspace': 'ctrl-b': 'b'
|
|
|
|
atom.keymap.add 'test', 'atom-text-editor': 'ctrl-b': 'unset!'
|
|
|
|
|
|
|
|
waits 1
|
|
|
|
|
|
|
|
runs -> expect(menu.sendToBrowserProcess.argsForCall[0][1]['b']).toBeUndefined()
|
|
|
|
|
|
|
|
it "updates the application menu when a keymap is reloaded", ->
|
|
|
|
spyOn(menu, 'update')
|
|
|
|
keymapPath = path.join(__dirname, 'fixtures', 'packages', 'package-with-keymaps', 'keymaps', 'keymap-1.cson')
|
|
|
|
atom.keymaps.reloadKeymap(keymapPath)
|
|
|
|
expect(menu.update).toHaveBeenCalled()
|