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