- Breaking change: Rename config file to svgedit-config-iife.js (or for the module version, svgedit-config-es.js);
also expect one directory higher; incorporates #207 (@iuyiuy) - Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons) - Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for better namespacing); incorporates #207 (@iuyiuy) - Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine) - Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed - Fix: Update Atom feed reference in HTML - Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes - Enhancement: Move config-sample.js out of `editor` directory - Enhancement: For `callback`-style extensions, also provide config object; add following to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml - Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel; make Node build routine for converting modular source to non-modular, use `loadStylesheets` for modular stylehsheet defining (but parallel loading); - Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default). - Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines - Refactoring: Avoid embedded API adding inline JavaScript listener - Refactoring: Move layers and context code to `draw.js` - Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js` - Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing) - Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency - Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules - Refactoring: Further avoidance of quotes on properties (as possible) - Refactoring: Use `class` in place of functions where intended as classes - Refactoring: Consistency and granularity in extensions imports - Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions - Testing: Add node-static for automating (and accessing out-of-directory contents) - Testing: Avoid HTML attributes for styling - Testing: Add npm `test` script - Testing: Comment out unused jQuery SVG test - Testing: Add test1 and svgutils_performance_test to all tests page - Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class - npm: Update devDeps - npm: Add html modules and config build to test script
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
/* eslint-env qunit */
|
||||
/* globals svgedit, equals */
|
||||
|
||||
import {NS} from '../editor/svgedit.js';
|
||||
import * as utilities from '../editor/svgutils.js';
|
||||
import * as browser from '../editor/browser.js';
|
||||
|
||||
// log function
|
||||
QUnit.log = function (details) {
|
||||
QUnit.log(function (details) {
|
||||
if (window.console && window.console.log) {
|
||||
window.console.log(details.result + ' :: ' + details.message);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function mockCreateSVGElement (jsonMap) {
|
||||
const elem = document.createElementNS(svgedit.NS.SVG, jsonMap['element']);
|
||||
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
|
||||
for (const attr in jsonMap['attr']) {
|
||||
elem.setAttribute(attr, jsonMap['attr'][attr]);
|
||||
}
|
||||
@@ -23,18 +26,24 @@ function mockAddSvgElementFromJson (json) {
|
||||
const mockPathActions = {resetOrientation () {}};
|
||||
let mockHistorySubCommands = [];
|
||||
const mockHistory = {
|
||||
BatchCommand () {
|
||||
return {
|
||||
addSubCommand (cmd) { mockHistorySubCommands.push(cmd); }
|
||||
};
|
||||
BatchCommand: class {
|
||||
constructor () {
|
||||
return {
|
||||
addSubCommand (cmd) { mockHistorySubCommands.push(cmd); }
|
||||
};
|
||||
}
|
||||
},
|
||||
RemoveElementCommand (elem, nextSibling, parent) {
|
||||
this.elem = elem;
|
||||
this.nextSibling = nextSibling;
|
||||
this.parent = parent;
|
||||
RemoveElementCommand: class {
|
||||
constructor (elem, nextSibling, parent) { // Longhand needed since used as a constructor
|
||||
this.elem = elem;
|
||||
this.nextSibling = nextSibling;
|
||||
this.parent = parent;
|
||||
}
|
||||
},
|
||||
InsertElementCommand (path) {
|
||||
this.path = path;
|
||||
InsertElementCommand: class {
|
||||
constructor (path) { // Longhand needed since used as a constructor
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
};
|
||||
const mockCount = {
|
||||
@@ -46,88 +55,88 @@ function mockClearSelection () { mockCount.clearSelection++; }
|
||||
function mockAddToSelection () { mockCount.addToSelection++; }
|
||||
function mockAddCommandToHistory () { mockCount.addCommandToHistory++; }
|
||||
|
||||
const svg = document.createElementNS(svgedit.NS.SVG, 'svg');
|
||||
const svg = document.createElementNS(NS.SVG, 'svg');
|
||||
const sandbox = document.getElementById('sandbox');
|
||||
const svgroot = mockCreateSVGElement({
|
||||
'element': 'svg',
|
||||
'attr': {'id': 'svgroot'}
|
||||
element: 'svg',
|
||||
attr: {id: 'svgroot'}
|
||||
});
|
||||
sandbox.appendChild(svgroot);
|
||||
|
||||
module('svgedit.utilities', {
|
||||
setup () {
|
||||
QUnit.module('svgedit.utilities', {
|
||||
beforeEach () {
|
||||
mockHistorySubCommands = [];
|
||||
mockCount.clearSelection = 0;
|
||||
mockCount.addToSelection = 0;
|
||||
mockCount.addCommandToHistory = 0;
|
||||
},
|
||||
teardown () {
|
||||
afterEach () {
|
||||
}
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities package', function () {
|
||||
expect(3);
|
||||
QUnit.test('Test svgedit.utilities package', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
ok(svgedit.utilities);
|
||||
ok(svgedit.utilities.toXml);
|
||||
equals(typeof svgedit.utilities.toXml, typeof function () {});
|
||||
assert.ok(utilities);
|
||||
assert.ok(utilities.toXml);
|
||||
assert.equal(typeof utilities.toXml, typeof function () {});
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.toXml() function', function () {
|
||||
expect(6);
|
||||
const {toXml} = svgedit.utilities;
|
||||
QUnit.test('Test svgedit.utilities.toXml() function', function (assert) {
|
||||
assert.expect(6);
|
||||
const {toXml} = utilities;
|
||||
|
||||
equals(toXml('a'), 'a');
|
||||
equals(toXml('ABC_'), 'ABC_');
|
||||
equals(toXml('PB&J'), 'PB&J');
|
||||
equals(toXml('2 < 5'), '2 < 5');
|
||||
equals(toXml('5 > 2'), '5 > 2');
|
||||
equals(toXml('\'<&>"'), ''<&>"');
|
||||
assert.equal(toXml('a'), 'a');
|
||||
assert.equal(toXml('ABC_'), 'ABC_');
|
||||
assert.equal(toXml('PB&J'), 'PB&J');
|
||||
assert.equal(toXml('2 < 5'), '2 < 5');
|
||||
assert.equal(toXml('5 > 2'), '5 > 2');
|
||||
assert.equal(toXml('\'<&>"'), ''<&>"');
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.fromXml() function', function () {
|
||||
expect(6);
|
||||
const {fromXml} = svgedit.utilities;
|
||||
QUnit.test('Test svgedit.utilities.fromXml() function', function (assert) {
|
||||
assert.expect(6);
|
||||
const {fromXml} = utilities;
|
||||
|
||||
equals(fromXml('a'), 'a');
|
||||
equals(fromXml('ABC_'), 'ABC_');
|
||||
equals(fromXml('PB&J'), 'PB&J');
|
||||
equals(fromXml('2 < 5'), '2 < 5');
|
||||
equals(fromXml('5 > 2'), '5 > 2');
|
||||
equals(fromXml('<&>'), '<&>');
|
||||
assert.equal(fromXml('a'), 'a');
|
||||
assert.equal(fromXml('ABC_'), 'ABC_');
|
||||
assert.equal(fromXml('PB&J'), 'PB&J');
|
||||
assert.equal(fromXml('2 < 5'), '2 < 5');
|
||||
assert.equal(fromXml('5 > 2'), '5 > 2');
|
||||
assert.equal(fromXml('<&>'), '<&>');
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.encode64() function', function () {
|
||||
expect(4);
|
||||
const {encode64} = svgedit.utilities;
|
||||
QUnit.test('Test svgedit.utilities.encode64() function', function (assert) {
|
||||
assert.expect(4);
|
||||
const {encode64} = utilities;
|
||||
|
||||
equals(encode64('abcdef'), 'YWJjZGVm');
|
||||
equals(encode64('12345'), 'MTIzNDU=');
|
||||
equals(encode64(' '), 'IA==');
|
||||
equals(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
|
||||
assert.equal(encode64('abcdef'), 'YWJjZGVm');
|
||||
assert.equal(encode64('12345'), 'MTIzNDU=');
|
||||
assert.equal(encode64(' '), 'IA==');
|
||||
assert.equal(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.decode64() function', function () {
|
||||
expect(4);
|
||||
const {decode64} = svgedit.utilities;
|
||||
QUnit.test('Test svgedit.utilities.decode64() function', function (assert) {
|
||||
assert.expect(4);
|
||||
const {decode64} = utilities;
|
||||
|
||||
equals(decode64('YWJjZGVm'), 'abcdef');
|
||||
equals(decode64('MTIzNDU='), '12345');
|
||||
equals(decode64('IA=='), ' ');
|
||||
equals(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
|
||||
assert.equal(decode64('YWJjZGVm'), 'abcdef');
|
||||
assert.equal(decode64('MTIzNDU='), '12345');
|
||||
assert.equal(decode64('IA=='), ' ');
|
||||
assert.equal(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.convertToXMLReferences() function', function () {
|
||||
expect(1);
|
||||
QUnit.test('Test svgedit.utilities.convertToXMLReferences() function', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const convert = svgedit.utilities.convertToXMLReferences;
|
||||
equals(convert('ABC'), 'ABC');
|
||||
// equals(convert('<27>BC'), 'ÀBC');
|
||||
const convert = utilities.convertToXMLReferences;
|
||||
assert.equal(convert('ABC'), 'ABC');
|
||||
// assert.equal(convert('<27>BC'), 'ÀBC');
|
||||
});
|
||||
|
||||
test('Test svgedit.utilities.bboxToObj() function', function () {
|
||||
expect(5);
|
||||
const {bboxToObj} = svgedit.utilities;
|
||||
QUnit.test('Test svgedit.utilities.bboxToObj() function', function (assert) {
|
||||
assert.expect(5);
|
||||
const {bboxToObj} = utilities;
|
||||
|
||||
const rect = svg.createSVGRect();
|
||||
rect.x = 1;
|
||||
@@ -136,185 +145,189 @@ test('Test svgedit.utilities.bboxToObj() function', function () {
|
||||
rect.height = 4;
|
||||
|
||||
const obj = bboxToObj(rect);
|
||||
equals(typeof obj, typeof {});
|
||||
equals(obj.x, 1);
|
||||
equals(obj.y, 2);
|
||||
equals(obj.width, 3);
|
||||
equals(obj.height, 4);
|
||||
assert.equal(typeof obj, typeof {});
|
||||
assert.equal(obj.x, 1);
|
||||
assert.equal(obj.y, 2);
|
||||
assert.equal(obj.width, 3);
|
||||
assert.equal(obj.height, 4);
|
||||
});
|
||||
|
||||
test('Test getUrlFromAttr', function () {
|
||||
expect(4);
|
||||
QUnit.test('Test getUrlFromAttr', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
equal(svgedit.utilities.getUrlFromAttr('url(#foo)'), '#foo');
|
||||
equal(svgedit.utilities.getUrlFromAttr('url(somefile.svg#foo)'), 'somefile.svg#foo');
|
||||
equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), '#foo');
|
||||
equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), '#foo');
|
||||
assert.equal(utilities.getUrlFromAttr('url(#foo)'), '#foo');
|
||||
assert.equal(utilities.getUrlFromAttr('url(somefile.svg#foo)'), 'somefile.svg#foo');
|
||||
assert.equal(utilities.getUrlFromAttr('url("#foo")'), '#foo');
|
||||
assert.equal(utilities.getUrlFromAttr('url("#foo")'), '#foo');
|
||||
});
|
||||
|
||||
test('Test getPathBBox', function () {
|
||||
if (svgedit.browser.supportsPathBBox()) return;
|
||||
const doc = svgedit.utilities.text2xml('<svg></svg>');
|
||||
const path = doc.createElementNS(svgedit.NS.SVG, 'path');
|
||||
QUnit.test('Test getPathBBox', function (assert) {
|
||||
if (browser.supportsPathBBox()) {
|
||||
assert.expect(0);
|
||||
return;
|
||||
}
|
||||
assert.expect(3);
|
||||
const doc = utilities.text2xml('<svg></svg>');
|
||||
const path = doc.createElementNS(NS.SVG, 'path');
|
||||
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
|
||||
const bb = svgedit.utilities.getPathBBox(path);
|
||||
equals(typeof bb, 'object', 'BBox returned object');
|
||||
ok(bb.x && !isNaN(bb.x));
|
||||
ok(bb.y && !isNaN(bb.y));
|
||||
const bb = utilities.getPathBBox(path);
|
||||
assert.equal(typeof bb, 'object', 'BBox returned object');
|
||||
assert.ok(bb.x && !isNaN(bb.x));
|
||||
assert.ok(bb.y && !isNaN(bb.y));
|
||||
});
|
||||
|
||||
test('Test getPathDFromSegments', function () {
|
||||
const {getPathDFromSegments} = svgedit.utilities;
|
||||
QUnit.test('Test getPathDFromSegments', function (assert) {
|
||||
const {getPathDFromSegments} = utilities;
|
||||
|
||||
const doc = svgedit.utilities.text2xml('<svg></svg>');
|
||||
const path = doc.createElementNS(svgedit.NS.SVG, 'path');
|
||||
const doc = utilities.text2xml('<svg></svg>');
|
||||
const path = doc.createElementNS(NS.SVG, 'path');
|
||||
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
|
||||
let d = getPathDFromSegments([
|
||||
['M', [1, 2]],
|
||||
['Z', []]
|
||||
]);
|
||||
equal(d, 'M1,2 Z');
|
||||
assert.equal(d, 'M1,2 Z');
|
||||
|
||||
d = getPathDFromSegments([
|
||||
['M', [1, 2]],
|
||||
['M', [3, 4]],
|
||||
['Z', []]
|
||||
]);
|
||||
equal(d, 'M1,2 M3,4 Z');
|
||||
assert.equal(d, 'M1,2 M3,4 Z');
|
||||
|
||||
d = getPathDFromSegments([
|
||||
['M', [1, 2]],
|
||||
['C', [3, 4, 5, 6]],
|
||||
['Z', []]
|
||||
]);
|
||||
equal(d, 'M1,2 C3,4 5,6 Z');
|
||||
assert.equal(d, 'M1,2 C3,4 5,6 Z');
|
||||
});
|
||||
|
||||
test('Test getPathDFromElement', function () {
|
||||
const {getPathDFromElement} = svgedit.utilities;
|
||||
QUnit.test('Test getPathDFromElement', function (assert) {
|
||||
const {getPathDFromElement} = utilities;
|
||||
|
||||
let elem = mockCreateSVGElement({
|
||||
'element': 'path',
|
||||
'attr': {'id': 'path', 'd': 'M0,1 Z'}
|
||||
element: 'path',
|
||||
attr: {id: 'path', d: 'M0,1 Z'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
equal(getPathDFromElement(elem), 'M0,1 Z');
|
||||
assert.equal(getPathDFromElement(elem), 'M0,1 Z');
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'rect',
|
||||
'attr': {'id': 'rect', 'x': '0', 'y': '1', 'width': '5', 'height': '10'}
|
||||
element: 'rect',
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
equal(getPathDFromElement(elem), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z');
|
||||
assert.equal(getPathDFromElement(elem), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z');
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'rect',
|
||||
'attr': {'id': 'roundrect', 'x': '0', 'y': '1', 'rx': '2', 'ry': '3', 'width': '10', 'height': '11'}
|
||||
element: 'rect',
|
||||
attr: {id: 'roundrect', x: '0', y: '1', rx: '2', ry: '3', width: '10', height: '11'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
const closeEnough = new RegExp('M0,4 C0,2.3[0-9]* 0.9[0-9]*,1 2,1 L8,1 C9.0[0-9]*,1 10,2.3[0-9]* 10,4 L10,9 C10,10.6[0-9]* 9.08675799086758,12 8,12 L2,12 C0.9[0-9]*,12 0,10.6[0-9]* 0,9 L0,4 Z');
|
||||
equal(closeEnough.test(getPathDFromElement(elem)), true);
|
||||
assert.equal(closeEnough.test(getPathDFromElement(elem)), true);
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'line',
|
||||
'attr': {'id': 'line', 'x1': '0', 'y1': '1', 'x2': '5', 'y2': '6'}
|
||||
element: 'line',
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
equal(getPathDFromElement(elem), 'M0,1L5,6');
|
||||
assert.equal(getPathDFromElement(elem), 'M0,1L5,6');
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'circle',
|
||||
'attr': {'id': 'circle', 'cx': '10', 'cy': '11', 'rx': '5', 'ry': '10'}
|
||||
element: 'circle',
|
||||
attr: {id: 'circle', cx: '10', cy: '11', rx: '5', ry: '10'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
equal(getPathDFromElement(elem), 'M10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 Z');
|
||||
assert.equal(getPathDFromElement(elem), 'M10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 C10,11 10,11 10,11 Z');
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'polyline',
|
||||
'attr': {'id': 'polyline', 'points': '0,1 5,1 5,11 0,11'}
|
||||
element: 'polyline',
|
||||
attr: {id: 'polyline', points: '0,1 5,1 5,11 0,11'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
equal(getPathDFromElement(elem), 'M0,1 5,1 5,11 0,11');
|
||||
assert.equal(getPathDFromElement(elem), 'M0,1 5,1 5,11 0,11');
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
equal(getPathDFromElement({tagName: 'something unknown'}), undefined);
|
||||
assert.equal(getPathDFromElement({tagName: 'something unknown'}), undefined);
|
||||
});
|
||||
|
||||
test('Test getBBoxOfElementAsPath', function () {
|
||||
QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
|
||||
function getBBoxOfElementAsPath (elem, addSvgElementFromJson, pathActions) {
|
||||
const bbox = svgedit.utilities.getBBoxOfElementAsPath(elem, addSvgElementFromJson, pathActions);
|
||||
return svgedit.utilities.bboxToObj(bbox); // need this for QUnit equal() to work.
|
||||
const bbox = utilities.getBBoxOfElementAsPath(elem, addSvgElementFromJson, pathActions);
|
||||
return utilities.bboxToObj(bbox); // need this for assert.equal() to work.
|
||||
}
|
||||
|
||||
let elem = mockCreateSVGElement({
|
||||
'element': 'path',
|
||||
'attr': {'id': 'path', 'd': 'M0,1 Z'}
|
||||
element: 'path',
|
||||
attr: {id: 'path', d: 'M0,1 Z'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
let bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
deepEqual(bbox, {x: 0, y: 1, width: 0, height: 0});
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 0, height: 0});
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'rect',
|
||||
'attr': {'id': 'rect', 'x': '0', 'y': '1', 'width': '5', 'height': '10'}
|
||||
element: 'rect',
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10});
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
elem = mockCreateSVGElement({
|
||||
'element': 'line',
|
||||
'attr': {'id': 'line', 'x1': '0', 'y1': '1', 'x2': '5', 'y2': '6'}
|
||||
element: 'line',
|
||||
attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
bbox = getBBoxOfElementAsPath(elem, mockAddSvgElementFromJson, mockPathActions);
|
||||
deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5});
|
||||
svgroot.removeChild(elem);
|
||||
|
||||
// TODO: test element with transform. Need resetOrientation above to be working or mock it.
|
||||
});
|
||||
|
||||
test('Test convertToPath rect', function () {
|
||||
const {convertToPath} = svgedit.utilities;
|
||||
QUnit.test('Test convertToPath rect', function (assert) {
|
||||
const {convertToPath} = utilities;
|
||||
const attrs = {
|
||||
'fill': 'red',
|
||||
'stroke': 'white',
|
||||
fill: 'red',
|
||||
stroke: 'white',
|
||||
'stroke-width': '1',
|
||||
'visibility': 'hidden'
|
||||
visibility: 'hidden'
|
||||
};
|
||||
|
||||
const elem = mockCreateSVGElement({
|
||||
'element': 'rect',
|
||||
'attr': {'id': 'rect', 'x': '0', 'y': '1', 'width': '5', 'height': '10'}
|
||||
element: 'rect',
|
||||
attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'}
|
||||
});
|
||||
svgroot.appendChild(elem);
|
||||
const path = convertToPath(elem, attrs, mockAddSvgElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
equal(path.getAttribute('d'), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z');
|
||||
equal(path.getAttribute('visibilituy'), null);
|
||||
equal(path.id, 'rect');
|
||||
equal(path.parentNode, svgroot);
|
||||
equal(elem.parentNode, null);
|
||||
equal(mockHistorySubCommands.length, 2);
|
||||
equal(mockCount.clearSelection, 1);
|
||||
equal(mockCount.addToSelection, 1);
|
||||
equal(mockCount.addCommandToHistory, 1);
|
||||
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');
|
||||
assert.equal(path.parentNode, svgroot);
|
||||
assert.equal(elem.parentNode, null);
|
||||
assert.equal(mockHistorySubCommands.length, 2);
|
||||
assert.equal(mockCount.clearSelection, 1);
|
||||
assert.equal(mockCount.addToSelection, 1);
|
||||
assert.equal(mockCount.addCommandToHistory, 1);
|
||||
svgroot.removeChild(path);
|
||||
});
|
||||
|
||||
test('Test convertToPath unknown element', function () {
|
||||
const {convertToPath} = svgedit.utilities;
|
||||
QUnit.test('Test convertToPath unknown element', function (assert) {
|
||||
const {convertToPath} = utilities;
|
||||
const attrs = {
|
||||
'fill': 'red',
|
||||
'stroke': 'white',
|
||||
fill: 'red',
|
||||
stroke: 'white',
|
||||
'stroke-width': '1',
|
||||
'visibility': 'hidden'
|
||||
visibility: 'hidden'
|
||||
};
|
||||
|
||||
const elem = {
|
||||
@@ -324,10 +337,10 @@ test('Test convertToPath unknown element', function () {
|
||||
parentNode: svgroot
|
||||
};
|
||||
const path = convertToPath(elem, attrs, mockAddSvgElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
|
||||
equal(path, null);
|
||||
equal(elem.parentNode, svgroot);
|
||||
equal(mockHistorySubCommands.length, 0);
|
||||
equal(mockCount.clearSelection, 0);
|
||||
equal(mockCount.addToSelection, 0);
|
||||
equal(mockCount.addCommandToHistory, 0);
|
||||
assert.equal(path, null);
|
||||
assert.equal(elem.parentNode, svgroot);
|
||||
assert.equal(mockHistorySubCommands.length, 0);
|
||||
assert.equal(mockCount.clearSelection, 0);
|
||||
assert.equal(mockCount.addToSelection, 0);
|
||||
assert.equal(mockCount.addCommandToHistory, 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user