2013-02-20 06:42:00 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-10-29 03:32:01 +00:00
|
|
|
<meta charset="utf-8" />
|
2013-02-20 06:42:00 +00:00
|
|
|
<title>Unit Tests for recalculate.js</title>
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
<link rel="stylesheet" href="qunit/qunit.css"/>
|
|
|
|
<script src="../editor/jquery.js"></script>
|
|
|
|
<script src="../editor/jquery-svg.js"></script>
|
|
|
|
<script src="../editor/svgedit.js"></script>
|
|
|
|
<script src="../editor/pathseg.js"></script>
|
|
|
|
<script src="../editor/browser.js"></script>
|
|
|
|
<script src="../editor/math.js"></script>
|
|
|
|
<script src="../editor/history.js"></script>
|
|
|
|
<script src="../editor/units.js"></script>
|
|
|
|
<script src="../editor/svgtransformlist.js"></script>
|
|
|
|
<script src="../editor/svgutils.js"></script>
|
|
|
|
<script src="../editor/coords.js"></script>
|
|
|
|
<script src="../editor/recalculate.js"></script>
|
|
|
|
<script src="qunit/qunit.js"></script>
|
2013-10-14 02:02:33 +00:00
|
|
|
<script>
|
2013-02-20 06:42:00 +00:00
|
|
|
$(function() {
|
|
|
|
// log function
|
2014-04-07 05:33:44 +00:00
|
|
|
QUnit.log = function(details) {
|
2013-02-20 06:42:00 +00:00
|
|
|
if (window.console && window.console.log) {
|
2014-04-07 05:33:44 +00:00
|
|
|
window.console.log(details.result +' :: '+ details.message);
|
2013-02-20 06:42:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-20 15:34:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-22 14:46:50 +00:00
|
|
|
function setUpTextWithTspan() {
|
|
|
|
setUp();
|
|
|
|
elem = document.createElementNS(svgedit.NS.SVG, 'text');
|
|
|
|
elem.setAttribute('x', '200');
|
|
|
|
elem.setAttribute('y', '150');
|
|
|
|
|
|
|
|
var tspan = document.createElementNS(svgedit.NS.SVG, 'tspan');
|
|
|
|
tspan.setAttribute('x', '200');
|
|
|
|
tspan.setAttribute('y', '150');
|
|
|
|
|
|
|
|
var theText = document.createTextNode('Foo bar');
|
|
|
|
tspan.appendChild(theText);
|
|
|
|
elem.appendChild(tspan);
|
|
|
|
svg.appendChild(elem);
|
|
|
|
}
|
|
|
|
|
2013-02-20 15:34:42 +00:00
|
|
|
function tearDown() {
|
|
|
|
while(svg.hasChildNodes()) {
|
|
|
|
svg.removeChild(svg.firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 14:46:50 +00:00
|
|
|
test('Test recalculateDimensions() on rect with identity matrix', function() {
|
2013-02-20 15:34:42 +00:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
setUpRect();
|
|
|
|
elem.setAttribute('transform', 'matrix(1,0,0,1,0,0)');
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
|
2013-02-20 15:34:42 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2013-02-22 14:46:50 +00:00
|
|
|
test('Test recalculateDimensions() on rect with simple translate', function() {
|
|
|
|
expect(5);
|
2013-02-20 15:34:42 +00:00
|
|
|
|
|
|
|
setUpRect();
|
|
|
|
elem.setAttribute('transform', 'translate(100,50)');
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
|
2013-02-22 14:46:50 +00:00
|
|
|
svgedit.recalculate.recalculateDimensions(elem);
|
|
|
|
|
|
|
|
equal(false, elem.hasAttribute('transform'));
|
|
|
|
equal('300', elem.getAttribute('x'));
|
|
|
|
equal('200', elem.getAttribute('y'));
|
|
|
|
equal('250', elem.getAttribute('width'));
|
|
|
|
equal('120', elem.getAttribute('height'));
|
|
|
|
tearDown();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test recalculateDimensions() on text w/tspan with simple translate', function() {
|
2013-02-22 15:46:11 +00:00
|
|
|
expect(5);
|
2013-02-22 14:46:50 +00:00
|
|
|
|
|
|
|
setUpTextWithTspan();
|
|
|
|
elem.setAttribute('transform', 'translate(100,50)');
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
|
2013-02-20 15:34:42 +00:00
|
|
|
svgedit.recalculate.recalculateDimensions(elem);
|
|
|
|
|
|
|
|
// Ensure that the identity matrix is swallowed and the element has no
|
|
|
|
// transform on it.
|
|
|
|
equal(false, elem.hasAttribute('transform'));
|
2013-02-22 14:46:50 +00:00
|
|
|
equal('300', elem.getAttribute('x'));
|
|
|
|
equal('200', elem.getAttribute('y'));
|
|
|
|
|
2013-02-22 15:46:11 +00:00
|
|
|
var tspan = elem.firstElementChild;
|
|
|
|
equal('300', tspan.getAttribute('x'));
|
|
|
|
equal('200', tspan.getAttribute('y'));
|
2013-02-20 15:34:42 +00:00
|
|
|
|
|
|
|
tearDown();
|
|
|
|
});
|
2013-02-22 14:46:50 +00:00
|
|
|
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
// TODO: Since recalculateDimensions() and surrounding code is
|
2013-02-20 06:42:00 +00:00
|
|
|
// probably the largest, most complicated and strange piece of
|
|
|
|
// code in SVG-edit, we need to write a whole lot of unit tests
|
|
|
|
// for it here.
|
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
</head>
|
2013-10-29 03:32:01 +00:00
|
|
|
<body>
|
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
|
|
|
<h1 id="qunit-header">Unit Tests for svgedit.recalculate</h1>
|
|
|
|
<h2 id="qunit-banner"></h2>
|
|
|
|
<h2 id="qunit-userAgent"></h2>
|
|
|
|
<ol id="qunit-tests"></ol>
|
|
|
|
<div id="root" style="visibility:hidden"></div>
|
2013-02-20 06:42:00 +00:00
|
|
|
</body>
|
|
|
|
</html>
|