websch/test/contextmenu_test.html

84 lines
2.9 KiB
HTML
Raw Normal View History

2012-05-17 22:50:00 +00:00
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
2012-07-25 06:32:18 +00:00
<script src='../editor/assets/jquery.js'></script>
2012-05-17 22:50:00 +00:00
<script>
// Mock for browser.js
window.svgedit = {};
window.svgEditor = {ready:function(){}};
</script>
<script type='text/javascript' src='../editor/contextmenu.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ 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>