2022-11-27 22:01:27 +00:00
|
|
|
import * as contextmenu from '../../../src/editor/contextmenu.js'
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
describe('contextmenu', function () {
|
|
|
|
/**
|
|
|
|
* Tear down tests, resetting custom menus.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
afterEach(() => {
|
2021-12-28 14:02:29 +00:00
|
|
|
contextmenu.resetCustomMenus()
|
|
|
|
})
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
it('Test svgedit.contextmenu package', function () {
|
2021-12-28 14:02:29 +00:00
|
|
|
assert.ok(contextmenu, 'contextmenu registered correctly')
|
|
|
|
assert.ok(contextmenu.add, 'add registered correctly')
|
|
|
|
assert.ok(contextmenu.hasCustomHandler, 'contextmenu hasCustomHandler registered correctly')
|
|
|
|
assert.ok(contextmenu.getCustomHandler, 'contextmenu getCustomHandler registered correctly')
|
|
|
|
})
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
it('Test svgedit.contextmenu does not add invalid menu item', function () {
|
|
|
|
assert.throws(
|
2021-05-12 23:00:09 +00:00
|
|
|
() => contextmenu.add({ id: 'justanid' }),
|
2019-11-24 03:29:24 +00:00
|
|
|
null, null,
|
|
|
|
'menu item with just an id is invalid'
|
2021-12-28 14:02:29 +00:00
|
|
|
)
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
assert.throws(
|
2021-05-12 23:00:09 +00:00
|
|
|
() => contextmenu.add({ id: 'idandlabel', label: 'anicelabel' }),
|
2019-11-24 03:29:24 +00:00
|
|
|
null, null,
|
|
|
|
'menu item with just an id and label is invalid'
|
2021-12-28 14:02:29 +00:00
|
|
|
)
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
assert.throws(
|
2021-05-12 23:00:09 +00:00
|
|
|
() => contextmenu.add({ id: 'idandlabel', label: 'anicelabel', action: 'notafunction' }),
|
2019-11-24 03:29:24 +00:00
|
|
|
null, null,
|
|
|
|
'menu item with action that is not a function is invalid'
|
2021-12-28 14:02:29 +00:00
|
|
|
)
|
|
|
|
})
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
it('Test svgedit.contextmenu adds valid menu item', function () {
|
2021-12-28 14:02:29 +00:00
|
|
|
const validItem = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }
|
|
|
|
contextmenu.add(validItem)
|
2019-11-24 03:29:24 +00:00
|
|
|
|
2021-12-28 14:02:29 +00:00
|
|
|
assert.ok(contextmenu.hasCustomHandler('valid'), 'Valid menu item is added.')
|
|
|
|
assert.equal(contextmenu.getCustomHandler('valid'), validItem.action, 'Valid menu action is added.')
|
|
|
|
})
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
it('Test svgedit.contextmenu rejects valid duplicate menu item id', function () {
|
2021-12-28 14:02:29 +00:00
|
|
|
const validItem1 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }
|
|
|
|
const validItem2 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }
|
|
|
|
contextmenu.add(validItem1)
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => contextmenu.add(validItem2),
|
|
|
|
null, null,
|
|
|
|
'duplicate menu item is rejected.'
|
2021-12-28 14:02:29 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|