2013-09-21 01:14:17 +04:00
|
|
|
{$$} = require 'atom'
|
2013-09-20 01:21:31 +04:00
|
|
|
|
2013-09-21 01:14:17 +04:00
|
|
|
ContextMenuManager = require '../src/context-menu-manager'
|
2013-09-20 01:21:31 +04:00
|
|
|
|
|
|
|
describe "ContextMenuManager", ->
|
|
|
|
[contextMenu] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
contextMenu = new ContextMenuManager
|
|
|
|
|
|
|
|
describe "adding definitions", ->
|
|
|
|
it 'loads', ->
|
|
|
|
contextMenu.add 'file-path',
|
|
|
|
'.selector':
|
|
|
|
'label': 'command'
|
|
|
|
|
|
|
|
expect(contextMenu.definitions['.selector'][0].label).toEqual 'label'
|
|
|
|
expect(contextMenu.definitions['.selector'][0].command).toEqual 'command'
|
|
|
|
|
2014-05-17 14:40:43 +04:00
|
|
|
it "loads submenus", ->
|
|
|
|
contextMenu.add 'file-path',
|
|
|
|
'.selector':
|
|
|
|
'parent': [
|
|
|
|
'child-1': 'child-1:trigger'
|
|
|
|
'child-2': 'child-1:trigger'
|
|
|
|
]
|
|
|
|
'parent-2': 'parent-2:trigger'
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-20 01:21:31 +04:00
|
|
|
describe 'dev mode', ->
|
|
|
|
it 'loads', ->
|
|
|
|
contextMenu.add 'file-path',
|
|
|
|
'.selector':
|
|
|
|
'label': 'command'
|
|
|
|
, devMode: true
|
|
|
|
|
|
|
|
expect(contextMenu.devModeDefinitions['.selector'][0].label).toEqual 'label'
|
|
|
|
expect(contextMenu.devModeDefinitions['.selector'][0].command).toEqual 'command'
|
|
|
|
|
|
|
|
describe "building a menu template", ->
|
|
|
|
beforeEach ->
|
|
|
|
contextMenu.definitions = {
|
|
|
|
'.parent':[
|
|
|
|
label: 'parent'
|
|
|
|
command: 'command-p'
|
|
|
|
]
|
|
|
|
'.child': [
|
|
|
|
label: 'child'
|
|
|
|
command: 'command-c'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
contextMenu.devModeDefinitions =
|
|
|
|
'.parent': [
|
|
|
|
label: 'dev-label'
|
|
|
|
command: 'dev-command'
|
|
|
|
]
|
|
|
|
|
|
|
|
describe "on a single element", ->
|
|
|
|
[element] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
element = ($$ -> @div class: 'parent')[0]
|
|
|
|
|
|
|
|
it "creates a menu with a single item", ->
|
|
|
|
menu = contextMenu.combinedMenuTemplateForElement(element)
|
|
|
|
|
|
|
|
expect(menu[0].label).toEqual 'parent'
|
|
|
|
expect(menu[0].command).toEqual 'command-p'
|
|
|
|
expect(menu[1]).toBeUndefined()
|
|
|
|
|
|
|
|
describe "in devMode", ->
|
|
|
|
beforeEach -> contextMenu.devMode = true
|
|
|
|
|
|
|
|
it "creates a menu with development items", ->
|
|
|
|
menu = contextMenu.combinedMenuTemplateForElement(element)
|
|
|
|
|
|
|
|
expect(menu[0].label).toEqual 'parent'
|
|
|
|
expect(menu[0].command).toEqual 'command-p'
|
2013-09-20 01:55:17 +04:00
|
|
|
expect(menu[1].type).toEqual 'separator'
|
|
|
|
expect(menu[2].label).toEqual 'dev-label'
|
|
|
|
expect(menu[2].command).toEqual 'dev-command'
|
2013-09-20 01:21:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
describe "on multiple elements", ->
|
|
|
|
[element] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
element = $$ ->
|
|
|
|
@div class: 'parent', =>
|
|
|
|
@div class: 'child'
|
|
|
|
|
|
|
|
element = element.find('.child')[0]
|
|
|
|
|
|
|
|
it "creates a menu with a two items", ->
|
|
|
|
menu = contextMenu.combinedMenuTemplateForElement(element)
|
|
|
|
|
|
|
|
expect(menu[0].label).toEqual 'child'
|
|
|
|
expect(menu[0].command).toEqual 'command-c'
|
|
|
|
expect(menu[1].label).toEqual 'parent'
|
|
|
|
expect(menu[1].command).toEqual 'command-p'
|
|
|
|
expect(menu[2]).toBeUndefined()
|
|
|
|
|
|
|
|
describe "in devMode", ->
|
|
|
|
beforeEach -> contextMenu.devMode = true
|
|
|
|
|
|
|
|
xit "creates a menu with development items", ->
|
|
|
|
menu = contextMenu.combinedMenuTemplateForElement(element)
|
|
|
|
|
|
|
|
expect(menu[0].label).toEqual 'child'
|
|
|
|
expect(menu[0].command).toEqual 'command-c'
|
|
|
|
expect(menu[1].label).toEqual 'parent'
|
|
|
|
expect(menu[1].command).toEqual 'command-p'
|
|
|
|
expect(menu[2].label).toEqual 'dev-label'
|
|
|
|
expect(menu[2].command).toEqual 'dev-command'
|
|
|
|
expect(menu[3]).toBeUndefined()
|
|
|
|
|
|
|
|
describe "#executeBuildHandlers", ->
|
|
|
|
menuTemplate = [
|
|
|
|
label: 'label'
|
|
|
|
executeAtBuild: ->
|
|
|
|
]
|
|
|
|
event =
|
|
|
|
target: null
|
|
|
|
|
|
|
|
it 'should invoke the executeAtBuild fn', ->
|
|
|
|
buildFn = spyOn(menuTemplate[0], 'executeAtBuild')
|
|
|
|
contextMenu.executeBuildHandlers(event, menuTemplate)
|
|
|
|
|
|
|
|
expect(buildFn).toHaveBeenCalled()
|
|
|
|
expect(buildFn.mostRecentCall.args[0]).toBe event
|
|
|
|
|