svgedit/test/contextmenu_test.html

84 lines
2.9 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Unit Tests for contextmenu.js</title>
<link rel="stylesheet" href="qunit/qunit.css"/>
<script src="../editor/jquery.js"></script>
<script>
// Mock for browser.js
window.svgEditor = {ready: function(){}};
</script>
<script src="../editor/contextmenu.js"></script>
<script src="qunit/qunit.js"></script>
<script>
$(function() {
// log function
QUnit.log = function(details) {
if (window.console && window.console.log) {
window.console.log(details.result +' :: '+ details.message);
}
};
function tearDown(){
svgedit.contextmenu.resetCustomMenus();
}
module('svgedit.contextmenu');
test('Test svgedit.contextmenu package', function() {
expect(4);
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");
});
test('Test svgedit.contextmenu does not add invalid menu item', function() {
expect(3);
svgedit.contextmenu.add({id:"justanid"});
ok(!svgedit.contextmenu.hasCustomHandler("justanid"),"menu item with just an id is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel"});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with just an id and label is invalid");
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");
});
test('Test svgedit.contextmenu adds valid menu item', function() {
expect(2);
var validItem = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
svgedit.contextmenu.add(validItem);
ok(svgedit.contextmenu.hasCustomHandler("valid"),"Valid menu item is added.");
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem.action,"Valid menu action is added.");
tearDown();
});
test('Test svgedit.contextmenu rejects valid duplicate menu item id', function() {
expect(1);
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);
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem1.action,"duplicate menu item is rejected.");
tearDown();
});
});
</script>
</head>
<body>
<h1 id="qunit-header">Unit Tests for contextmenu.js</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="svgroot" style="visibility:hidden"></div>
</body>
</html>