Create jquery-svg module and empty test, update build. Add a couple tiny unit tests for recalculate.js
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2442 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<body>
|
||||
<h1>All SVG-edit Tests</h1>
|
||||
<p>This file frames all SVG-edit test pages. This should only include tests known to work. These tests are known to pass 100% in the following: Firefox 3.6, Chrome 7, IE9 Preview 6 (1.9.8006.6000), Opera 10.63. If a test is broken in this page, it is possible that <em>YOU</em> broke it. Please do not submit code that breaks any of these tests.</p>
|
||||
<iframe src='jquery-svg_test.html' width='100%' height='70' scrolling='no'></iframe>
|
||||
<iframe src='svgtransformlist_test.html' width='100%' height='70' scrolling='no'></iframe>
|
||||
<iframe src='contextmenu_test.html' width='100%' height='70' scrolling='no'></iframe>
|
||||
<iframe src='math_test.html' width='100%' height='70' scrolling='no'></iframe>
|
||||
|
||||
27
test/jquery-svg_test.html
Normal file
27
test/jquery-svg_test.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Unit Tests for jquery-svg.js</title>
|
||||
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
||||
<script type='text/javascript' src='../editor/jquery.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);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id='qunit-header'>Unit Tests for jquery-svg</h1>
|
||||
<h2 id='qunit-banner'></h2>
|
||||
<h2 id='qunit-userAgent'></h2>
|
||||
<ol id='qunit-tests'></ol>
|
||||
<div id='root' style=''></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,6 +3,8 @@
|
||||
<head>
|
||||
<title>Unit Tests for recalculate.js</title>
|
||||
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
||||
<script type='text/javascript' src='../editor/jquery.js'></script>
|
||||
<script type='text/javascript' src='../editor/jquery-svg.js'></script>
|
||||
<script type='text/javascript' src='../editor/svgedit.js'></script>
|
||||
<script type='text/javascript' src='../editor/browser.js'></script>
|
||||
<script type='text/javascript' src='../editor/math.js'></script>
|
||||
@@ -22,6 +24,84 @@
|
||||
}
|
||||
};
|
||||
|
||||
var root = document.getElementById('root');
|
||||
var svgroot = document.createElementNS(svgedit.NS.SVG, 'svg');
|
||||
svgroot.id = 'svgroot';
|
||||
root.appendChild(svgroot);
|
||||
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
|
||||
svgroot.appendChild(svg);
|
||||
var elemId = 1;
|
||||
var elem;
|
||||
|
||||
function setUp() {
|
||||
svgedit.utilities.init({
|
||||
getSVGRoot: function() { return svg },
|
||||
getDOMDocument: function() { return null },
|
||||
getDOMContainer: function() { return null }
|
||||
});
|
||||
svgedit.coords.init({
|
||||
getGridSnapping: function() { return false; },
|
||||
getDrawing: function() {
|
||||
return {
|
||||
getNextId: function() { return '' + elemId++; }
|
||||
};
|
||||
}
|
||||
});
|
||||
svgedit.recalculate.init({
|
||||
getSVGRoot: function() { return svg },
|
||||
getStartTransform: function() { return ''},
|
||||
setStartTransform: function() { }
|
||||
});
|
||||
}
|
||||
|
||||
function setUpRect() {
|
||||
setUp();
|
||||
elem = document.createElementNS(svgedit.NS.SVG, 'rect');
|
||||
elem.setAttribute('x', '200');
|
||||
elem.setAttribute('y', '150');
|
||||
elem.setAttribute('width', '250');
|
||||
elem.setAttribute('height', '120');
|
||||
svg.appendChild(elem);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
while(svg.hasChildNodes()) {
|
||||
svg.removeChild(svg.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
test('Test recalculateDimensions() for identity matrix', function() {
|
||||
expect(1);
|
||||
|
||||
setUpRect();
|
||||
elem.setAttribute('transform', 'matrix(1,0,0,1,0,0)');
|
||||
|
||||
svgedit.recalculate.recalculateDimensions(elem);
|
||||
|
||||
// Ensure that the identity matrix is swallowed and the element has no
|
||||
// transform on it.
|
||||
equal(false, elem.hasAttribute('transform'));
|
||||
|
||||
tearDown();
|
||||
});
|
||||
|
||||
test('Test recalculateDimensions() for simple translate', function() {
|
||||
expect(1);
|
||||
|
||||
setUpRect();
|
||||
elem.setAttribute('transform', 'translate(100,50)');
|
||||
|
||||
// TODO: Need the hack to jquery's attr() at the top of svgcanvas.js
|
||||
// to make this work.
|
||||
svgedit.recalculate.recalculateDimensions(elem);
|
||||
|
||||
// Ensure that the identity matrix is swallowed and the element has no
|
||||
// transform on it.
|
||||
equal(false, elem.hasAttribute('transform'));
|
||||
|
||||
tearDown();
|
||||
});
|
||||
|
||||
// TODO: Since recalculateDimensions() and surrounding code is
|
||||
// probably the largest, most complicated and strange piece of
|
||||
// code in SVG-edit, we need to write a whole lot of unit tests
|
||||
|
||||
Reference in New Issue
Block a user