- 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

@@ -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.