Files
svgedit/cypress/integration/unit/svgtransformlist.js
JFH 1af0cd0572 V7 preview (#480)
* #issue-fix The new menu will ask if you want to erase the current content but it will ignore the answer

* #issue-fix  dialog needs to be closer than the original

* #issue-fix main menu alignment changes

* #issue_fix double click and opensvg issue fixed

* #issue-fix process_cancel change to seConfirm

* #issue-fix review how the top toolbar display when many buttons are displayed

* #issue-fix unwanted css reoved

* #issue-fix BOTTOM TOOLS Make sure all features of the bottom toolbar are working

* #issue-fix IMPORT IMAGE menu open issue fixed

* #issue-fix alert dialog overwrite style

* #issue-fix lint issue fixed

* npm update + associated fixes

* #36 look of opacity button should like the zoom button (without the dropdown button)

* #37 Clicking anywhere on the bottom bar (for example below the opacity button is displaying the “color popup”.)

* #38 The opacity button does not update with the current element

* #42 When you import an image, it works well but the dialog should disappear automatically

* Fixes #53: 4th option for the background display fixed

* Fixes #53: 4th option for the background fixed

* #49 the x button does not work

* Fixes #41: Alignment fixes in bottom bar

* fix test scenario

* #39 opacity button/stroke size/radius button don’t allow the 0 value

* #41 The look and alignment of stroke size and stroke style should be consistent with the rest of the bottom bar.

* #44 Text font dropdown is broken

* #52 Fix the export

* Fixes #44: Text font dropdown fixed

* Fixes #44: Text font dropdown fixed

* Fixes #44: Text font dropdown fixed

* Fixes #44: Text font dropdown fixed

* Update index.html

* update husky

* fixes

* moves from index.html to js

* fix #66

* fix #48 first set of new icons

* Reorganize tools in left panel to be more intuitive

* Update button styles to adapt to new icons

* Fix #48 new set of icons for alignments

* Variabilisation of icon bkgd colors
Update of color choice to fit new icons design

* Update canvas and rulers colors

* Improve layer handle design

* Modernize SVG Logo but keeping original spirit

* Fix #48 continue improve icons

* Continue to reorganise left panel

* Update right panel handle for layers

* Fix #48 new set of icons for main menu

* Improve main menu design

* Rework menu organisation

* Rework menu organisation

* Update input element design

* New icons

* Improve Zoom Module

* Improve Color Picker Module

* New icons

* New icons

* #65 restore the feature of start/end marker lines partially did

* #64 The export dialog needs to include the quality options (except for PDF)

* #39 opacity button/stroke size/radius button don’t allow the 0 value

* #39 eslint changes

* #69 menu button style overwrite

* #65 restore the feature of start/end marker lines

* #43 With a small window, the look of the top toolbar is broken

* #43 tool top alignment revert

* #46 Move this jQuery component to a web component  for graduate and picker components

* #46 Move this jQuery component to a web component

* remove some non standard lint rules

* #46 picker convert as pure javascript changes

* #46 jquery plugin convert to pure javascript

* #46 jquery plugin change to pure javascript

* #46 jquery remove and convert to pure javascript

* #46 slider issue fixed

* #46 ColorValuePicker and js convertion

* #46 globals $ remov from slider class

* #46 jquery convert pure javascript changes

* #46 jquery to js convertion changes

* #46 paintbox and current element color set issue fixed

* #46 unwanted files removed

* #46 $.extend modify changes

* #46 extend modifiey changes

* #46 $.extend change to pure javascript

* #46 extend and data changes

* #46 jquery removed

* #45 These buttons don't work and dropdown is broken

* #45 These buttons don't work and dropdown is broken

* #45 These buttons don't work and dropdown is broken commit reverted

* #43 With a small window, the look of the top toolbar is broken

* Update jQuery.jPicker.js

* #76 draggable modification changes

* #76 jquery-ui-1.8.17.custom.min.js removed from editor

* #76 jquery ui file removed

* npm update

* #77 console issue fixed

* #77 <SVG> button issue fixed

* #77 shortkey issue fixed

* #77 jquery hotkeys plugin changes

* #77 hotkey plugin related changes

* #78 hotkey related code comment.

* #78 js-hotkeys/jquery.hotkeys.min.js file removed from svgedit.js

* #51 Rewrite the color palette without elix

* #81 unwanted files removed

* #81 folder name renamed

* #81 folder rename changes

* #81 jquery-ui  folder renamed

* #81 jquery modify changes

* #81 globals $ removed

Co-authored-by: Agriya Dev5 <agriya.dev5@agriya.in>
Co-authored-by: mathieucura <mathieu@optimistik.fr>
2021-03-05 12:45:07 +01:00

333 lines
11 KiB
JavaScript

import '../../../instrumented/editor/jquery.min.js';
import {NS} from '../../../instrumented/common/namespaces.js';
import * as transformlist from '../../../instrumented/svgcanvas/svgtransformlist.js';
import {disableSupportsNativeTransformLists} from '../../../instrumented/common/browser.js';
import almostEqualsPlugin from '../../support/assert-almostEquals.js';
import expectOutOfBoundsExceptionPlugin from '../../support/assert-expectOutOfBoundsException.js';
chai.use(almostEqualsPlugin);
chai.use(expectOutOfBoundsExceptionPlugin);
describe('svgtransformlist', function () {
disableSupportsNativeTransformLists();
let svgroot, svgcontent, rect, circle;
/**
* Set up tests, adding elements.
* @returns {void}
*/
beforeEach(() => {
document.body.textContent = '';
svgroot = document.createElement('div');
svgroot.id = 'svgroot';
svgroot.style.visibility = 'hidden';
document.body.append(svgroot);
svgcontent = document.createElementNS(NS.SVG, 'svg');
svgroot.append(svgcontent);
rect = document.createElementNS(NS.SVG, 'rect');
svgcontent.append(rect);
rect.id = 'r';
circle = document.createElementNS(NS.SVG, 'circle');
svgcontent.append(circle);
circle.id = 'c';
});
/**
* Tear down tests, emptying SVG root, and resetting list map.
* @returns {void}
*/
afterEach(() => {
transformlist.resetListMap();
while (svgroot.hasChildNodes()) {
svgroot.firstChild.remove();
}
});
it('Test svgedit.transformlist package', function () {
assert.ok(transformlist);
assert.ok(transformlist.getTransformList);
});
it('Test svgedit.transformlist.getTransformList() function', function () {
const rxform = transformlist.getTransformList(rect);
const cxform = transformlist.getTransformList(circle);
assert.ok(rxform);
assert.ok(cxform);
assert.equal(typeof rxform, typeof {});
assert.equal(typeof cxform, typeof {});
});
it('Test SVGTransformList.numberOfItems property', function () {
const rxform = transformlist.getTransformList(rect);
assert.equal(typeof rxform.numberOfItems, typeof 0);
assert.equal(rxform.numberOfItems, 0);
});
it('Test SVGTransformList.initialize()', function () {
const rxform = transformlist.getTransformList(rect);
const cxform = transformlist.getTransformList(circle);
const t = svgcontent.createSVGTransform();
assert.ok(t);
assert.ok(rxform.initialize);
assert.equal(typeof rxform.initialize, typeof function () { /* empty fn */ });
rxform.initialize(t);
assert.equal(rxform.numberOfItems, 1);
assert.equal(cxform.numberOfItems, 0);
// If a transform was already in a transform list, this should
// remove it from its old list and add it to this list.
cxform.initialize(t);
// This also fails in Firefox native.
// assert.equal(rxform.numberOfItems, 0, 'Did not remove transform from list before initializing another transformlist');
assert.equal(cxform.numberOfItems, 1);
});
it('Test SVGTransformList.appendItem() and getItem()', function () {
const rxform = transformlist.getTransformList(rect);
const cxform = transformlist.getTransformList(circle);
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
assert.ok(rxform.appendItem);
assert.ok(rxform.getItem);
assert.equal(typeof rxform.appendItem, typeof function () { /* empty fn */ });
assert.equal(typeof rxform.getItem, typeof function () { /* empty fn */ });
rxform.appendItem(t1);
rxform.appendItem(t2);
rxform.appendItem(t3);
assert.equal(rxform.numberOfItems, 3);
const rxf = rxform.getItem(0);
assert.equal(rxf, t1);
assert.equal(rxform.getItem(1), t2);
assert.equal(rxform.getItem(2), t3);
assert.expectOutOfBoundsException(rxform, 'getItem', -1);
assert.expectOutOfBoundsException(rxform, 'getItem', 3);
cxform.appendItem(t1);
// These also fail in Firefox native.
// assert.equal(rxform.numberOfItems, 2, 'Did not remove a transform from a list before appending it to a new transformlist');
// assert.equal(rxform.getItem(0), t2, 'Found the wrong transform in a transformlist');
// assert.equal(rxform.getItem(1), t3, 'Found the wrong transform in a transformlist');
assert.equal(cxform.numberOfItems, 1);
assert.equal(cxform.getItem(0), t1);
});
it('Test SVGTransformList.removeItem()', function () {
const rxform = transformlist.getTransformList(rect);
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform();
assert.ok(rxform.removeItem);
assert.equal(typeof rxform.removeItem, typeof function () { /* empty fn */ });
rxform.appendItem(t1);
rxform.appendItem(t2);
const removedTransform = rxform.removeItem(0);
assert.equal(rxform.numberOfItems, 1);
assert.equal(removedTransform, t1);
assert.equal(rxform.getItem(0), t2);
assert.expectOutOfBoundsException(rxform, 'removeItem', -1);
assert.expectOutOfBoundsException(rxform, 'removeItem', 1);
});
it('Test SVGTransformList.replaceItem()', function () {
const rxform = transformlist.getTransformList(rect);
const cxform = transformlist.getTransformList(circle);
assert.ok(rxform.replaceItem);
assert.equal(typeof rxform.replaceItem, typeof function () { /* empty fn */ });
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
const newItem = rxform.replaceItem(t3, 0);
assert.equal(rxform.numberOfItems, 2);
assert.equal(newItem, t3);
assert.equal(rxform.getItem(0), t3);
assert.equal(rxform.getItem(1), t2);
// Fails in Firefox native
// assert.equal(cxform.numberOfItems, 0);
// test replaceItem within a list
rxform.appendItem(t1);
rxform.replaceItem(t1, 0);
// Fails in Firefox native
// assert.equal(rxform.numberOfItems, 2);
assert.equal(rxform.getItem(0), t1);
assert.equal(rxform.getItem(1), t2);
});
it('Test SVGTransformList.insertItemBefore()', function () {
const rxform = transformlist.getTransformList(rect);
const cxform = transformlist.getTransformList(circle);
assert.ok(rxform.insertItemBefore);
assert.equal(typeof rxform.insertItemBefore, typeof function () { /* empty fn */ });
const t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
const newItem = rxform.insertItemBefore(t3, 0);
assert.equal(rxform.numberOfItems, 3);
assert.equal(newItem, t3);
assert.equal(rxform.getItem(0), t3);
assert.equal(rxform.getItem(1), t1);
assert.equal(rxform.getItem(2), t2);
// Fails in Firefox native
// assert.equal(cxform.numberOfItems, 0);
rxform.insertItemBefore(t2, 1);
// Fails in Firefox native (they make copies of the transforms)
// assert.equal(rxform.numberOfItems, 3);
assert.equal(rxform.getItem(0), t3);
assert.equal(rxform.getItem(1), t2);
assert.equal(rxform.getItem(2), t1);
});
it('Test SVGTransformList.init() for translate(200,100)', function () {
rect.setAttribute('transform', 'translate(200,100)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const translate = rxform.getItem(0);
assert.equal(translate.type, 2);
const m = translate.matrix;
assert.equal(m.a, 1);
assert.equal(m.b, 0);
assert.equal(m.c, 0);
assert.equal(m.d, 1);
assert.equal(m.e, 200);
assert.equal(m.f, 100);
});
it('Test SVGTransformList.init() for scale(4)', function () {
rect.setAttribute('transform', 'scale(4)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const scale = rxform.getItem(0);
assert.equal(scale.type, 3);
const m = scale.matrix;
assert.equal(m.a, 4);
assert.equal(m.b, 0);
assert.equal(m.c, 0);
assert.equal(m.d, 4);
assert.equal(m.e, 0);
assert.equal(m.f, 0);
});
it('Test SVGTransformList.init() for scale(4,3)', function () {
rect.setAttribute('transform', 'scale(4,3)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const scale = rxform.getItem(0);
assert.equal(scale.type, 3);
const m = scale.matrix;
assert.equal(m.a, 4);
assert.equal(m.b, 0);
assert.equal(m.c, 0);
assert.equal(m.d, 3);
assert.equal(m.e, 0);
assert.equal(m.f, 0);
});
it('Test SVGTransformList.init() for rotate(45)', function () {
rect.setAttribute('transform', 'rotate(45)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const rotate = rxform.getItem(0);
assert.equal(rotate.type, 4);
assert.equal(rotate.angle, 45);
const m = rotate.matrix;
assert.almostEquals(1 / Math.sqrt(2), m.a);
assert.almostEquals(1 / Math.sqrt(2), m.b);
assert.almostEquals(-1 / Math.sqrt(2), m.c);
assert.almostEquals(1 / Math.sqrt(2), m.d);
assert.equal(m.e, 0);
assert.equal(m.f, 0);
});
it('Test SVGTransformList.init() for rotate(45, 100, 200)', function () {
rect.setAttribute('transform', 'rotate(45, 100, 200)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const rotate = rxform.getItem(0);
assert.equal(rotate.type, 4);
assert.equal(rotate.angle, 45);
const m = rotate.matrix;
assert.almostEquals(m.a, 1 / Math.sqrt(2));
assert.almostEquals(m.b, 1 / Math.sqrt(2));
assert.almostEquals(m.c, -1 / Math.sqrt(2));
assert.almostEquals(m.d, 1 / Math.sqrt(2));
const r = svgcontent.createSVGMatrix();
r.a = 1 / Math.sqrt(2); r.b = 1 / Math.sqrt(2);
r.c = -1 / Math.sqrt(2); r.d = 1 / Math.sqrt(2);
const t = svgcontent.createSVGMatrix();
t.e = -100; t.f = -200;
const t_ = svgcontent.createSVGMatrix();
t_.e = 100; t_.f = 200;
const result = t_.multiply(r).multiply(t);
assert.almostEquals(m.e, result.e);
assert.almostEquals(m.f, result.f);
});
it('Test SVGTransformList.init() for matrix(1, 2, 3, 4, 5, 6)', function () {
rect.setAttribute('transform', 'matrix(1,2,3,4,5,6)');
const rxform = transformlist.getTransformList(rect);
assert.equal(rxform.numberOfItems, 1);
const mt = rxform.getItem(0);
assert.equal(mt.type, 1);
const m = mt.matrix;
assert.equal(m.a, 1);
assert.equal(m.b, 2);
assert.equal(m.c, 3);
assert.equal(m.d, 4);
assert.equal(m.e, 5);
assert.equal(m.f, 6);
});
});