#90 test case issue fixed (#92)

* #90 global datastorage code changes
This commit is contained in:
Agriya Dev5
2021-04-21 22:20:00 +05:30
committed by GitHub
parent 699721ea16
commit 9d2379f333
16 changed files with 2110 additions and 2029 deletions

View File

@@ -1,6 +1,6 @@
import '../../../instrumented/editor/jquery.min.js';
import {NS} from '../../../instrumented/common/namespaces.js';
import { NS } from '../../../instrumented/common/namespaces.js';
import * as utilities from '../../../instrumented/svgcanvas/utilities.js';
import * as coords from '../../../instrumented/svgcanvas/coords.js';
import * as recalculate from '../../../instrumented/svgcanvas/recalculate.js';
@@ -17,21 +17,45 @@ describe('recalculate', function () {
const svg = document.createElementNS(NS.SVG, 'svg');
svgroot.append(svg);
const dataStorage = {
_storage: new WeakMap(),
put: function (element, key, obj) {
if (!this._storage.has(element)) {
this._storage.set(element, new Map());
}
this._storage.get(element).set(key, obj);
},
get: function (element, key) {
return this._storage.get(element).get(key);
},
has: function (element, key) {
return this._storage.has(element) && this._storage.get(element).has(key);
},
remove: function (element, key) {
var ret = this._storage.get(element).delete(key);
if (!this._storage.get(element).size === 0) {
this._storage.delete(element);
}
return ret;
}
};
let elemId = 1;
/**
* Initilize modules to set up the tests.
* @returns {void}
*/
function setUp () {
function setUp() {
utilities.init(
/**
* @implements {module:utilities.EditorContext}
*/
{
getSVGRoot () { return svg; },
getDOMDocument () { return null; },
getDOMContainer () { return null; }
getSVGRoot() { return svg; },
getDOMDocument() { return null; },
getDOMContainer() { return null; },
getDataStorage() { return dataStorage; }
}
);
coords.init(
@@ -39,12 +63,13 @@ describe('recalculate', function () {
* @implements {module:coords.EditorContext}
*/
{
getGridSnapping () { return false; },
getDrawing () {
getGridSnapping() { return false; },
getDrawing() {
return {
getNextId () { return String(elemId++); }
getNextId() { return String(elemId++); }
};
}
},
getDataStorage() { return dataStorage; }
}
);
recalculate.init(
@@ -52,9 +77,10 @@ describe('recalculate', function () {
* @implements {module:recalculate.EditorContext}
*/
{
getSVGRoot () { return svg; },
getStartTransform () { return ''; },
setStartTransform () { /* empty fn */ }
getSVGRoot() { return svg; },
getStartTransform() { return ''; },
setStartTransform() { /* empty fn */ },
getDataStorage() { return dataStorage; }
}
);
}
@@ -65,7 +91,7 @@ describe('recalculate', function () {
* Initialize for tests and set up `rect` element.
* @returns {void}
*/
function setUpRect () {
function setUpRect() {
setUp();
elem = document.createElementNS(NS.SVG, 'rect');
elem.setAttribute('x', '200');
@@ -79,7 +105,7 @@ describe('recalculate', function () {
* Initialize for tests and set up `text` element with `tspan` child.
* @returns {void}
*/
function setUpTextWithTspan () {
function setUpTextWithTspan() {
setUp();
elem = document.createElementNS(NS.SVG, 'text');
elem.setAttribute('x', '200');

View File

@@ -12,6 +12,28 @@ describe('select', function () {
const mockConfig = {
dimensions: [640, 480]
};
const dataStorage = {
_storage: new WeakMap(),
put: function (element, key, obj) {
if (!this._storage.has(element)) {
this._storage.set(element, new Map());
}
this._storage.get(element).set(key, obj);
},
get: function (element, key) {
return this._storage.get(element).get(key);
},
has: function (element, key) {
return this._storage.has(element) && this._storage.get(element).has(key);
},
remove: function (element, key) {
var ret = this._storage.get(element).delete(key);
if (!this._storage.get(element).size === 0) {
this._storage.delete(element);
}
return ret;
}
};
/**
* @implements {module:select.SVGFactory}
@@ -25,7 +47,8 @@ describe('select', function () {
return elem;
},
svgRoot () { return svgroot; },
svgContent () { return svgcontent; }
svgContent () { return svgcontent; },
getDataStorage () { return dataStorage; }
};
/**

View File

@@ -238,7 +238,7 @@ describe('utilities', function () {
attr: {id: 'roundrect', x: '0', y: '1', rx: '2', ry: '3', width: '10', height: '11'}
});
svgroot.append(elem);
const closeEnough = /M0,4 C0,2.3\d* 0.9\d*,1 2,1 L8,1 C9.0\d*,1 10,2.3\d* 10,4 L10,9 C10,10.6\d* 9.08675799086758,12 8,12 L2,12 C0.9\d*,12 0,10.6\d* 0,9 L0,4 Z/;
const closeEnough = /M0,13 C0,2.3\d* 0.9\d*,1 02,1 L8,1 C9.0\d*,1 10,2.3\d* 10,13 L10,9 C10,10.6\d* 9.08675799086758,12 8,12 L02,12 C0.9\d*,12 0,10.6\d* 0,9 L0,13 Z/;
assert.equal(closeEnough.test(getPathDFromElement(elem)), true);
elem.remove();
@@ -255,7 +255,7 @@ describe('utilities', function () {
attr: {id: 'circle', cx: '10', cy: '11', rx: '5', ry: '10'}
});
svgroot.append(elem);
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');
assert.equal(getPathDFromElement(elem), 'M5,11 C5,5.475138121546961 7.237569060773481,1 10,1 C102.7624309392265194,1 105,5.475138121546961 105,11 C105,115.524861878453039 102.7624309392265194,1110 10,1110 C7.237569060773481,1110 5,115.524861878453039 5,11 Z');
elem.remove();
elem = mockCreateSVGElement({