2013-12-06 18:23:02 +04:00
|
|
|
assert = require 'assert'
|
2013-08-14 08:04:16 +04:00
|
|
|
remote = require 'remote'
|
2013-12-06 18:23:02 +04:00
|
|
|
|
|
|
|
Menu = remote.require 'menu'
|
2013-08-14 08:09:53 +04:00
|
|
|
MenuItem = remote.require 'menu-item'
|
2013-08-14 08:04:16 +04:00
|
|
|
|
2013-12-06 18:23:02 +04:00
|
|
|
describe 'menu module', ->
|
2013-08-14 08:04:16 +04:00
|
|
|
describe 'Menu.buildFromTemplate', ->
|
|
|
|
it 'should be able to attach extra fields', ->
|
|
|
|
menu = Menu.buildFromTemplate [label: 'text', extra: 'field']
|
|
|
|
assert.equal menu.items[0].extra, 'field'
|
2013-08-14 08:09:53 +04:00
|
|
|
|
|
|
|
describe 'Menu.insert', ->
|
|
|
|
it 'should store item in @items by its index', ->
|
|
|
|
menu = Menu.buildFromTemplate [
|
|
|
|
{label: '1'}
|
|
|
|
{label: '2'}
|
|
|
|
{label: '3'}
|
|
|
|
]
|
|
|
|
item = new MenuItem(label: 'inserted')
|
|
|
|
menu.insert 1, item
|
|
|
|
|
|
|
|
assert.equal menu.items[0].label, '1'
|
|
|
|
assert.equal menu.items[1].label, 'inserted'
|
|
|
|
assert.equal menu.items[2].label, '2'
|
|
|
|
assert.equal menu.items[3].label, '3'
|
2013-08-14 08:51:37 +04:00
|
|
|
|
|
|
|
describe 'MenuItem.click', ->
|
|
|
|
it 'should be called with the item object passed', (done) ->
|
2013-08-14 17:49:13 +04:00
|
|
|
menu = Menu.buildFromTemplate [
|
2013-08-14 08:51:37 +04:00
|
|
|
label: 'text'
|
|
|
|
click: (item) ->
|
|
|
|
assert.equal item.constructor.name, 'MenuItem'
|
|
|
|
assert.equal item.label, 'text'
|
|
|
|
done()
|
2013-08-14 17:49:13 +04:00
|
|
|
]
|
|
|
|
menu.delegate.executeCommand menu.items[0].commandId
|
2014-05-25 09:01:53 +04:00
|
|
|
|
2014-05-26 09:01:26 +04:00
|
|
|
describe 'MenuItem with checked property', ->
|
|
|
|
it 'clicking an checkbox item should flip the checked property', ->
|
|
|
|
menu = Menu.buildFromTemplate [ label: 'text', type: 'checkbox' ]
|
2014-05-25 09:01:53 +04:00
|
|
|
assert.equal menu.items[0].checked, false
|
|
|
|
menu.delegate.executeCommand menu.items[0].commandId
|
|
|
|
assert.equal menu.items[0].checked, true
|
|
|
|
|
2014-05-26 09:01:26 +04:00
|
|
|
it 'clicking an radio item should always make checked property true', ->
|
|
|
|
menu = Menu.buildFromTemplate [ label: 'text', type: 'radio' ]
|
|
|
|
menu.delegate.executeCommand menu.items[0].commandId
|
|
|
|
assert.equal menu.items[0].checked, true
|
|
|
|
menu.delegate.executeCommand menu.items[0].commandId
|
|
|
|
assert.equal menu.items[0].checked, true
|
|
|
|
|
2014-05-25 11:25:36 +04:00
|
|
|
it 'at least have one item checked in each group', ->
|
|
|
|
template = []
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [0..10]
|
|
|
|
template.push type: 'separator'
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [12..20]
|
|
|
|
menu = Menu.buildFromTemplate template
|
|
|
|
menu.delegate.menuWillShow()
|
|
|
|
assert.equal menu.items[0].checked, true
|
|
|
|
assert.equal menu.items[12].checked, true
|
|
|
|
|
2014-05-25 09:01:53 +04:00
|
|
|
it 'should assign groupId automatically', ->
|
|
|
|
template = []
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [0..10]
|
|
|
|
template.push type: 'separator'
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [12..20]
|
|
|
|
menu = Menu.buildFromTemplate template
|
|
|
|
groupId = menu.items[0].groupId
|
|
|
|
assert.equal menu.items[i].groupId, groupId for i in [0..10]
|
|
|
|
assert.equal menu.items[i].groupId, groupId + 1 for i in [12..20]
|
|
|
|
|
|
|
|
it "setting 'checked' should flip other items' 'checked' property", ->
|
|
|
|
template = []
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [0..10]
|
|
|
|
template.push type: 'separator'
|
|
|
|
template.push label: "#{i}", type: 'radio' for i in [12..20]
|
|
|
|
menu = Menu.buildFromTemplate template
|
|
|
|
assert.equal menu.items[i].checked, false for i in [0..10]
|
|
|
|
menu.items[0].checked = true
|
|
|
|
assert.equal menu.items[0].checked, true
|
|
|
|
assert.equal menu.items[i].checked, false for i in [1..10]
|
|
|
|
menu.items[10].checked = true
|
|
|
|
assert.equal menu.items[10].checked, true
|
|
|
|
assert.equal menu.items[i].checked, false for i in [0..9]
|
|
|
|
assert.equal menu.items[i].checked, false for i in [12..20]
|
|
|
|
menu.items[12].checked = true
|
|
|
|
assert.equal menu.items[10].checked, true
|
|
|
|
assert.equal menu.items[i].checked, false for i in [0..9]
|
|
|
|
assert.equal menu.items[12].checked, true
|
|
|
|
assert.equal menu.items[i].checked, false for i in [13..20]
|