- Security fix: 'extPath', 'imgPath', 'extIconsPath', 'canvgPath', 'langPath', 'jGraduatePath', and 'jspdfPath' were not being prevented
- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention) - Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor) - Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js" - Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js" - Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js" - Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css" - Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name) - Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js" - Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js" - Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg) - Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency - Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency - Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary) - Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js` - Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential) - Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n - Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways). - Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name - Breaking change: Have `readLang` return lang and data but do not call `setLang` - Fix: Have general locales load first so extensions may use - Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded - Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG - Fix: Wrong name for moinsave - Update: Update WebAppFind per new API changes - Enhancement: Make `setStrings` public on editor for late setting (used by `ext-shapes.js`) - Enhancement: Add `extensions_added` event - Enhancement: Add `message` event (Relay messages including those which have been been received prior to extension load) - Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers - Enhancement: Allow avoiding "name" in extension export (just extract out of file name) - Enhancement: Add stack blur to canvg by default (and refactoring it) - Enhancement: Return `Promise` for `embedImage` (as with some other loading methods) - Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading - Enhancement: Recover if an extension fails to load (just log and otherwise ignore) - Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too - Enhancement: Allowing importing of locales within `addLangData` - npm: Update devDeps - Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved - Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements - Docs: Add Edtior doc file for help to general users - Docs: Clarify/simplify install instructions - npm/Docs (JSDoc): Add script to check for overly generic types - Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc) - Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names) - Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns` - Docs (JSDoc): Add our own layout template to support overflow - Docs (JSDoc): Use cleverLinks and disallow unknown tags - Docs (JSDoc): Insist on "pedantic" flag; put output directory in config - Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object - Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens` - Docs: Generally update/improve docs (fixes #92) - Docs: Update links to `latest` path (Avoid needing to update such references upon each release) - Docs: 80 chars max - Refactoring: Drop code for extension as function (already requiring export to be an object) - Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names - Refactoring: Add a `Command` base class - Refactoring: Simplify svgicons `callback` ready detection - Refactoring: Put `let` or `const` closer to scope - Refactoring: Remove unneeded `delimiter` from regex escaping utility - Refactoring: Clearer variable names - Refactoring: Use (non-deprecated) Event constructors - Testing: Use new Sinon
This commit is contained in:
@@ -18,13 +18,13 @@
|
||||
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" scrolling="no"></iframe>
|
||||
<iframe src="jQuery.attr_test.html" scrolling="no"></iframe>
|
||||
-->
|
||||
<iframe src="svgtransformlist_test.html" scrolling="no"></iframe>
|
||||
<iframe src="contextmenu_test.html" scrolling="no"></iframe>
|
||||
<iframe src="math_test.html" scrolling="no"></iframe>
|
||||
<iframe src="svgutils_test.html" scrolling="no"></iframe>
|
||||
<iframe src="svgutils_bbox_test.html" scrolling="no"></iframe>
|
||||
<iframe src="utilities_test.html" scrolling="no"></iframe>
|
||||
<iframe src="utilities_bbox_test.html" scrolling="no"></iframe>
|
||||
<iframe src="history_test.html" scrolling="no"></iframe>
|
||||
<iframe src="select_test.html" scrolling="no"></iframe>
|
||||
<iframe src="draw_test.html" scrolling="no"></iframe>
|
||||
@@ -35,6 +35,6 @@
|
||||
<iframe src="recalculate_test.html" scrolling="no"></iframe>
|
||||
|
||||
<iframe src="test1.html" scrolling="no"></iframe>
|
||||
<iframe src="svgutils_performance_test.html" scrolling="no"></iframe>
|
||||
<iframe src="utilities_performance_test.html" scrolling="no"></iframe>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<script type="module" src="coords_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Unit Tests for svgedit.coords</h1>
|
||||
<h1 id="qunit-header">Unit Tests for coords</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env qunit */
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as coords from '../editor/coords.js';
|
||||
|
||||
// log function
|
||||
@@ -20,19 +20,29 @@ svgroot.append(svg);
|
||||
let elemId = 1;
|
||||
function setUp () {
|
||||
// Mock out editor context.
|
||||
utilities.init({
|
||||
getSVGRoot () { return svg; },
|
||||
getDOMDocument () { return null; },
|
||||
getDOMContainer () { return null; }
|
||||
});
|
||||
coords.init({
|
||||
getGridSnapping () { return false; },
|
||||
getDrawing () {
|
||||
return {
|
||||
getNextId () { return '' + elemId++; }
|
||||
};
|
||||
utilities.init(
|
||||
/**
|
||||
* @implements {module:utilities.EditorContext}
|
||||
*/
|
||||
{
|
||||
getSVGRoot () { return svg; },
|
||||
getDOMDocument () { return null; },
|
||||
getDOMContainer () { return null; }
|
||||
}
|
||||
});
|
||||
);
|
||||
coords.init(
|
||||
/**
|
||||
* @implements {module:coords.EditorContext}
|
||||
*/
|
||||
{
|
||||
getGridSnapping () { return false; },
|
||||
getDrawing () {
|
||||
return {
|
||||
getNextId () { return '' + elemId++; }
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function tearDown () {
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css"/>
|
||||
<script src="../editor/jquery.min.js"></script>
|
||||
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script src="../node_modules/sinon/pkg/sinon-no-sourcemaps.js"></script>
|
||||
<script src="../node_modules/sinon-test/dist/sinon-test.js"></script>
|
||||
<script type="module" src="draw_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
/* globals sinon, sinonTest */
|
||||
/* eslint-env qunit */
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as draw from '../editor/draw.js';
|
||||
import * as units from '../editor/units.js';
|
||||
|
||||
import sinon from '../node_modules/sinon/pkg/sinon-esm.js';
|
||||
import sinonTest from '../node_modules/sinon-test/dist/sinon-test-es.js';
|
||||
import sinonQunit from './sinon/sinon-qunit.js';
|
||||
|
||||
sinon.test = sinonTest(sinon, {
|
||||
@@ -46,10 +48,15 @@ const svgN = document.createElementNS(NS.SVG, 'svg');
|
||||
svgN.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
|
||||
svgN.setAttributeNS(NS.SE, 'se:nonce', NONCE);
|
||||
|
||||
units.init({
|
||||
// used by units.shortFloat - call path: cloneLayer -> copyElem -> convertPath -> pathDSegment -> shortFloat
|
||||
getRoundDigits () { return 3; }
|
||||
});
|
||||
units.init(
|
||||
/**
|
||||
* @implements {module:units.ElementContainer}
|
||||
*/
|
||||
{
|
||||
// used by units.shortFloat - call path: cloneLayer -> copyElem -> convertPath -> pathDSegment -> shortFloat
|
||||
getRoundDigits () { return 3; }
|
||||
}
|
||||
);
|
||||
|
||||
// Simplifying from svgcanvas.js usage
|
||||
const idprefix = 'svg_';
|
||||
@@ -60,10 +67,15 @@ const getCurrentDrawing = function () {
|
||||
};
|
||||
const setCurrentGroup = (cg) => {
|
||||
};
|
||||
draw.init({
|
||||
getCurrentDrawing,
|
||||
setCurrentGroup
|
||||
});
|
||||
draw.init(
|
||||
/**
|
||||
* @implements {module:draw.DrawCanvasInit}
|
||||
*/
|
||||
{
|
||||
getCurrentDrawing,
|
||||
setCurrentGroup
|
||||
}
|
||||
);
|
||||
|
||||
function createSVGElement (jsonMap) {
|
||||
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
|
||||
@@ -73,7 +85,7 @@ function createSVGElement (jsonMap) {
|
||||
return elem;
|
||||
}
|
||||
|
||||
const setupSvgWith3Layers = function (svgElem) {
|
||||
const setupSVGWith3Layers = function (svgElem) {
|
||||
const layer1 = document.createElementNS(NS.SVG, 'g');
|
||||
const layer1Title = document.createElementNS(NS.SVG, 'title');
|
||||
layer1Title.append(document.createTextNode(LAYER1));
|
||||
@@ -127,7 +139,7 @@ const createSomeElementsInGroup = function (group) {
|
||||
return 4;
|
||||
};
|
||||
|
||||
const cleanupSvg = function (svgElem) {
|
||||
const cleanupSVG = function (svgElem) {
|
||||
while (svgElem.firstChild) { svgElem.firstChild.remove(); }
|
||||
};
|
||||
|
||||
@@ -207,7 +219,7 @@ QUnit.test('Test getId() and getNextId() without nonce', function (assert) {
|
||||
assert.equal(doc.getNextId(), 'svg_4');
|
||||
assert.equal(doc.getId(), 'svg_4');
|
||||
// clean out svg document
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getId() and getNextId() with prefix without nonce', function (assert) {
|
||||
@@ -227,7 +239,7 @@ QUnit.test('Test getId() and getNextId() with prefix without nonce', function (a
|
||||
assert.equal(doc.getNextId(), prefix + '3');
|
||||
assert.equal(doc.getId(), prefix + '3');
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getId() and getNextId() with nonce', function (assert) {
|
||||
@@ -252,7 +264,7 @@ QUnit.test('Test getId() and getNextId() with nonce', function (assert) {
|
||||
assert.equal(doc.getNextId(), prefix + '_4');
|
||||
assert.equal(doc.getId(), prefix + '_4');
|
||||
|
||||
cleanupSvg(svgN);
|
||||
cleanupSVG(svgN);
|
||||
});
|
||||
|
||||
QUnit.test('Test getId() and getNextId() with prefix with nonce', function (assert) {
|
||||
@@ -273,7 +285,7 @@ QUnit.test('Test getId() and getNextId() with prefix with nonce', function (asse
|
||||
assert.equal(doc.getNextId(), prefix + '3');
|
||||
assert.equal(doc.getId(), prefix + '3');
|
||||
|
||||
cleanupSvg(svgN);
|
||||
cleanupSVG(svgN);
|
||||
});
|
||||
|
||||
QUnit.test('Test releaseId()', function (assert) {
|
||||
@@ -293,7 +305,7 @@ QUnit.test('Test releaseId()', function (assert) {
|
||||
assert.ok(doc.releaseId(firstId));
|
||||
assert.ok(!doc.releaseId(firstId));
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getNumLayers', function (assert) {
|
||||
@@ -302,18 +314,18 @@ QUnit.test('Test getNumLayers', function (assert) {
|
||||
assert.equal(typeof drawing.getNumLayers, typeof function () {});
|
||||
assert.equal(drawing.getNumLayers(), 0);
|
||||
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.equal(drawing.getNumLayers(), 3);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test hasLayer', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
const drawing = new draw.Drawing(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
@@ -324,7 +336,7 @@ QUnit.test('Test hasLayer', function (assert) {
|
||||
assert.ok(drawing.hasLayer(LAYER2));
|
||||
assert.ok(drawing.hasLayer(LAYER1));
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test identifyLayers() with empty document', function (assert) {
|
||||
@@ -352,14 +364,14 @@ QUnit.test('Test identifyLayers() with empty document', function (assert) {
|
||||
const firstChild = layerGroup.childNodes.item(0);
|
||||
assert.equal(firstChild.tagName, 'title');
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test identifyLayers() with some layers', function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
|
||||
assert.equal(svg.childNodes.length, 3);
|
||||
|
||||
@@ -374,13 +386,13 @@ QUnit.test('Test identifyLayers() with some layers', function (assert) {
|
||||
assert.equal(drawing.all_layers[1].getGroup().getAttribute('class'), LAYER_CLASS);
|
||||
assert.equal(drawing.all_layers[2].getGroup().getAttribute('class'), LAYER_CLASS);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test identifyLayers() with some layers and orphans', function (assert) {
|
||||
assert.expect(14);
|
||||
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
|
||||
const orphan1 = document.createElementNS(NS.SVG, 'rect');
|
||||
const orphan2 = document.createElementNS(NS.SVG, 'rect');
|
||||
@@ -408,14 +420,14 @@ QUnit.test('Test identifyLayers() with some layers and orphans', function (asser
|
||||
assert.equal(layer4.childNodes.item(1), orphan1);
|
||||
assert.equal(layer4.childNodes.item(2), orphan2);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getLayerName()', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
|
||||
drawing.identifyLayers();
|
||||
|
||||
@@ -424,14 +436,14 @@ QUnit.test('Test getLayerName()', function (assert) {
|
||||
assert.equal(drawing.getLayerName(1), LAYER2);
|
||||
assert.equal(drawing.getLayerName(2), LAYER3);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getCurrentLayer()', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.getCurrentLayer);
|
||||
@@ -439,14 +451,14 @@ QUnit.test('Test getCurrentLayer()', function (assert) {
|
||||
assert.ok(drawing.getCurrentLayer());
|
||||
assert.equal(drawing.getCurrentLayer(), drawing.all_layers[2].getGroup());
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test setCurrentLayer() and getCurrentLayerName()', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.setCurrentLayer);
|
||||
@@ -460,7 +472,7 @@ QUnit.test('Test setCurrentLayer() and getCurrentLayerName()', function (assert)
|
||||
assert.equal(drawing.getCurrentLayerName(), LAYER3);
|
||||
assert.equal(drawing.getCurrentLayer(), drawing.all_layers[2].getGroup());
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test setCurrentLayerName()', function (assert) {
|
||||
@@ -469,7 +481,7 @@ QUnit.test('Test setCurrentLayerName()', function (assert) {
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.setCurrentLayerName);
|
||||
@@ -490,7 +502,7 @@ QUnit.test('Test setCurrentLayerName()', function (assert) {
|
||||
assert.equal(oldName, mockHrService.changeElement.getCall(0).args[1]['#text']);
|
||||
assert.equal(newName, mockHrService.changeElement.getCall(0).args[0].textContent);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test createLayer()', function (assert) {
|
||||
@@ -503,7 +515,7 @@ QUnit.test('Test createLayer()', function (assert) {
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.createLayer);
|
||||
@@ -521,7 +533,7 @@ QUnit.test('Test createLayer()', function (assert) {
|
||||
assert.ok(mockHrService.startBatchCommand.calledOnce);
|
||||
assert.ok(mockHrService.endBatchCommand.calledOnce);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test mergeLayer()', function (assert) {
|
||||
@@ -533,7 +545,7 @@ QUnit.test('Test mergeLayer()', function (assert) {
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
const layers = setupSvgWith3Layers(svg);
|
||||
const layers = setupSVGWith3Layers(svg);
|
||||
const elementCount = createSomeElementsInGroup(layers[2]) + 1; // +1 for title element
|
||||
assert.equal(layers[1].childElementCount, 1);
|
||||
assert.equal(layers[2].childElementCount, elementCount);
|
||||
@@ -557,7 +569,7 @@ QUnit.test('Test mergeLayer()', function (assert) {
|
||||
assert.equal(mockHrService.moveElement.callCount, elementCount - 1); // -1 because the title was not moved.
|
||||
assert.equal(mockHrService.removeElement.callCount, 2); // remove group and title.
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test mergeLayer() when no previous layer to merge', function (assert) {
|
||||
@@ -569,7 +581,7 @@ QUnit.test('Test mergeLayer() when no previous layer to merge', function (assert
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
const layers = setupSvgWith3Layers(svg);
|
||||
const layers = setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
drawing.setCurrentLayer(LAYER1);
|
||||
assert.equal(drawing.getCurrentLayer(), layers[0]);
|
||||
@@ -589,7 +601,7 @@ QUnit.test('Test mergeLayer() when no previous layer to merge', function (assert
|
||||
assert.equal(mockHrService.moveElement.callCount, 0);
|
||||
assert.equal(mockHrService.removeElement.callCount, 0);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test mergeAllLayers()', function (assert) {
|
||||
@@ -601,7 +613,7 @@ QUnit.test('Test mergeAllLayers()', function (assert) {
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
const layers = setupSvgWith3Layers(svg);
|
||||
const layers = setupSVGWith3Layers(svg);
|
||||
const elementCount = createSomeElementsInGroup(layers[0]) + 1; // +1 for title element
|
||||
createSomeElementsInGroup(layers[1]);
|
||||
createSomeElementsInGroup(layers[2]);
|
||||
@@ -631,7 +643,7 @@ QUnit.test('Test mergeAllLayers()', function (assert) {
|
||||
assert.equal(mockHrService.moveElement.callCount, elementCount * 3 - 3);
|
||||
assert.equal(mockHrService.removeElement.callCount, 2 * 2); // remove group and title twice.
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test cloneLayer()', function (assert) {
|
||||
@@ -642,7 +654,7 @@ QUnit.test('Test cloneLayer()', function (assert) {
|
||||
};
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
const layers = setupSvgWith3Layers(svg);
|
||||
const layers = setupSVGWith3Layers(svg);
|
||||
const layer3 = layers[2];
|
||||
const elementCount = createSomeElementsInGroup(layer3) + 1; // +1 for title element
|
||||
assert.equal(layer3.childElementCount, elementCount);
|
||||
@@ -680,14 +692,14 @@ QUnit.test('Test cloneLayer()', function (assert) {
|
||||
assert.equal(g.childNodes.length, 1);
|
||||
assert.equal(g.id, 'svg_4');
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getLayerVisibility()', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.getLayerVisibility);
|
||||
@@ -696,14 +708,14 @@ QUnit.test('Test getLayerVisibility()', function (assert) {
|
||||
assert.ok(drawing.getLayerVisibility(LAYER2));
|
||||
assert.ok(drawing.getLayerVisibility(LAYER3));
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test setLayerVisibility()', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.setLayerVisibility);
|
||||
@@ -720,14 +732,14 @@ QUnit.test('Test setLayerVisibility()', function (assert) {
|
||||
drawing.setLayerVisibility(LAYER3, 'test-string');
|
||||
assert.ok(!drawing.getLayerVisibility(LAYER3));
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test getLayerOpacity()', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.getLayerOpacity);
|
||||
@@ -736,14 +748,14 @@ QUnit.test('Test getLayerOpacity()', function (assert) {
|
||||
assert.strictEqual(drawing.getLayerOpacity(LAYER2), 1.0);
|
||||
assert.strictEqual(drawing.getLayerOpacity(LAYER3), 1.0);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test setLayerOpacity()', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
assert.ok(drawing.setLayerOpacity);
|
||||
@@ -761,14 +773,14 @@ QUnit.test('Test setLayerOpacity()', function (assert) {
|
||||
drawing.setLayerOpacity(LAYER3, 100);
|
||||
assert.strictEqual(drawing.getLayerOpacity(LAYER3), 1.0);
|
||||
|
||||
cleanupSvg(svg);
|
||||
cleanupSVG(svg);
|
||||
});
|
||||
|
||||
QUnit.test('Test deleteCurrentLayer()', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const drawing = new draw.Drawing(svg);
|
||||
setupSvgWith3Layers(svg);
|
||||
setupSVGWith3Layers(svg);
|
||||
drawing.identifyLayers();
|
||||
|
||||
drawing.setCurrentLayer(LAYER2);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* eslint-env qunit */
|
||||
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as transformlist from '../editor/svgtransformlist.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as history from '../editor/history.js';
|
||||
|
||||
// TODO(codedread): Write tests for handling history events.
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Unit Tests for jquery-svg.js</title>
|
||||
<title>Unit Tests for jQuery.attr.js</title>
|
||||
<link rel="icon" type="image/png" href="../editor/images/logo.png"/>
|
||||
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css"/>
|
||||
<script src="../editor/jquery.min.js"></script>
|
||||
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script type="module" src="jquery-svg_test.js"></script>
|
||||
<script type="module" src="jQuery.attr_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Unit Tests for jquery-svg</h1>
|
||||
<h1 id="qunit-header">Unit Tests for jQuery.attr</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-env qunit */
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as math from '../editor/math.js';
|
||||
|
||||
// log function
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-env qunit */
|
||||
import '../editor/pathseg.js';
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import '../editor/svgpathseg.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as pathModule from '../editor/path.js';
|
||||
|
||||
// log function
|
||||
@@ -11,17 +11,32 @@ QUnit.log((details) => {
|
||||
}
|
||||
});
|
||||
|
||||
function getMockContext (svg) {
|
||||
/**
|
||||
* @param {SVGSVGElement} [svg]
|
||||
* @returns {Array}
|
||||
*/
|
||||
function getMockContexts (svg) {
|
||||
svg = svg || document.createElementNS(NS.SVG, 'svg');
|
||||
const selectorParentGroup = document.createElementNS(NS.SVG, 'g');
|
||||
selectorParentGroup.setAttribute('id', 'selectorParentGroup');
|
||||
svg.append(selectorParentGroup);
|
||||
return {
|
||||
getDOMDocument () { return svg; },
|
||||
getDOMContainer () { return svg; },
|
||||
getSVGRoot () { return svg; },
|
||||
getCurrentZoom () { return 1; }
|
||||
};
|
||||
return [
|
||||
/**
|
||||
* @implements {module:path.EditorContext}
|
||||
*/
|
||||
{
|
||||
getSVGRoot () { return svg; },
|
||||
getCurrentZoom () { return 1; }
|
||||
},
|
||||
/**
|
||||
* @implements {module:utilities.EditorContext}
|
||||
*/
|
||||
{
|
||||
getDOMDocument () { return svg; },
|
||||
getDOMContainer () { return svg; },
|
||||
getSVGRoot () { return svg; }
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
QUnit.test('Test svgedit.path.replacePathSeg', function (assert) {
|
||||
@@ -30,9 +45,9 @@ QUnit.test('Test svgedit.path.replacePathSeg', function (assert) {
|
||||
const path = document.createElementNS(NS.SVG, 'path');
|
||||
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
||||
|
||||
const mockContext = getMockContext();
|
||||
pathModule.init(mockContext);
|
||||
utilities.init(mockContext);
|
||||
const [mockPathContext, mockUtilitiesContext] = getMockContexts();
|
||||
pathModule.init(mockPathContext);
|
||||
utilities.init(mockUtilitiesContext);
|
||||
new pathModule.Path(path); // eslint-disable-line no-new
|
||||
|
||||
assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
||||
@@ -52,9 +67,9 @@ QUnit.test('Test svgedit.path.Segment.setType simple', function (assert) {
|
||||
const path = document.createElementNS(NS.SVG, 'path');
|
||||
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
||||
|
||||
const mockContext = getMockContext();
|
||||
pathModule.init(mockContext);
|
||||
utilities.init(mockContext);
|
||||
const [mockPathContext, mockUtilitiesContext] = getMockContexts();
|
||||
pathModule.init(mockPathContext);
|
||||
utilities.init(mockUtilitiesContext);
|
||||
new pathModule.Path(path); // eslint-disable-line no-new
|
||||
|
||||
assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
||||
@@ -82,9 +97,9 @@ QUnit.test('Test svgedit.path.Segment.setType with control points', function (as
|
||||
path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z');
|
||||
svg.append(path);
|
||||
|
||||
const mockContext = getMockContext(svg);
|
||||
pathModule.init(mockContext);
|
||||
utilities.init(mockContext);
|
||||
const [mockPathContext, mockUtilitiesContext] = getMockContexts(svg);
|
||||
pathModule.init(mockPathContext);
|
||||
utilities.init(mockUtilitiesContext);
|
||||
const segment = new pathModule.Segment(1, path.pathSegList.getItem(1));
|
||||
segment.path = new pathModule.Path(path);
|
||||
|
||||
@@ -112,9 +127,9 @@ QUnit.test('Test svgedit.path.Segment.move', function (assert) {
|
||||
const path = document.createElementNS(NS.SVG, 'path');
|
||||
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
||||
|
||||
const mockContext = getMockContext();
|
||||
pathModule.init(mockContext);
|
||||
utilities.init(mockContext);
|
||||
const [mockPathContext, mockUtilitiesContext] = getMockContexts();
|
||||
pathModule.init(mockPathContext);
|
||||
utilities.init(mockUtilitiesContext);
|
||||
new pathModule.Path(path); // eslint-disable-line no-new
|
||||
|
||||
assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
||||
@@ -134,9 +149,9 @@ QUnit.test('Test svgedit.path.Segment.moveCtrl', function (assert) {
|
||||
const path = document.createElementNS(NS.SVG, 'path');
|
||||
path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z');
|
||||
|
||||
const mockContext = getMockContext();
|
||||
pathModule.init(mockContext);
|
||||
utilities.init(mockContext);
|
||||
const [mockPathContext, mockUtilitiesContext] = getMockContexts();
|
||||
pathModule.init(mockPathContext);
|
||||
utilities.init(mockUtilitiesContext);
|
||||
new pathModule.Path(path); // eslint-disable-line no-new
|
||||
|
||||
assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C');
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*
|
||||
* @example assert.close(3.141, Math.PI, 0.001);
|
||||
*
|
||||
* @param Number actual
|
||||
* @param Number expected
|
||||
* @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers)
|
||||
* @param String message (optional)
|
||||
* @param {Float} actual
|
||||
* @param {Float} expected
|
||||
* @param {Float} maxDifference (the maximum inclusive difference allowed between the actual and expected numbers)
|
||||
* @param {string} [message] Defaults to structured message
|
||||
*/
|
||||
function close (actual, expected, maxDifference, message) {
|
||||
const actualDiff = (actual === expected) ? 0 : Math.abs(actual - expected),
|
||||
@@ -22,10 +22,10 @@ function close (actual, expected, maxDifference, message) {
|
||||
*
|
||||
* @example assert.close.percent(155, 150, 3.4); // Difference is ~3.33%
|
||||
*
|
||||
* @param Number actual
|
||||
* @param Number expected
|
||||
* @param Number maxPercentDifference (the maximum inclusive difference percentage allowed between the actual and expected numbers)
|
||||
* @param String message (optional)
|
||||
* @param {Float} actual
|
||||
* @param {Float} expected
|
||||
* @param {Float} maxPercentDifference (the maximum inclusive difference percentage allowed between the actual and expected numbers)
|
||||
* @param {string} [message] Defaults to a structured message
|
||||
*/
|
||||
function closePercent (actual, expected, maxPercentDifference, message) {
|
||||
let actualDiff, result;
|
||||
@@ -51,10 +51,10 @@ function closePercent (actual, expected, maxPercentDifference, message) {
|
||||
*
|
||||
* @example assert.notClose(3.1, Math.PI, 0.001);
|
||||
*
|
||||
* @param Number actual
|
||||
* @param Number expected
|
||||
* @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers)
|
||||
* @param String message (optional)
|
||||
* @param {Float} actual
|
||||
* @param {Float} expected
|
||||
* @param {Float} minDifference (the minimum exclusive difference allowed between the actual and expected numbers)
|
||||
* @param {string} [message] Defaults to structured message
|
||||
*/
|
||||
function notClose (actual, expected, minDifference, message) {
|
||||
const actualDiff = Math.abs(actual - expected),
|
||||
@@ -69,10 +69,10 @@ function notClose (actual, expected, minDifference, message) {
|
||||
*
|
||||
* @example assert.notClose.percent(156, 150, 3.5); // Difference is 4.0%
|
||||
*
|
||||
* @param Number actual
|
||||
* @param Number expected
|
||||
* @param Number minPercentDifference (the minimum exclusive difference percentage allowed between the actual and expected numbers)
|
||||
* @param String message (optional)
|
||||
* @param {Float} actual
|
||||
* @param {Float} expected
|
||||
* @param {Float} minPercentDifference (the minimum exclusive difference percentage allowed between the actual and expected numbers)
|
||||
* @param {string} [message] Defaults to a structured message
|
||||
*/
|
||||
function notClosePercent (actual, expected, minPercentDifference, message) {
|
||||
let actualDiff, result;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<script type="module" src="recalculate_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Unit Tests for svgedit.recalculate</h1>
|
||||
<h1 id="qunit-header">Unit Tests for recalculate</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-env qunit */
|
||||
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as coords from '../editor/coords.js';
|
||||
import * as recalculate from '../editor/recalculate.js';
|
||||
|
||||
@@ -21,24 +21,39 @@ svgroot.append(svg);
|
||||
|
||||
let elemId = 1;
|
||||
function setUp () {
|
||||
utilities.init({
|
||||
getSVGRoot () { return svg; },
|
||||
getDOMDocument () { return null; },
|
||||
getDOMContainer () { return null; }
|
||||
});
|
||||
coords.init({
|
||||
getGridSnapping () { return false; },
|
||||
getDrawing () {
|
||||
return {
|
||||
getNextId () { return '' + elemId++; }
|
||||
};
|
||||
utilities.init(
|
||||
/**
|
||||
* @implements {module:utilities.EditorContext}
|
||||
*/
|
||||
{
|
||||
getSVGRoot () { return svg; },
|
||||
getDOMDocument () { return null; },
|
||||
getDOMContainer () { return null; }
|
||||
}
|
||||
});
|
||||
recalculate.init({
|
||||
getSVGRoot () { return svg; },
|
||||
getStartTransform () { return ''; },
|
||||
setStartTransform () {}
|
||||
});
|
||||
);
|
||||
coords.init(
|
||||
/**
|
||||
* @implements {module:coords.EditorContext}
|
||||
*/
|
||||
{
|
||||
getGridSnapping () { return false; },
|
||||
getDrawing () {
|
||||
return {
|
||||
getNextId () { return '' + elemId++; }
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
recalculate.init(
|
||||
/**
|
||||
* @implements {module:recalculate.EditorContext}
|
||||
*/
|
||||
{
|
||||
getSVGRoot () { return svg; },
|
||||
getStartTransform () { return ''; },
|
||||
setStartTransform () {}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
let elem;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-env qunit */
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as sanitize from '../editor/sanitize.js';
|
||||
|
||||
// log function
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-env qunit */
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as select from '../editor/select.js';
|
||||
|
||||
// log function
|
||||
@@ -17,6 +17,10 @@ let svgcontent;
|
||||
const mockConfig = {
|
||||
dimensions: [640, 480]
|
||||
};
|
||||
|
||||
/**
|
||||
* @implements {module:select.SVGFactory}
|
||||
*/
|
||||
const mockFactory = {
|
||||
createSVGElement (jsonMap) {
|
||||
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env qunit */
|
||||
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as transformlist from '../editor/svgtransformlist.js';
|
||||
import {disableSupportsNativeTransformLists} from '../editor/browser.js';
|
||||
import almostEqualsPlugin from './qunit/qunit-assert-almostEquals.js';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env qunit */
|
||||
|
||||
import '../editor/pathseg.js';
|
||||
import '../editor/svgpathseg.js';
|
||||
import SvgCanvas from '../editor/svgcanvas.js';
|
||||
|
||||
// log function
|
||||
|
||||
@@ -9,13 +9,18 @@ QUnit.log((details) => {
|
||||
});
|
||||
|
||||
function setUp () {
|
||||
units.init({
|
||||
getBaseUnit () { return 'cm'; },
|
||||
getHeight () { return 600; },
|
||||
getWidth () { return 800; },
|
||||
getRoundDigits () { return 4; },
|
||||
getElement (elementId) { return document.getElementById(elementId); }
|
||||
});
|
||||
units.init(
|
||||
/**
|
||||
* @implements {module:units.ElementContainer}
|
||||
*/
|
||||
{
|
||||
getBaseUnit () { return 'cm'; },
|
||||
getHeight () { return 600; },
|
||||
getWidth () { return 800; },
|
||||
getRoundDigits () { return 4; },
|
||||
getElement (elementId) { return document.getElementById(elementId); }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
QUnit.test('Test svgedit.units package', function (assert) {
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Unit Tests for svgutils.js BBox functions</title>
|
||||
<title>Unit Tests for utilities.js BBox functions</title>
|
||||
<link rel="icon" type="image/png" href="../editor/images/logo.png"/>
|
||||
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css"/>
|
||||
<script src="../editor/jquery.min.js"></script>
|
||||
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script type="module" src="svgutils_bbox_test.js"></script>
|
||||
<script type="module" src="utilities_bbox_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Unit Tests for svgutils.js BBox functions</h1>
|
||||
<h1 id="qunit-header">Unit Tests for utilities.js BBox functions</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-env qunit */
|
||||
import '../editor/pathseg.js';
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import '../editor/svgpathseg.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as transformlist from '../editor/svgtransformlist.js';
|
||||
import * as math from '../editor/math.js';
|
||||
import * as path from '../editor/path.js';
|
||||
@@ -23,11 +23,11 @@ function mockCreateSVGElement (jsonMap) {
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
let mockAddSvgElementFromJsonCallCount = 0;
|
||||
function mockAddSvgElementFromJson (json) {
|
||||
let mockaddSVGElementFromJsonCallCount = 0;
|
||||
function mockaddSVGElementFromJson (json) {
|
||||
const elem = mockCreateSVGElement(json);
|
||||
svgroot.append(elem);
|
||||
mockAddSvgElementFromJsonCallCount++;
|
||||
mockaddSVGElementFromJsonCallCount++;
|
||||
return elem;
|
||||
}
|
||||
const mockPathActions = {
|
||||
@@ -74,7 +74,7 @@ QUnit.module('svgedit.utilities_bbox', {
|
||||
// We're reusing ID's so we need to do this for transforms.
|
||||
transformlist.resetListMap();
|
||||
path.init(null);
|
||||
mockAddSvgElementFromJsonCallCount = 0;
|
||||
mockaddSVGElementFromJsonCallCount = 0;
|
||||
},
|
||||
afterEach () {
|
||||
}
|
||||
@@ -96,9 +96,9 @@ QUnit.test('Test getBBoxWithTransform and no transform', function (assert) {
|
||||
attr: {id: 'path', d: 'M0,1 L2,3'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2});
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
elem.remove();
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
@@ -106,9 +106,9 @@ QUnit.test('Test getBBoxWithTransform and no transform', function (assert) {
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
elem.remove();
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
@@ -116,9 +116,9 @@ QUnit.test('Test getBBoxWithTransform and no transform', function (assert) {
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
elem.remove();
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
@@ -131,9 +131,9 @@ QUnit.test('Test getBBoxWithTransform and no transform', function (assert) {
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
g.remove();
|
||||
});
|
||||
|
||||
@@ -145,7 +145,7 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
|
||||
attr: {id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10)'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, 10, EPSILON);
|
||||
assert.close(bbox.y, 10, EPSILON);
|
||||
assert.close(bbox.width, 0, EPSILON);
|
||||
@@ -157,12 +157,12 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
|
||||
attr: {id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20)'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, 5, EPSILON);
|
||||
assert.close(bbox.y, 15, EPSILON);
|
||||
assert.close(bbox.width, 20, EPSILON);
|
||||
assert.close(bbox.height, 10, EPSILON);
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 1);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 1);
|
||||
elem.remove();
|
||||
|
||||
const rect = {x: 10, y: 10, width: 10, height: 20};
|
||||
@@ -173,14 +173,14 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
|
||||
attr: {id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
mockAddSvgElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
mockaddSVGElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
const r2 = rotateRect(rect, angle, origin);
|
||||
assert.close(bbox.x, r2.x, EPSILON, 'rect2 x is ' + r2.x);
|
||||
assert.close(bbox.y, r2.y, EPSILON, 'rect2 y is ' + r2.y);
|
||||
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
|
||||
assert.close(bbox.height, r2.height, EPSILON, 'rect2 height is ' + r2.height);
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
elem.remove();
|
||||
|
||||
// Same as previous but wrapped with g and the transform is with the g.
|
||||
@@ -194,13 +194,13 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
mockAddSvgElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(g, mockAddSvgElementFromJson, mockPathActions);
|
||||
mockaddSVGElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(g, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, r2.x, EPSILON, 'rect2 x is ' + r2.x);
|
||||
assert.close(bbox.y, r2.y, EPSILON, 'rect2 y is ' + r2.y);
|
||||
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
|
||||
assert.close(bbox.height, r2.height, EPSILON, 'rect2 height is ' + r2.height);
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 0);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 0);
|
||||
g.remove();
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
@@ -208,14 +208,14 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
|
||||
attr: {id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100)'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
mockAddSvgElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
mockaddSVGElementFromJsonCallCount = 0;
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
// TODO: the BBox algorithm is using the bezier control points to calculate the bounding box. Should be 50, 50, 100, 100.
|
||||
assert.ok(bbox.x > 45 && bbox.x <= 50);
|
||||
assert.ok(bbox.y > 45 && bbox.y <= 50);
|
||||
assert.ok(bbox.width >= 100 && bbox.width < 110);
|
||||
assert.ok(bbox.height >= 100 && bbox.height < 110);
|
||||
assert.equal(mockAddSvgElementFromJsonCallCount, 1);
|
||||
assert.equal(mockaddSVGElementFromJsonCallCount, 1);
|
||||
elem.remove();
|
||||
});
|
||||
|
||||
@@ -232,7 +232,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
|
||||
attr: {id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10) ' + matrix}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, 10 + tx, EPSILON);
|
||||
assert.close(bbox.y, 10 + ty, EPSILON);
|
||||
assert.close(bbox.width, 0, EPSILON);
|
||||
@@ -247,7 +247,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
|
||||
attr: {id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20) ' + matrix}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, 5 + tx, EPSILON);
|
||||
assert.close(bbox.y, 15 + ty, EPSILON);
|
||||
assert.close(bbox.width, 20, EPSILON);
|
||||
@@ -267,7 +267,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
|
||||
attr: {id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ') ' + matrix}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
const r2 = rotateRect(rect, angle, origin);
|
||||
assert.close(bbox.x, r2.x + tx, EPSILON, 'rect2 x is ' + r2.x);
|
||||
assert.close(bbox.y, r2.y + ty, EPSILON, 'rect2 y is ' + r2.y);
|
||||
@@ -286,7 +286,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
bbox = getBBoxWithTransform(g, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(g, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.close(bbox.x, r2.x + tx, EPSILON, 'rect2 x is ' + r2.x);
|
||||
assert.close(bbox.y, r2.y + ty, EPSILON, 'rect2 y is ' + r2.y);
|
||||
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
|
||||
@@ -298,7 +298,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
|
||||
attr: {id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100) ' + matrix}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxWithTransform(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
// TODO: the BBox algorithm is using the bezier control points to calculate the bounding box. Should be 50, 50, 100, 100.
|
||||
assert.ok(bbox.x > 45 + tx && bbox.x <= 50 + tx);
|
||||
assert.ok(bbox.y > 45 + ty && bbox.y <= 50 + ty);
|
||||
@@ -316,7 +316,7 @@ QUnit.test('Test getStrokedBBox with stroke-width 10', function (assert) {
|
||||
attr: {id: 'path', d: 'M0,1 L2,3', 'stroke-width': strokeWidth}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 2 + strokeWidth, height: 2 + strokeWidth});
|
||||
elem.remove();
|
||||
|
||||
@@ -325,7 +325,7 @@ QUnit.test('Test getStrokedBBox with stroke-width 10', function (assert) {
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth});
|
||||
elem.remove();
|
||||
|
||||
@@ -334,7 +334,7 @@ QUnit.test('Test getStrokedBBox with stroke-width 10', function (assert) {
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': strokeWidth}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 5 + strokeWidth});
|
||||
elem.remove();
|
||||
|
||||
@@ -348,7 +348,7 @@ QUnit.test('Test getStrokedBBox with stroke-width 10', function (assert) {
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth});
|
||||
g.remove();
|
||||
});
|
||||
@@ -361,7 +361,7 @@ QUnit.test("Test getStrokedBBox with stroke-width 'none'", function (assert) {
|
||||
attr: {id: 'path', d: 'M0,1 L2,3', 'stroke-width': 'none'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2});
|
||||
elem.remove();
|
||||
|
||||
@@ -370,7 +370,7 @@ QUnit.test("Test getStrokedBBox with stroke-width 'none'", function (assert) {
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
elem.remove();
|
||||
|
||||
@@ -379,7 +379,7 @@ QUnit.test("Test getStrokedBBox with stroke-width 'none'", function (assert) {
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': 'none'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
elem.remove();
|
||||
|
||||
@@ -393,7 +393,7 @@ QUnit.test("Test getStrokedBBox with stroke-width 'none'", function (assert) {
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
g.remove();
|
||||
});
|
||||
@@ -406,7 +406,7 @@ QUnit.test('Test getStrokedBBox with no stroke-width attribute', function (asser
|
||||
attr: {id: 'path', d: 'M0,1 L2,3'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2});
|
||||
elem.remove();
|
||||
|
||||
@@ -415,7 +415,7 @@ QUnit.test('Test getStrokedBBox with no stroke-width attribute', function (asser
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
elem.remove();
|
||||
|
||||
@@ -424,7 +424,7 @@ QUnit.test('Test getStrokedBBox with no stroke-width attribute', function (asser
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
elem.remove();
|
||||
|
||||
@@ -438,7 +438,7 @@ QUnit.test('Test getStrokedBBox with no stroke-width attribute', function (asser
|
||||
});
|
||||
g.append(elem);
|
||||
svgroot.append(g);
|
||||
bbox = getStrokedBBox([elem], mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
g.remove();
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge, chrome=1"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||
<title>Performance Unit Tests for svgutils.js</title>
|
||||
<title>Performance Unit Tests for utilities.js</title>
|
||||
|
||||
<link rel="icon" type="image/png" href="../editor/images/logo.png"/>
|
||||
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css"/>
|
||||
@@ -19,10 +19,10 @@
|
||||
</style>
|
||||
<script src="../editor/jquery.min.js"></script>
|
||||
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script type="module" src="svgutils_performance_test.js"></script>
|
||||
<script type="module" src="utilities_performance_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Performance Unit Tests for svgutils.js</h1>
|
||||
<h1 id="qunit-header">Performance Unit Tests for utilities.js</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-env qunit */
|
||||
import '../editor/pathseg.js';
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import '../editor/svgpathseg.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as transformlist from '../editor/svgtransformlist.js';
|
||||
import * as math from '../editor/math.js';
|
||||
|
||||
@@ -21,7 +21,7 @@ function mockCreateSVGElement (jsonMap) {
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
function mockAddSvgElementFromJson (json) {
|
||||
function mockaddSVGElementFromJson (json) {
|
||||
const elem = mockCreateSVGElement(json);
|
||||
currentLayer.append(elem);
|
||||
return elem;
|
||||
@@ -131,7 +131,7 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
|
||||
// Skip the first child which is the title.
|
||||
for (let index = 1; index < count; index++) {
|
||||
const child = children[index];
|
||||
/* const obj = */ getStrokedBBox([child], mockAddSvgElementFromJson, mockPathActions);
|
||||
/* const obj = */ getStrokedBBox([child], mockaddSVGElementFromJson, mockPathActions);
|
||||
now = Date.now(); const delta = now - lastTime; lastTime = now;
|
||||
total += delta;
|
||||
min = Math.min(min, delta);
|
||||
@@ -150,7 +150,7 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
|
||||
// Skip the first child which is the title.
|
||||
for (let index = 1; index < count; index++) {
|
||||
const child = children[index];
|
||||
/* const obj = */ getStrokedBBox([child], mockAddSvgElementFromJson, mockPathActions);
|
||||
/* const obj = */ getStrokedBBox([child], mockaddSVGElementFromJson, mockPathActions);
|
||||
now = Date.now(); const delta = now - lastTime; lastTime = now;
|
||||
total += delta;
|
||||
min = Math.min(min, delta);
|
||||
@@ -2,15 +2,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Unit Tests for svgutils.js</title>
|
||||
<title>Unit Tests for utilities.js</title>
|
||||
<link rel="icon" type="image/png" href="../editor/images/logo.png"/>
|
||||
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css"/>
|
||||
<script src="../editor/jquery.min.js"></script>
|
||||
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script type="module" src="svgutils_test.js"></script>
|
||||
<script type="module" src="utilities_test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Unit Tests for svgutils.js</h1>
|
||||
<h1 id="qunit-header">Unit Tests for utilities.js</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-env qunit */
|
||||
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import {NS} from '../editor/namespaces.js';
|
||||
import * as utilities from '../editor/utilities.js';
|
||||
import * as browser from '../editor/browser.js';
|
||||
|
||||
// log function
|
||||
@@ -18,7 +18,7 @@ function mockCreateSVGElement (jsonMap) {
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
function mockAddSvgElementFromJson (json) {
|
||||
function mockaddSVGElementFromJson (json) {
|
||||
const elem = mockCreateSVGElement(json);
|
||||
svgroot.append(elem);
|
||||
return elem;
|
||||
@@ -259,8 +259,8 @@ QUnit.test('Test getPathDFromElement', function (assert) {
|
||||
});
|
||||
|
||||
QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
|
||||
function getBBoxOfElementAsPath (elem, addSvgElementFromJson, pathActions) {
|
||||
const bbox = utilities.getBBoxOfElementAsPath(elem, addSvgElementFromJson, pathActions);
|
||||
function getBBoxOfElementAsPath (elem, addSVGElementFromJson, pathActions) {
|
||||
const bbox = utilities.getBBoxOfElementAsPath(elem, addSVGElementFromJson, pathActions);
|
||||
return utilities.bboxToObj(bbox); // need this for assert.equal() to work.
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
|
||||
attr: {id: 'path', d: 'M0,1 Z'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
let bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
let bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 0, height: 0});
|
||||
elem.remove();
|
||||
|
||||
@@ -278,7 +278,7 @@ QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
elem.remove();
|
||||
|
||||
@@ -287,7 +287,7 @@ QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
elem.remove();
|
||||
|
||||
@@ -308,7 +308,7 @@ QUnit.test('Test convertToPath rect', function (assert) {
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.append(elem);
|
||||
const path = convertToPath(elem, attrs, mockAddSvgElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
const path = convertToPath(elem, attrs, mockaddSVGElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
assert.equal(path.getAttribute('d'), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z');
|
||||
assert.equal(path.getAttribute('visibilituy'), null);
|
||||
assert.equal(path.id, 'rect');
|
||||
@@ -336,7 +336,7 @@ QUnit.test('Test convertToPath unknown element', function (assert) {
|
||||
getAttribute (attr) { return ''; },
|
||||
parentNode: svgroot
|
||||
};
|
||||
const path = convertToPath(elem, attrs, mockAddSvgElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
const path = convertToPath(elem, attrs, mockaddSVGElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
assert.equal(path, null);
|
||||
assert.equal(elem.parentNode, svgroot);
|
||||
assert.equal(mockHistorySubCommands.length, 0);
|
||||
Reference in New Issue
Block a user