- Linting (ESLint): Stricter rules (or switch to warning)

- Breaking internal API change: `updateGripCursor` moved to be class method of Selector rather than instance method
- Breaking internal API change: `subpathIsClosed` moved to be class method of `Path` rather than instance method
- Refactoring: Reuse utilities base64 encoder for SVG icons plugin
- Docs (JSDoc): Fix return of the `mouseUp` (can also be an object) and `mouseDown` (may also be a boolean) of `pathActions`; other JSDoc additions/improvements
This commit is contained in:
Brett Zamir
2018-11-07 14:51:50 +08:00
parent 901c9547fe
commit 7c470e9909
126 changed files with 2081 additions and 1373 deletions

View File

@@ -8,6 +8,10 @@ QUnit.log((details) => {
}
});
/**
* Tear down tests, resetting custom menus.
* @returns {undefined}
*/
function tearDown () {
contextmenu.resetCustomMenus();
}
@@ -39,7 +43,7 @@ QUnit.test('Test svgedit.contextmenu does not add invalid menu item', function (
QUnit.test('Test svgedit.contextmenu adds valid menu item', function (assert) {
assert.expect(2);
const validItem = {id: 'valid', label: 'anicelabel', action () { alert('testing'); }};
const validItem = {id: 'valid', label: 'anicelabel', action () { console.log('testing'); }};
contextmenu.add(validItem);
assert.ok(contextmenu.hasCustomHandler('valid'), 'Valid menu item is added.');
@@ -50,8 +54,8 @@ QUnit.test('Test svgedit.contextmenu adds valid menu item', function (assert) {
QUnit.test('Test svgedit.contextmenu rejects valid duplicate menu item id', function (assert) {
assert.expect(1);
const validItem1 = {id: 'valid', label: 'anicelabel', action () { alert('testing'); }};
const validItem2 = {id: 'valid', label: 'anicelabel', action () { alert('testingtwice'); }};
const validItem1 = {id: 'valid', label: 'anicelabel', action () { console.log('testing'); }};
const validItem2 = {id: 'valid', label: 'anicelabel', action () { console.log('testingtwice'); }};
contextmenu.add(validItem1);
contextmenu.add(validItem2);

View File

@@ -18,6 +18,11 @@ const svg = document.createElementNS(NS.SVG, 'svg');
svgroot.append(svg);
let elemId = 1;
/**
* Set up tests with mock data.
* @returns {undefined}
*/
function setUp () {
// Mock out editor context.
utilities.init(
@@ -38,13 +43,17 @@ function setUp () {
getGridSnapping () { return false; },
getDrawing () {
return {
getNextId () { return '' + elemId++; }
getNextId () { return String(elemId++); }
};
}
}
);
}
/**
* Tear down tests, removing elements.
* @returns {undefined}
*/
function tearDown () {
while (svg.hasChildNodes()) {
svg.firstChild.remove();

View File

@@ -65,8 +65,7 @@ const currentDrawing_ = new draw.Drawing(svgcontent, idprefix);
const getCurrentDrawing = function () {
return currentDrawing_;
};
const setCurrentGroup = (cg) => {
};
const setCurrentGroup = (cg) => { /* */ };
draw.init(
/**
* @implements {module:draw.DrawCanvasInit}
@@ -77,11 +76,15 @@ draw.init(
}
);
/**
* @param {module:utilities.SVGElementJSON} jsonMap
* @returns {SVGElement}
*/
function createSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
}
@@ -143,12 +146,7 @@ const cleanupSVG = function (svgElem) {
while (svgElem.firstChild) { svgElem.firstChild.remove(); }
};
QUnit.module('svgedit.draw.Drawing', {
beforeEach () {
},
afterEach () {
}
});
QUnit.module('svgedit.draw.Drawing');
QUnit.test('Test draw module', function (assert) {
assert.expect(4);
@@ -157,7 +155,7 @@ QUnit.test('Test draw module', function (assert) {
assert.equal(typeof draw, typeof {});
assert.ok(draw.Drawing);
assert.equal(typeof draw.Drawing, typeof function () {});
assert.equal(typeof draw.Drawing, typeof function () { /* */ });
});
QUnit.test('Test document creation', function (assert) {
@@ -311,7 +309,7 @@ QUnit.test('Test releaseId()', function (assert) {
QUnit.test('Test getNumLayers', function (assert) {
assert.expect(3);
const drawing = new draw.Drawing(svg);
assert.equal(typeof drawing.getNumLayers, typeof function () {});
assert.equal(typeof drawing.getNumLayers, typeof function () { /* */ });
assert.equal(drawing.getNumLayers(), 0);
setupSVGWith3Layers(svg);
@@ -329,7 +327,7 @@ QUnit.test('Test hasLayer', function (assert) {
const drawing = new draw.Drawing(svg);
drawing.identifyLayers();
assert.equal(typeof drawing.hasLayer, typeof function () {});
assert.equal(typeof drawing.hasLayer, typeof function () { /* */ });
assert.ok(!drawing.hasLayer('invalid-layer'));
assert.ok(drawing.hasLayer(LAYER3));
@@ -447,7 +445,7 @@ QUnit.test('Test getCurrentLayer()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.getCurrentLayer);
assert.equal(typeof drawing.getCurrentLayer, typeof function () {});
assert.equal(typeof drawing.getCurrentLayer, typeof function () { /* */ });
assert.ok(drawing.getCurrentLayer());
assert.equal(drawing.getCurrentLayer(), drawing.all_layers[2].getGroup());
@@ -462,7 +460,7 @@ QUnit.test('Test setCurrentLayer() and getCurrentLayerName()', function (assert)
drawing.identifyLayers();
assert.ok(drawing.setCurrentLayer);
assert.equal(typeof drawing.setCurrentLayer, typeof function () {});
assert.equal(typeof drawing.setCurrentLayer, typeof function () { /* */ });
drawing.setCurrentLayer(LAYER2);
assert.equal(drawing.getCurrentLayerName(), LAYER2);
@@ -485,7 +483,7 @@ QUnit.test('Test setCurrentLayerName()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.setCurrentLayerName);
assert.equal(typeof drawing.setCurrentLayerName, typeof function () {});
assert.equal(typeof drawing.setCurrentLayerName, typeof function () { /* */ });
const oldName = drawing.getCurrentLayerName();
const newName = 'New Name';
@@ -519,7 +517,7 @@ QUnit.test('Test createLayer()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.createLayer);
assert.equal(typeof drawing.createLayer, typeof function () {});
assert.equal(typeof drawing.createLayer, typeof function () { /* */ });
const NEW_LAYER_NAME = 'Layer A';
const layerG = drawing.createLayer(NEW_LAYER_NAME, mockHrService);
@@ -553,7 +551,7 @@ QUnit.test('Test mergeLayer()', function (assert) {
assert.equal(drawing.getCurrentLayer(), layers[2]);
assert.ok(drawing.mergeLayer);
assert.equal(typeof drawing.mergeLayer, typeof function () {});
assert.equal(typeof drawing.mergeLayer, typeof function () { /* */ });
drawing.mergeLayer(mockHrService);
@@ -623,7 +621,7 @@ QUnit.test('Test mergeAllLayers()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.mergeAllLayers);
assert.equal(typeof drawing.mergeAllLayers, typeof function () {});
assert.equal(typeof drawing.mergeAllLayers, typeof function () { /* */ });
drawing.mergeAllLayers(mockHrService);
@@ -661,7 +659,7 @@ QUnit.test('Test cloneLayer()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.cloneLayer);
assert.equal(typeof drawing.cloneLayer, typeof function () {});
assert.equal(typeof drawing.cloneLayer, typeof function () { /* */ });
const clone = drawing.cloneLayer('clone', mockHrService);
@@ -703,7 +701,7 @@ QUnit.test('Test getLayerVisibility()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.getLayerVisibility);
assert.equal(typeof drawing.getLayerVisibility, typeof function () {});
assert.equal(typeof drawing.getLayerVisibility, typeof function () { /* */ });
assert.ok(drawing.getLayerVisibility(LAYER1));
assert.ok(drawing.getLayerVisibility(LAYER2));
assert.ok(drawing.getLayerVisibility(LAYER3));
@@ -719,7 +717,7 @@ QUnit.test('Test setLayerVisibility()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.setLayerVisibility);
assert.equal(typeof drawing.setLayerVisibility, typeof function () {});
assert.equal(typeof drawing.setLayerVisibility, typeof function () { /* */ });
drawing.setLayerVisibility(LAYER3, false);
drawing.setLayerVisibility(LAYER2, true);
@@ -743,7 +741,7 @@ QUnit.test('Test getLayerOpacity()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.getLayerOpacity);
assert.equal(typeof drawing.getLayerOpacity, typeof function () {});
assert.equal(typeof drawing.getLayerOpacity, typeof function () { /* */ });
assert.strictEqual(drawing.getLayerOpacity(LAYER1), 1.0);
assert.strictEqual(drawing.getLayerOpacity(LAYER2), 1.0);
assert.strictEqual(drawing.getLayerOpacity(LAYER3), 1.0);
@@ -759,7 +757,7 @@ QUnit.test('Test setLayerOpacity()', function (assert) {
drawing.identifyLayers();
assert.ok(drawing.setLayerOpacity);
assert.equal(typeof drawing.setLayerOpacity, typeof function () {});
assert.equal(typeof drawing.setLayerOpacity, typeof function () { /* */ });
drawing.setLayerOpacity(LAYER1, 0.4);
drawing.setLayerOpacity(LAYER2, 'invalid-string');
@@ -802,18 +800,18 @@ QUnit.test('Test svgedit.draw.randomizeIds()', function (assert) {
// Confirm in LET_DOCUMENT_DECIDE mode that the document decides
// if there is a nonce.
let drawing = new draw.Drawing(svgN.cloneNode(true));
assert.ok(!!drawing.getNonce());
assert.ok(drawing.getNonce());
drawing = new draw.Drawing(svg.cloneNode(true));
assert.ok(!drawing.getNonce());
// Confirm that a nonce is set once we're in ALWAYS_RANDOMIZE mode.
draw.randomizeIds(true, drawing);
assert.ok(!!drawing.getNonce());
assert.ok(drawing.getNonce());
// Confirm new drawings in ALWAYS_RANDOMIZE mode have a nonce.
drawing = new draw.Drawing(svg.cloneNode(true));
assert.ok(!!drawing.getNonce());
assert.ok(drawing.getNonce());
drawing.clearNonce();
assert.ok(!drawing.getNonce());
@@ -822,7 +820,7 @@ QUnit.test('Test svgedit.draw.randomizeIds()', function (assert) {
// but that their se:nonce attribute is left alone.
draw.randomizeIds(false, drawing);
assert.ok(!drawing.getNonce());
assert.ok(!!drawing.getSvgElem().getAttributeNS(NS.SE, 'nonce'));
assert.ok(drawing.getSvgElem().getAttributeNS(NS.SE, 'nonce'));
drawing = new draw.Drawing(svg.cloneNode(true));
assert.ok(!drawing.getNonce());

View File

@@ -3,16 +3,16 @@
import {NS} from '../editor/namespaces.js';
import * as transformlist from '../editor/svgtransformlist.js';
import * as utilities from '../editor/utilities.js';
import * as history from '../editor/history.js';
import * as hstory from '../editor/history.js';
// TODO(codedread): Write tests for handling history events.
// Mocked out methods.
transformlist.changeRemoveElementFromListMap((elem) => {});
transformlist.changeRemoveElementFromListMap((elem) => { /* */ });
utilities.mock({
getHref (elem) { return '#foo'; },
setHref (elem, val) {},
setHref (elem, val) { /* */ },
getRotationAngle (elem) { return 0; }
});
@@ -36,10 +36,10 @@ QUnit.module('svgedit.history');
class MockCommand {
constructor (optText) { this.text_ = optText; }
apply () {}
unapply () {}
apply () { /* */ } // eslint-disable-line class-methods-use-this
unapply () { /* */ } // eslint-disable-line class-methods-use-this
getText () { return this.text_; }
elements () { return []; }
elements () { return []; } // eslint-disable-line class-methods-use-this
}
/*
@@ -48,9 +48,17 @@ class MockHistoryEventHandler {
}
*/
/**
* Set up tests (with undo manager).
* @returns {undefined}
*/
function setUp () {
undoMgr = new history.UndoManager();
undoMgr = new hstory.UndoManager();
}
/**
* Tear down tests, destroying undo manager.
* @returns {undefined}
*/
function tearDown () {
undoMgr = null;
}
@@ -58,19 +66,19 @@ function tearDown () {
QUnit.test('Test svgedit.history package', function (assert) {
assert.expect(13);
assert.ok(history);
assert.ok(history.MoveElementCommand);
assert.ok(history.InsertElementCommand);
assert.ok(history.ChangeElementCommand);
assert.ok(history.RemoveElementCommand);
assert.ok(history.BatchCommand);
assert.ok(history.UndoManager);
assert.equal(typeof history.MoveElementCommand, typeof function () {});
assert.equal(typeof history.InsertElementCommand, typeof function () {});
assert.equal(typeof history.ChangeElementCommand, typeof function () {});
assert.equal(typeof history.RemoveElementCommand, typeof function () {});
assert.equal(typeof history.BatchCommand, typeof function () {});
assert.equal(typeof history.UndoManager, typeof function () {});
assert.ok(hstory);
assert.ok(hstory.MoveElementCommand);
assert.ok(hstory.InsertElementCommand);
assert.ok(hstory.ChangeElementCommand);
assert.ok(hstory.RemoveElementCommand);
assert.ok(hstory.BatchCommand);
assert.ok(hstory.UndoManager);
assert.equal(typeof hstory.MoveElementCommand, typeof function () { /* */ });
assert.equal(typeof hstory.InsertElementCommand, typeof function () { /* */ });
assert.equal(typeof hstory.ChangeElementCommand, typeof function () { /* */ });
assert.equal(typeof hstory.RemoveElementCommand, typeof function () { /* */ });
assert.equal(typeof hstory.BatchCommand, typeof function () { /* */ });
assert.equal(typeof hstory.UndoManager, typeof function () { /* */ });
});
QUnit.test('Test UndoManager methods', function (assert) {
@@ -86,12 +94,12 @@ QUnit.test('Test UndoManager methods', function (assert) {
assert.ok(undoMgr.getNextRedoCommandText);
assert.equal(typeof undoMgr, typeof {});
assert.equal(typeof undoMgr.addCommandToHistory, typeof function () {});
assert.equal(typeof undoMgr.getUndoStackSize, typeof function () {});
assert.equal(typeof undoMgr.getRedoStackSize, typeof function () {});
assert.equal(typeof undoMgr.resetUndoStack, typeof function () {});
assert.equal(typeof undoMgr.getNextUndoCommandText, typeof function () {});
assert.equal(typeof undoMgr.getNextRedoCommandText, typeof function () {});
assert.equal(typeof undoMgr.addCommandToHistory, typeof function () { /* */ });
assert.equal(typeof undoMgr.getUndoStackSize, typeof function () { /* */ });
assert.equal(typeof undoMgr.getRedoStackSize, typeof function () { /* */ });
assert.equal(typeof undoMgr.resetUndoStack, typeof function () { /* */ });
assert.equal(typeof undoMgr.getNextUndoCommandText, typeof function () { /* */ });
assert.equal(typeof undoMgr.getNextRedoCommandText, typeof function () { /* */ });
tearDown();
});
@@ -312,8 +320,8 @@ QUnit.test('Test MoveElementCommand', function (assert) {
let move = new history.MoveElementCommand(div3, div1, divparent);
assert.ok(move.unapply);
assert.ok(move.apply);
assert.equal(typeof move.unapply, typeof function () {});
assert.equal(typeof move.apply, typeof function () {});
assert.equal(typeof move.unapply, typeof function () { /* */ });
assert.equal(typeof move.apply, typeof function () { /* */ });
move.unapply();
assert.equal(divparent.firstElementChild, div3);
@@ -325,7 +333,7 @@ QUnit.test('Test MoveElementCommand', function (assert) {
assert.equal(divparent.firstElementChild.nextElementSibling, div2);
assert.equal(divparent.lastElementChild, div3);
move = new history.MoveElementCommand(div1, null, divparent);
move = new hstory.MoveElementCommand(div1, null, divparent);
move.unapply();
assert.equal(divparent.firstElementChild, div2);
@@ -337,7 +345,7 @@ QUnit.test('Test MoveElementCommand', function (assert) {
assert.equal(divparent.firstElementChild.nextElementSibling, div2);
assert.equal(divparent.lastElementChild, div3);
move = new history.MoveElementCommand(div2, div5, div4);
move = new hstory.MoveElementCommand(div2, div5, div4);
move.unapply();
assert.equal(divparent.firstElementChild, div1);
@@ -361,11 +369,11 @@ QUnit.test('Test InsertElementCommand', function (assert) {
setUp();
let insert = new history.InsertElementCommand(div3);
let insert = new hstory.InsertElementCommand(div3);
assert.ok(insert.unapply);
assert.ok(insert.apply);
assert.equal(typeof insert.unapply, typeof function () {});
assert.equal(typeof insert.apply, typeof function () {});
assert.equal(typeof insert.unapply, typeof function () { /* */ });
assert.equal(typeof insert.apply, typeof function () { /* */ });
insert.unapply();
assert.equal(divparent.childElementCount, 2);
@@ -379,7 +387,7 @@ QUnit.test('Test InsertElementCommand', function (assert) {
assert.equal(div1.nextElementSibling, div2);
assert.equal(div2.nextElementSibling, div3);
insert = new history.InsertElementCommand(div2);
insert = new hstory.InsertElementCommand(div2);
insert.unapply();
assert.equal(divparent.childElementCount, 2);
@@ -404,11 +412,11 @@ QUnit.test('Test RemoveElementCommand', function (assert) {
const div6 = document.createElement('div');
div6.id = 'div6';
let remove = new history.RemoveElementCommand(div6, null, divparent);
let remove = new hstory.RemoveElementCommand(div6, null, divparent);
assert.ok(remove.unapply);
assert.ok(remove.apply);
assert.equal(typeof remove.unapply, typeof function () {});
assert.equal(typeof remove.apply, typeof function () {});
assert.equal(typeof remove.unapply, typeof function () { /* */ });
assert.equal(typeof remove.apply, typeof function () { /* */ });
remove.unapply();
assert.equal(divparent.childElementCount, 4);
@@ -423,7 +431,7 @@ QUnit.test('Test RemoveElementCommand', function (assert) {
assert.equal(div1.nextElementSibling, div2);
assert.equal(div2.nextElementSibling, div3);
remove = new history.RemoveElementCommand(div6, div2, divparent);
remove = new hstory.RemoveElementCommand(div6, div2, divparent);
remove.unapply();
assert.equal(divparent.childElementCount, 4);
@@ -447,12 +455,12 @@ QUnit.test('Test ChangeElementCommand', function (assert) {
setUp();
div1.setAttribute('title', 'new title');
let change = new history.ChangeElementCommand(div1,
let change = new hstory.ChangeElementCommand(div1,
{title: 'old title', class: 'foo'});
assert.ok(change.unapply);
assert.ok(change.apply);
assert.equal(typeof change.unapply, typeof function () {});
assert.equal(typeof change.apply, typeof function () {});
assert.equal(typeof change.unapply, typeof function () { /* */ });
assert.equal(typeof change.apply, typeof function () { /* */ });
change.unapply();
assert.equal(div1.getAttribute('title'), 'old title');
@@ -463,7 +471,7 @@ QUnit.test('Test ChangeElementCommand', function (assert) {
assert.ok(!div1.getAttribute('class'));
div1.textContent = 'inner text';
change = new history.ChangeElementCommand(div1,
change = new hstory.ChangeElementCommand(div1,
{'#text': null});
change.unapply();
@@ -473,7 +481,7 @@ QUnit.test('Test ChangeElementCommand', function (assert) {
assert.equal(div1.textContent, 'inner text');
div1.textContent = '';
change = new history.ChangeElementCommand(div1,
change = new hstory.ChangeElementCommand(div1,
{'#text': 'old text'});
change.unapply();
@@ -502,7 +510,7 @@ QUnit.test('Test ChangeElementCommand', function (assert) {
});
gethrefvalue = '#newhref';
change = new history.ChangeElementCommand(rect,
change = new hstory.ChangeElementCommand(rect,
{'#href': '#oldhref'});
assert.equal(justCalled, 'getHref');
@@ -518,12 +526,12 @@ QUnit.test('Test ChangeElementCommand', function (assert) {
const line = document.createElementNS(NS.SVG, 'line');
line.setAttribute('class', 'newClass');
change = new history.ChangeElementCommand(line, {class: 'oldClass'});
change = new hstory.ChangeElementCommand(line, {class: 'oldClass'});
assert.ok(change.unapply);
assert.ok(change.apply);
assert.equal(typeof change.unapply, typeof function () {});
assert.equal(typeof change.apply, typeof function () {});
assert.equal(typeof change.unapply, typeof function () { /* */ });
assert.equal(typeof change.apply, typeof function () { /* */ });
change.unapply();
assert.equal(line.getAttribute('class'), 'oldClass');
@@ -542,15 +550,15 @@ QUnit.test('Test BatchCommand', function (assert) {
let concatResult = '';
MockCommand.prototype.apply = function () { concatResult += this.text_; };
const batch = new history.BatchCommand();
const batch = new hstory.BatchCommand();
assert.ok(batch.unapply);
assert.ok(batch.apply);
assert.ok(batch.addSubCommand);
assert.ok(batch.isEmpty);
assert.equal(typeof batch.unapply, typeof function () {});
assert.equal(typeof batch.apply, typeof function () {});
assert.equal(typeof batch.addSubCommand, typeof function () {});
assert.equal(typeof batch.isEmpty, typeof function () {});
assert.equal(typeof batch.unapply, typeof function () { /* */ });
assert.equal(typeof batch.apply, typeof function () { /* */ });
assert.equal(typeof batch.addSubCommand, typeof function () { /* */ });
assert.equal(typeof batch.isEmpty, typeof function () { /* */ });
assert.ok(batch.isEmpty());
@@ -563,13 +571,13 @@ QUnit.test('Test BatchCommand', function (assert) {
batch.apply();
assert.equal(concatResult, 'abc');
MockCommand.prototype.apply = function () {};
MockCommand.prototype.apply = function () { /* */ };
MockCommand.prototype.unapply = function () { concatResult += this.text_; };
concatResult = '';
batch.unapply();
assert.equal(concatResult, 'cba');
MockCommand.prototype.unapply = function () {};
MockCommand.prototype.unapply = function () { /* */ };
tearDown();
});

View File

@@ -1,5 +1,9 @@
/* eslint-env qunit */
/* eslint-disable import/unambiguous */
// Todo: Incomplete!
// log function
QUnit.log((details) => {
if (window.console && window.console.log) {

View File

@@ -20,9 +20,9 @@ QUnit.test('Test svgedit.math package', function (assert) {
assert.ok(math.transformPoint);
assert.ok(math.isIdentity);
assert.ok(math.matrixMultiply);
assert.equal(typeof math.transformPoint, typeof function () {});
assert.equal(typeof math.isIdentity, typeof function () {});
assert.equal(typeof math.matrixMultiply, typeof function () {});
assert.equal(typeof math.transformPoint, typeof function () { /* */ });
assert.equal(typeof math.isIdentity, typeof function () { /* */ });
assert.equal(typeof math.matrixMultiply, typeof function () { /* */ });
});
QUnit.test('Test svgedit.math.transformPoint() function', function (assert) {

View File

@@ -1,5 +1,12 @@
const NEAR_ZERO = 5e-6; // 0.000005, Firefox fails at higher levels of precision.
/**
* Checks that the supplied values are equal with a high though not absolute degree of precision.
* @param {Float} actual
* @param {Float} expected
* @param {string} message
* @returns {undefined}
*/
function almostEquals (actual, expected, message) {
message = message || (actual + ' did not equal ' + expected);
this.pushResult({
@@ -10,6 +17,10 @@ function almostEquals (actual, expected, message) {
});
}
/**
* @param {external:qunit} QUnit
* @returns {external:qunit} The same instance passed in after extending
*/
export default function extend (QUnit) {
QUnit.extend(QUnit.assert, {
almostEquals

View File

@@ -10,7 +10,7 @@
* @param {string} [message] Defaults to structured message
* @returns {undefined}
*/
function close (actual, expected, maxDifference, message) {
function close (actual, expected, maxDifference, message) { // eslint-disable-line no-shadow
const actualDiff = (actual === expected) ? 0 : Math.abs(actual - expected),
result = actualDiff <= maxDifference;
message = message || (actual + ' should be within ' + maxDifference + ' (inclusive) of ' + expected + (result ? '' : '. Actual: ' + actualDiff));
@@ -96,6 +96,10 @@ function notClosePercent (actual, expected, minPercentDifference, message) {
this.pushResult({result, actual, expected, message});
}
/**
* @param {external:qunit} QUnit
* @returns {external:qunit} The same instance passed in after extending
*/
export default function extend (QUnit) {
QUnit.extend(QUnit.assert, {
close,

View File

@@ -1,3 +1,10 @@
/**
* Expects an out of bounds `INDEX_SIZE_ERR` exception.
* @param {GenericObject} obj
* @param {GenericCallback} fn
* @param {Any} arg1
* @returns {undefined}
*/
function expectOutOfBoundsException (obj, fn, arg1) {
const expected = true;
const message = 'Caught an INDEX_SIZE_ERR exception';
@@ -10,9 +17,13 @@ function expectOutOfBoundsException (obj, fn, arg1) {
}
}
const actual = result;
console.log('aaa', result, actual, expected);
this.pushResult({result, actual, expected, message});
}
/**
* @param {external:qunit} QUnit
* @returns {external:qunit} The same instance passed in after extending
*/
export default function extend (QUnit) {
QUnit.extend(QUnit.assert, {
expectOutOfBoundsException

View File

@@ -20,6 +20,11 @@ const svg = document.createElementNS(NS.SVG, 'svg');
svgroot.append(svg);
let elemId = 1;
/**
* Initilize modules to set up the tests.
* @returns {undefined}
*/
function setUp () {
utilities.init(
/**
@@ -39,7 +44,7 @@ function setUp () {
getGridSnapping () { return false; },
getDrawing () {
return {
getNextId () { return '' + elemId++; }
getNextId () { return String(elemId++); }
};
}
}
@@ -51,13 +56,17 @@ function setUp () {
{
getSVGRoot () { return svg; },
getStartTransform () { return ''; },
setStartTransform () {}
setStartTransform () { /* */ }
}
);
}
let elem;
/**
* Initialize for tests and set up `rect` element.
* @returns {undefined}
*/
function setUpRect () {
setUp();
elem = document.createElementNS(NS.SVG, 'rect');
@@ -68,6 +77,10 @@ function setUpRect () {
svg.append(elem);
}
/**
* Initialize for tests and set up `text` element with `tspan` child.
* @returns {undefined}
*/
function setUpTextWithTspan () {
setUp();
elem = document.createElementNS(NS.SVG, 'text');
@@ -84,6 +97,10 @@ function setUpTextWithTspan () {
svg.append(elem);
}
/**
* Tear down the tests (empty the svg element).
* @returns {undefined}
*/
function tearDown () {
while (svg.hasChildNodes()) {
svg.firstChild.remove();

View File

@@ -1,6 +1,6 @@
/* eslint-env qunit */
import {NS} from '../editor/namespaces.js';
import * as select from '../editor/select.js';
import {NS} from '../editor/namespaces.js';
// log function
QUnit.log((details) => {
@@ -23,16 +23,20 @@ const mockConfig = {
*/
const mockFactory = {
createSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap.attr) {
elem.setAttribute(attr, jsonMap.attr[attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
},
svgRoot () { return svgroot; },
svgContent () { return svgcontent; }
};
/**
* Potentially reusable test set-up.
* @returns {undefined}
*/
function setUp () {
svgroot = mockFactory.createSVGElement({
element: 'svg',
@@ -66,6 +70,10 @@ function setUpWithInit () {
}
*/
/**
* Tear down the test by emptying our sandbox area.
* @returns {undefined}
*/
function tearDown () {
while (sandbox.hasChildNodes()) {
sandbox.firstChild.remove();
@@ -81,10 +89,10 @@ QUnit.test('Test svgedit.select package', function (assert) {
assert.ok(select.init);
assert.ok(select.getSelectorManager);
assert.equal(typeof select, typeof {});
assert.equal(typeof select.Selector, typeof function () {});
assert.equal(typeof select.SelectorManager, typeof function () {});
assert.equal(typeof select.init, typeof function () {});
assert.equal(typeof select.getSelectorManager, typeof function () {});
assert.equal(typeof select.Selector, typeof function () { /* */ });
assert.equal(typeof select.SelectorManager, typeof function () { /* */ });
assert.equal(typeof select.init, typeof function () { /* */ });
assert.equal(typeof select.getSelectorManager, typeof function () { /* */ });
});
QUnit.test('Test Selector DOM structure', function (assert) {

View File

@@ -1,6 +1,20 @@
// Adapted from https://www.npmjs.com/package/sinon-test
export default function ({sinon, QUnit}) {
/**
* @external QUnit
*/
/**
* @external sinon
*/
/**
* Adds methods to Sinon using a QUnit implementation.
* @param {PlainObject} implementations
* @param {external:sinon} implementations.sinon
* @param {external:QUnit} implementations.QUnit
* @returns {undefined}
*/
export default function sinonQunit ({sinon, QUnit}) {
sinon.assert.fail = function (msg) {
QUnit.ok(false, msg);
};
@@ -10,7 +24,7 @@ export default function ({sinon, QUnit}) {
};
const qTest = QUnit.test;
QUnit.test = function (testName, callback) {
QUnit.test = function (testName, callback) { // eslint-disable-line promise/prefer-await-to-callbacks
return qTest(testName, sinon.test(callback));
};
}

View File

@@ -21,6 +21,10 @@ QUnit.log((details) => {
const svgroot = document.querySelector('#svgroot');
let svgcontent, rect, circle;
/**
* Set up tests, adding elements.
* @returns {undefined}
*/
function setUp () {
svgcontent = svgroot.appendChild(document.createElementNS(NS.SVG, 'svg'));
rect = svgcontent.appendChild(document.createElementNS(NS.SVG, 'rect'));
@@ -29,6 +33,10 @@ function setUp () {
circle.id = 'c';
}
/**
* Tear down tests, emptying SVG root, and resetting list map.
* @returns {undefined}
*/
function tearDown () {
transformlist.resetListMap();
while (svgroot.hasChildNodes()) {
@@ -82,7 +90,7 @@ QUnit.test('Test SVGTransformList.initialize()', function (assert) {
const t = svgcontent.createSVGTransform();
assert.ok(t);
assert.ok(rxform.initialize);
assert.equal(typeof rxform.initialize, typeof function () {});
assert.equal(typeof rxform.initialize, typeof function () { /* */ });
rxform.initialize(t);
assert.equal(rxform.numberOfItems, 1);
assert.equal(cxform.numberOfItems, 0);
@@ -110,8 +118,8 @@ QUnit.test('Test SVGTransformList.appendItem() and getItem()', function (assert)
assert.ok(rxform.appendItem);
assert.ok(rxform.getItem);
assert.equal(typeof rxform.appendItem, typeof function () {});
assert.equal(typeof rxform.getItem, typeof function () {});
assert.equal(typeof rxform.appendItem, typeof function () { /* */ });
assert.equal(typeof rxform.getItem, typeof function () { /* */ });
rxform.appendItem(t1);
rxform.appendItem(t2);
@@ -145,7 +153,7 @@ QUnit.test('Test SVGTransformList.removeItem()', function (assert) {
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform();
assert.ok(rxform.removeItem);
assert.equal(typeof rxform.removeItem, typeof function () {});
assert.equal(typeof rxform.removeItem, typeof function () { /* */ });
rxform.appendItem(t1);
rxform.appendItem(t2);
@@ -168,7 +176,7 @@ QUnit.test('Test SVGTransformList.replaceItem()', function (assert) {
const cxform = transformlist.getTransformList(circle);
assert.ok(rxform.replaceItem);
assert.equal(typeof rxform.replaceItem, typeof function () {});
assert.equal(typeof rxform.replaceItem, typeof function () { /* */ });
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
@@ -205,7 +213,7 @@ QUnit.test('Test SVGTransformList.insertItemBefore()', function (assert) {
const cxform = transformlist.getTransformList(circle);
assert.ok(rxform.insertItemBefore);
assert.equal(typeof rxform.insertItemBefore, typeof function () {});
assert.equal(typeof rxform.insertItemBefore, typeof function () { /* */ });
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),

View File

@@ -40,7 +40,8 @@ const svgCanvas = new SvgCanvas(
extensions: ['ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js'],
initTool: 'select',
wireframe: false
});
}
);
const
// svgroot = document.getElementById('svgroot'),
@@ -188,7 +189,7 @@ QUnit.test('Test import math elements inside a foreignObject', function (assert)
// see Bug https://bugs.webkit.org/show_bug.cgi?id=35042
const math = fo.firstChild;
assert.equal(!!math, true, 'Math element exists');
assert.equal(Boolean(math), true, 'Math element exists');
assert.equal(math.nodeName, 'math', 'Math element has the proper nodeName');
assert.equal(math.getAttribute('id'), 'm', 'Math element has an id');
assert.equal(math.namespaceURI, 'http://www.w3.org/1998/Math/MathML', 'Preserved MathML namespace');
@@ -227,12 +228,13 @@ QUnit.test('Test importing SVG remaps IDs', function (assert) {
/* const doc = */ svgCanvas.setSvgString(
'<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">' +
'<g><title>Layer 1</title>' +
'<ellipse id="svg_1" cx="200" cy="200" rx="50" ry="20" fill="blue"/>' +
'<ellipse id="svg_2" cx="300" cy="100" rx="40" ry="30" fill="green"/>' +
'<ellipse id="svg_3" cx="300" cy="100" rx="40" ry="30" fill="green"/>' +
'</g>' +
'</svg>');
'<g><title>Layer 1</title>' +
'<ellipse id="svg_1" cx="200" cy="200" rx="50" ry="20" fill="blue"/>' +
'<ellipse id="svg_2" cx="300" cy="100" rx="40" ry="30" fill="green"/>' +
'<ellipse id="svg_3" cx="300" cy="100" rx="40" ry="30" fill="green"/>' +
'</g>' +
'</svg>'
);
svgCanvas.importSvgString(
'<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink">' +

View File

@@ -6,14 +6,14 @@ import axeCheck from 'axe-testcafe';
fixture`TestCafe Axe accessibility tests (Editor - no parameters)`
.page`http://localhost:8000/editor/svg-editor.html`;
test('Editor - no parameters', async t => {
test('Editor - no parameters', async (t) => {
await axeCheck(t); // , axeContent, axeOptions: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axerun
});
fixture`TestCafe Axe accessibility tests (Editor - with all extensions)`
.page`http://localhost:8000/editor/svg-editor.html?extensions=ext-arrows.js,ext-closepath.js,ext-foreignobject.js,ext-helloworld.js,ext-mathjax.js,ext-php_savefile.js,ext-server_moinsave.js,ext-server_opensave.js,ext-webappfind.js,ext-xdomain-messaging.js`;
test('Editor ES - with all extensions', async t => {
test('Editor ES - with all extensions', async (t) => {
await axeCheck(t); // , axeContent, axeOptions: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axerun
});

View File

@@ -6,14 +6,14 @@ import {Selector} from 'testcafe';
fixture`TestCafe UI tests`
.page`http://localhost:8000/editor/svg-editor.html`;
test('Editor - No parameters: Export button', async t => {
test('Editor - No parameters: Export button', async (t) => {
await t
.click('#dialog_buttons > input[type=button][value=OK]')
.click('#main_icon')
.expect(Selector('#tool_export')).ok('Has open button');
});
test('Editor - No parameters: Export button clicking', async t => {
test('Editor - No parameters: Export button clicking', async (t) => {
await t
.click('#dialog_buttons > input[type=button][value=OK]')
.click('#main_icon')

View File

@@ -8,6 +8,10 @@ QUnit.log((details) => {
}
});
/**
* Set up tests, supplying mock data.
* @returns {undefined}
*/
function setUp () {
units.init(
/**
@@ -35,7 +39,7 @@ QUnit.test('Test svgedit.units.shortFloat()', function (assert) {
setUp();
assert.ok(units.shortFloat);
assert.equal(typeof units.shortFloat, typeof function () {});
assert.equal(typeof units.shortFloat, typeof function () { /* */ });
const {shortFloat} = units;
assert.equal(shortFloat(0.00000001), 0);
@@ -51,7 +55,7 @@ QUnit.test('Test svgedit.units.isValidUnit()', function (assert) {
setUp();
assert.ok(units.isValidUnit);
assert.equal(typeof units.isValidUnit, typeof function () {});
assert.equal(typeof units.isValidUnit, typeof function () { /* */ });
const {isValidUnit} = units;
assert.ok(isValidUnit('0'));
@@ -79,7 +83,7 @@ QUnit.test('Test svgedit.units.convertUnit()', function (assert) {
setUp();
assert.ok(units.convertUnit);
assert.equal(typeof units.convertUnit, typeof function () {});
assert.equal(typeof units.convertUnit, typeof function () { /* */ });
// cm in default setup
assert.equal(units.convertUnit(42), 1.1113);
assert.equal(units.convertUnit(42, 'px'), 42);

View File

@@ -16,14 +16,25 @@ QUnit.log((details) => {
}
});
/**
* Create an SVG element for a mock.
* @param {module:utilities.SVGElementJSON} jsonMap
* @returns {SVGElement}
*/
function mockCreateSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
}
let mockaddSVGElementFromJsonCallCount = 0;
/**
* Mock of {@link module:utilities.EditorContext#addSVGElementFromJson}.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
function mockaddSVGElementFromJson (json) {
const elem = mockCreateSVGElement(json);
svgroot.append(elem);
@@ -32,7 +43,7 @@ function mockaddSVGElementFromJson (json) {
}
const mockPathActions = {
resetOrientation (pth) {
if (pth == null || pth.nodeName !== 'path') { return false; }
if (utilities.isNullish(pth) || pth.nodeName !== 'path') { return false; }
const tlist = transformlist.getTransformList(pth);
const m = math.transformListToTransform(tlist).matrix;
tlist.clear();
@@ -57,6 +68,7 @@ const mockPathActions = {
path.replacePathSeg(type, i, pts, pth);
}
// path.reorientGrads(pth, m);
return undefined;
}
};
@@ -75,8 +87,6 @@ QUnit.module('svgedit.utilities_bbox', {
transformlist.resetListMap();
path.init(null);
mockaddSVGElementFromJsonCallCount = 0;
},
afterEach () {
}
});
@@ -167,7 +177,7 @@ QUnit.test('Test getBBoxWithTransform and a rotation transform', function (asser
const rect = {x: 10, y: 10, width: 10, height: 20};
const angle = 45;
const origin = {x: 15, y: 20};
const origin = {x: 15, y: 20}; // eslint-disable-line no-shadow
elem = mockCreateSVGElement({
element: 'rect',
attr: {id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')'}
@@ -256,7 +266,7 @@ QUnit.test('Test getBBoxWithTransform with rotation and matrix transforms', func
const rect = {x: 10, y: 10, width: 10, height: 20};
const angle = 45;
const origin = {x: 15, y: 20};
const origin = {x: 15, y: 20}; // eslint-disable-line no-shadow
tx = 10; // tx right
ty = 10; // tx down
txInRotatedSpace = Math.sqrt(tx * tx + ty * ty); // translate in rotated 45 space.
@@ -443,10 +453,23 @@ QUnit.test('Test getStrokedBBox with no stroke-width attribute', function (asser
g.remove();
});
/**
* Returns radians for degrees.
* @param {Float} degrees
* @returns {Float}
*/
function radians (degrees) {
return degrees * Math.PI / 180;
}
function rotatePoint (point, angle, origin) {
/**
*
* @param {module:utilities.BBoxObject} point
* @param {Float} angle
* @param {module:math.XYObject} origin
* @returns {module:math.XYObject}
*/
function rotatePoint (point, angle, origin) { // eslint-disable-line no-shadow
if (!origin) {
origin = {x: 0, y: 0};
}
@@ -458,7 +481,14 @@ function rotatePoint (point, angle, origin) {
y: x * Math.sin(theta) + y * Math.cos(theta) + origin.y
};
}
function rotateRect (rect, angle, origin) {
/**
*
* @param {module:utilities.BBoxObject} rect
* @param {Float} angle
* @param {module:math.XYObject} origin
* @returns {module:utilities.BBoxObject}
*/
function rotateRect (rect, angle, origin) { // eslint-disable-line no-shadow
const tl = rotatePoint({x: rect.x, y: rect.y}, angle, origin);
const tr = rotatePoint({x: rect.x + rect.width, y: rect.y}, angle, origin);
const br = rotatePoint({x: rect.x + rect.width, y: rect.y + rect.height}, angle, origin);

View File

@@ -14,13 +14,24 @@ QUnit.log((details) => {
const currentLayer = document.getElementById('layer1');
/**
* Create an SVG element for a mock.
* @param {module:utilities.SVGElementJSON} jsonMap
* @returns {SVGElement}
*/
function mockCreateSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
}
/**
* Mock of {@link module:utilities.EditorContext#addSVGElementFromJson}.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
function mockaddSVGElementFromJson (json) {
const elem = mockCreateSVGElement(json);
currentLayer.append(elem);
@@ -31,27 +42,28 @@ function mockaddSVGElementFromJson (json) {
const groupWithMatrixTransform = document.getElementById('svg_group_with_matrix_transform');
const textWithMatrixTransform = document.getElementById('svg_text_with_matrix_transform');
/**
* Toward performance testing, fill document with clones of element.
* @param {SVGElement} elem
* @param {Integer} count
* @returns {undefined}
*/
function fillDocumentByCloningElement (elem, count) {
const elemId = elem.getAttribute('id') + '-';
for (let index = 0; index < count; index++) {
const clone = elem.cloneNode(true); // t: deep clone
// Make sure you set a unique ID like a real document.
clone.setAttribute('id', elemId + index);
const parent = elem.parentNode;
parent.append(clone);
const {parentNode} = elem;
parentNode.append(clone);
}
}
QUnit.module('svgedit.utilities_performance', {
beforeEach () {
},
afterEach () {
}
});
QUnit.module('svgedit.utilities_performance');
const mockPathActions = {
resetOrientation (path) {
if (path == null || path.nodeName !== 'path') { return false; }
if (utilities.isNullish(path) || path.nodeName !== 'path') { return false; }
const tlist = transformlist.getTransformList(path);
const m = math.transformListToTransform(tlist).matrix;
tlist.clear();
@@ -64,10 +76,13 @@ const mockPathActions = {
for (let i = 0; i < len; ++i) {
const seg = segList.getItem(i);
const type = seg.pathSegType;
if (type === 1) { continue; }
if (type === 1) {
continue;
}
const pts = [];
['', 1, 2].forEach(function (n, j) {
const x = seg['x' + n], y = seg['y' + n];
const x = seg['x' + n],
y = seg['y' + n];
if (x !== undefined && y !== undefined) {
const pt = math.transformPoint(x, y, m);
pts.splice(pts.length, 0, pt.x, pt.y);
@@ -77,6 +92,7 @@ const mockPathActions = {
}
// utilities.reorientGrads(path, m);
return undefined;
}
};
@@ -144,11 +160,11 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
// The second pass is two to ten times faster.
setTimeout(function () {
const count = children.length;
const ct = children.length;
const start = lastTime = now = Date.now();
const strt = lastTime = now = Date.now();
// Skip the first child which is the title.
for (let index = 1; index < count; index++) {
for (let index = 1; index < ct; index++) {
const child = children[index];
/* const obj = */ getStrokedBBox([child], mockaddSVGElementFromJson, mockPathActions);
now = Date.now(); const delta = now - lastTime; lastTime = now;
@@ -157,10 +173,10 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
max = Math.max(max, delta);
}
total = lastTime - start;
const ave = total / count;
assert.ok(ave < 2, 'svgedit.utilities.getStrokedBBox average execution time is less than 1 ms');
console.log('Pass2 svgCanvas.getStrokedBBox total ms ' + total + ', ave ms ' + ave.toFixed(1) + ',\t min/max ' + min + ' ' + max);
total = lastTime - strt;
const avg = total / ct;
assert.ok(avg < 2, 'svgedit.utilities.getStrokedBBox average execution time is less than 1 ms');
console.log('Pass2 svgCanvas.getStrokedBBox total ms ' + total + ', ave ms ' + avg.toFixed(1) + ',\t min/max ' + min + ' ' + max);
done();
});

View File

@@ -1,8 +1,8 @@
/* eslint-env qunit */
import {NS} from '../editor/namespaces.js';
import * as utilities from '../editor/utilities.js';
import * as browser from '../editor/browser.js';
import * as utilities from '../editor/utilities.js';
import {NS} from '../editor/namespaces.js';
// log function
QUnit.log((details) => {
@@ -11,19 +11,29 @@ QUnit.log((details) => {
}
});
/**
* Create an element for test.
* @param {module:utilities.SVGElementJSON} jsonMap
* @returns {SVGElement}
*/
function mockCreateSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
}
/**
* Adds SVG Element per parameters and appends to root.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
function mockaddSVGElementFromJson (json) {
const elem = mockCreateSVGElement(json);
svgroot.append(elem);
return elem;
}
const mockPathActions = {resetOrientation () {}};
const mockPathActions = {resetOrientation () { /* */ }};
let mockHistorySubCommands = [];
const mockHistory = {
BatchCommand: class {
@@ -34,7 +44,8 @@ const mockHistory = {
}
},
RemoveElementCommand: class {
constructor (elem, nextSibling, parent) { // Longhand needed since used as a constructor
// Longhand needed since used as a constructor
constructor (elem, nextSibling, parent) {
this.elem = elem;
this.nextSibling = nextSibling;
this.parent = parent;
@@ -51,9 +62,28 @@ const mockCount = {
addToSelection: 0,
addCommandToHistory: 0
};
function mockClearSelection () { mockCount.clearSelection++; }
function mockAddToSelection () { mockCount.addToSelection++; }
function mockAddCommandToHistory () { mockCount.addCommandToHistory++; }
/**
* Increments clear seleciton count for mock test.
* @returns {undefined}
*/
function mockClearSelection () {
mockCount.clearSelection++;
}
/**
* Increments add selection count for mock test.
* @returns {undefined}
*/
function mockAddToSelection () {
mockCount.addToSelection++;
}
/**
* Increments add command to history count for mock test.
* @returns {undefined}
*/
function mockAddCommandToHistory () {
mockCount.addCommandToHistory++;
}
const svg = document.createElementNS(NS.SVG, 'svg');
const sandbox = document.getElementById('sandbox');
@@ -70,8 +100,7 @@ QUnit.module('svgedit.utilities', {
mockCount.addToSelection = 0;
mockCount.addCommandToHistory = 0;
},
afterEach () {
}
afterEach () { /* */ }
});
QUnit.test('Test svgedit.utilities package', function (assert) {
@@ -79,7 +108,7 @@ QUnit.test('Test svgedit.utilities package', function (assert) {
assert.ok(utilities);
assert.ok(utilities.toXml);
assert.equal(typeof utilities.toXml, typeof function () {});
assert.equal(typeof utilities.toXml, typeof function () { /* */ });
});
QUnit.test('Test svgedit.utilities.toXml() function', function (assert) {
@@ -259,6 +288,10 @@ QUnit.test('Test getPathDFromElement', function (assert) {
});
QUnit.test('Test getBBoxOfElementAsPath', function (assert) {
/**
* Wrap `utilities.getBBoxOfElementAsPath` to convert bbox to object for testing.
* @implements {module:utilities.getBBoxOfElementAsPath}
*/
function getBBoxOfElementAsPath (elem, addSVGElementFromJson, pathActions) {
const bbox = utilities.getBBoxOfElementAsPath(elem, addSVGElementFromJson, pathActions);
return utilities.bboxToObj(bbox); // need this for assert.equal() to work.