From 6c708ed9748005a711a935a8e3ead5613b73dfd0 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Sun, 29 Aug 2021 16:05:21 +0200 Subject: [PATCH] update tests --- .../ui/__snapshots__/scenario2.js.snap | 140 ++++++++-------- .../ui/__snapshots__/scenario4.js.snap | 158 +++++++++--------- .../ui/__snapshots__/scenario5.js.snap | 88 +++++----- cypress/integration/unit/utilities.js | 11 -- src/svgcanvas/undo.js | 16 +- src/svgcanvas/utilities.js | 9 +- 6 files changed, 198 insertions(+), 224 deletions(-) diff --git a/cypress/integration/ui/__snapshots__/scenario2.js.snap b/cypress/integration/ui/__snapshots__/scenario2.js.snap index 241be924..ce009cdd 100644 --- a/cypress/integration/ui/__snapshots__/scenario2.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario2.js.snap @@ -331,68 +331,6 @@ exports[`use all parts of svg-edit > check tool_ellipse_change_rotation #0`] = ` `; -exports[`use all parts of svg-edit > check tool_ellipse_change_blur #0`] = ` - - - Layer 1 - - - - - - - - - - -`; - exports[`use all parts of svg-edit > check tool_ellipse_change_cx_cy_coordinate #0`] = ` check tool_ellipse_change_cx_cy_coordinate > - - + + @@ -510,8 +448,8 @@ exports[`use all parts of svg-edit > check tool_ellipse_change_rx_ry_radius #0`] > - - + + @@ -572,8 +510,8 @@ exports[`use all parts of svg-edit > check tool_ellipse_bring_to_back #0`] = ` > - - + + @@ -634,8 +572,8 @@ exports[`use all parts of svg-edit > check tool_ellipse_bring_to_front #0`] = ` > - - + + @@ -708,6 +646,68 @@ exports[`use all parts of svg-edit > check tool_ellipse_clone #0`] = ` id="svg_4" > + + + + + + +`; + +exports[`use all parts of svg-edit > check tool_ellipse_change_blur #0`] = ` + + + Layer 1 + + + + diff --git a/cypress/integration/ui/__snapshots__/scenario4.js.snap b/cypress/integration/ui/__snapshots__/scenario4.js.snap index 57e732f8..3bad2580 100644 --- a/cypress/integration/ui/__snapshots__/scenario4.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario4.js.snap @@ -280,69 +280,6 @@ exports[`use all parts of svg-edit > check tool_rect_change_rotation #0`] = ` `; -exports[`use all parts of svg-edit > check tool_rect_change_blur #0`] = ` - - - Layer 1 - - - - - - - - - - -`; - exports[`use all parts of svg-edit > check tool_rect_change_opacity #0`] = ` check tool_rect_change_opacity #0`] = ` > - - + + @@ -463,8 +400,8 @@ exports[`use all parts of svg-edit > check tool_fhrect_change_x_y_coordinate #0` > - - + + @@ -526,8 +463,8 @@ exports[`use all parts of svg-edit > check tool_fhrect_change_width_height #0`] > - - + + @@ -600,8 +537,8 @@ exports[`use all parts of svg-edit > check tool_square_clone #0`] = ` > - - + + @@ -674,8 +611,8 @@ exports[`use all parts of svg-edit > check tool_square_bring_to_back #0`] = ` > - - + + @@ -748,8 +685,8 @@ exports[`use all parts of svg-edit > check tool_square_bring_to_front #0`] = ` > - - + + @@ -824,8 +761,8 @@ exports[`use all parts of svg-edit > check tool_square_change_corner_radius #0`] > - - + + @@ -898,8 +835,8 @@ exports[`use all parts of svg-edit > check tool_rect_change_to_path #0`] = ` > - - + + @@ -944,6 +881,69 @@ exports[`use all parts of svg-edit > check tool_rect_delete #0`] = ` ry="25" > + + + + + + +`; + +exports[`use all parts of svg-edit > check tool_rect_change_blur #0`] = ` + + + Layer 1 + + + + diff --git a/cypress/integration/ui/__snapshots__/scenario5.js.snap b/cypress/integration/ui/__snapshots__/scenario5.js.snap index 947b63a5..ab0a001c 100644 --- a/cypress/integration/ui/__snapshots__/scenario5.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario5.js.snap @@ -84,44 +84,6 @@ exports[`use all parts of svg-edit > check tool_line_change_rotation #0`] = ` `; -exports[`use all parts of svg-edit > check tool_line_change_blur #0`] = ` - - - Layer 1 - - - - - - - - -`; - exports[`use all parts of svg-edit > check tool_line_change_opacity #0`] = ` check tool_line_change_opacity #0`] = ` > - - + + @@ -177,8 +139,8 @@ exports[`use all parts of svg-edit > check tool_line_delete #0`] = ` Layer 1 - - + + @@ -245,8 +207,8 @@ exports[`use all parts of svg-edit > check tool_line_clone #0`] = ` - - + + @@ -303,6 +265,44 @@ exports[`use all parts of svg-edit > check tool_fhrect_change_x_y_coordinate #0` > + + + + + + +`; + +exports[`use all parts of svg-edit > check tool_line_change_blur #0`] = ` + + + Layer 1 + + diff --git a/cypress/integration/unit/utilities.js b/cypress/integration/unit/utilities.js index aa70e571..daa7e8db 100644 --- a/cypress/integration/unit/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -113,17 +113,6 @@ describe('utilities', function () { assert.equal(toXml('\'<&>"'), ''<&>"'); }); - it('Test svgedit.utilities.fromXml() function', function () { - const { fromXml } = utilities; - - 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('<&>'), '<&>'); - }); - it('Test svgedit.utilities.encode64() function', function () { const { encode64 } = utilities; diff --git a/src/svgcanvas/undo.js b/src/svgcanvas/undo.js index 54588398..00d0d3ae 100644 --- a/src/svgcanvas/undo.js +++ b/src/svgcanvas/undo.js @@ -81,20 +81,6 @@ export const getUndoManager = function () { if (values.stdDeviation) { undoContext_.getCanvas().setBlurOffsets(cmd.elem.parentNode, values.stdDeviation); } - // This is resolved in later versions of webkit, perhaps we should - // have a featured detection for correct 'use' behavior? - // —————————— - // Remove & Re-add hack for Webkit (issue 775) - // if (cmd.elem.tagName === 'use' && isWebkit()) { - // const {elem} = cmd; - // if (!elem.getAttribute('x') && !elem.getAttribute('y')) { - // const parent = elem.parentNode; - // const sib = elem.nextSibling; - // elem.remove(); - // parent.insertBefore(elem, sib); - // // Ok to replace above with this? `sib.before(elem);` - // } - // } if (cmd.elem.tagName === 'text'){ const [ dx, dy ] = [ cmd.newValues.x - cmd.oldValues.x, cmd.newValues.y - cmd.oldValues.y ]; @@ -248,7 +234,7 @@ export const changeSelectedAttributeNoUndoMethod = function (attr, newValue, ele // we need to update the rotational transform attribute const angle = getRotationAngle(elem); if (angle !== 0 && attr !== 'transform') { - const tlist = elem.transform.baseVal; + const tlist = elem.transform?.baseVal; let n = tlist.numberOfItems; while (n--) { const xform = tlist.getItem(n); diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index df0c6146..e6348d9b 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -1147,10 +1147,9 @@ export const getStrokedBBoxDefaultVisible = function (elems) { * @param {boolean} toRad - When true returns the value in radians rather than degrees * @returns {Float} The angle in degrees or radians */ -export const getRotationAngleFromTransformList = function (tlist, toRad) { - if (!tlist) { return 0; } // elements have no tlist - const N = tlist.numberOfItems; - for (let i = 0; i < N; ++i) { +export const getRotationAngleFromTransformList = (tlist, toRad) => { + if (!tlist) { return 0; } // element have no tlist + for (let i = 0; i < tlist.numberOfItems; ++i) { const xform = tlist.getItem(i); if (xform.type === 4) { return toRad ? xform.angle * Math.PI / 180.0 : xform.angle; @@ -1169,7 +1168,7 @@ export const getRotationAngleFromTransformList = function (tlist, toRad) { export let getRotationAngle = function (elem, toRad) { const selected = elem || editorContext_.getSelectedElements()[0]; // find the rotation transform (if any) and set it - const tlist = selected.transform.baseVal; + const tlist = selected.transform?.baseVal; return getRotationAngleFromTransformList(tlist, toRad); };