svgedit/cypress/integration/unit/contextmenu.js

60 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-07-14 16:06:33 +00:00
import '../../../instrumented/editor/jquery.min.js';
import * as contextmenu from '../../../instrumented/editor/contextmenu.js';
describe('contextmenu', function () {
/**
* Tear down tests, resetting custom menus.
* @returns {void}
*/
afterEach(() => {
contextmenu.resetCustomMenus();
});
it('Test svgedit.contextmenu package', function () {
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');
});
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' }),
null, null,
'menu item with just an id is invalid'
);
assert.throws(
2021-05-12 23:00:09 +00:00
() => contextmenu.add({ id: 'idandlabel', label: 'anicelabel' }),
null, null,
'menu item with just an id and label is invalid'
);
assert.throws(
2021-05-12 23:00:09 +00:00
() => contextmenu.add({ id: 'idandlabel', label: 'anicelabel', action: 'notafunction' }),
null, null,
'menu item with action that is not a function is invalid'
);
});
it('Test svgedit.contextmenu adds valid menu item', function () {
2021-05-12 23:00:09 +00:00
const validItem = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } };
contextmenu.add(validItem);
assert.ok(contextmenu.hasCustomHandler('valid'), 'Valid menu item is added.');
assert.equal(contextmenu.getCustomHandler('valid'), validItem.action, 'Valid menu action is added.');
});
it('Test svgedit.contextmenu rejects valid duplicate menu item id', function () {
2021-05-12 23:00:09 +00:00
const validItem1 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } };
const validItem2 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } };
contextmenu.add(validItem1);
assert.throws(
() => contextmenu.add(validItem2),
null, null,
'duplicate menu item is rejected.'
);
});
});