2018-05-15 15:16:28 +00:00
|
|
|
/* eslint-env qunit */
|
2018-05-18 03:25:45 +00:00
|
|
|
/* globals svgedit, equals */
|
|
|
|
|
|
|
|
// log function
|
|
|
|
QUnit.log = function (details) {
|
|
|
|
if (window.console && window.console.log) {
|
|
|
|
window.console.log(details.result + ' :: ' + details.message);
|
2018-05-18 04:12:27 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
};
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
function tearDown () {
|
|
|
|
svgedit.contextmenu.resetCustomMenus();
|
|
|
|
}
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
module('svgedit.contextmenu');
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.contextmenu package', function () {
|
|
|
|
expect(4);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
ok(svgedit.contextmenu, 'contextmenu registered correctly');
|
|
|
|
ok(svgedit.addContextMenuItem, 'addContextMenuItem registered correctly');
|
|
|
|
ok(svgedit.contextmenu.hasCustomMenuItemHandler, 'contextmenu hasCustomHandler registered correctly');
|
|
|
|
ok(svgedit.contextmenu.getCustomMenuItemHandler, 'contextmenu getCustomHandler registered correctly');
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.contextmenu does not add invalid menu item', function () {
|
|
|
|
expect(3);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
svgedit.addContextMenuItem({id: 'justanid'});
|
|
|
|
ok(!svgedit.contextmenu.hasCustomMenuItemHandler('justanid'), 'menu item with just an id is invalid');
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
svgedit.addContextMenuItem({id: 'idandlabel', label: 'anicelabel'});
|
|
|
|
ok(!svgedit.contextmenu.hasCustomMenuItemHandler('idandlabel'), 'menu item with just an id and label is invalid');
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
svgedit.addContextMenuItem({id: 'idandlabel', label: 'anicelabel', action: 'notafunction'});
|
|
|
|
ok(!svgedit.contextmenu.hasCustomMenuItemHandler('idandlabel'), 'menu item with action that is not a function is invalid');
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.contextmenu adds valid menu item', function () {
|
|
|
|
expect(2);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const validItem = {id: 'valid', label: 'anicelabel', action () { alert('testing'); }};
|
|
|
|
svgedit.addContextMenuItem(validItem);
|
|
|
|
|
|
|
|
ok(svgedit.contextmenu.hasCustomMenuItemHandler('valid'), 'Valid menu item is added.');
|
|
|
|
equals(svgedit.contextmenu.getCustomMenuItemHandler('valid'), validItem.action, 'Valid menu action is added.');
|
|
|
|
tearDown();
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.contextmenu rejects valid duplicate menu item id', function () {
|
|
|
|
expect(1);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const validItem1 = {id: 'valid', label: 'anicelabel', action () { alert('testing'); }};
|
|
|
|
const validItem2 = {id: 'valid', label: 'anicelabel', action () { alert('testingtwice'); }};
|
|
|
|
svgedit.addContextMenuItem(validItem1);
|
|
|
|
svgedit.addContextMenuItem(validItem2);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
equals(svgedit.contextmenu.getCustomMenuItemHandler('valid'), validItem1.action, 'duplicate menu item is rejected.');
|
|
|
|
tearDown();
|
2018-05-15 15:16:28 +00:00
|
|
|
});
|