summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-06-27 11:57:42 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-06-27 11:57:42 +0200
commit37750c14d57eabe1d4692b5ec3db431f4cfc9fcb (patch)
tree54ad812f2b64614a4897228b411846ae720e904f /spec
parent1a9bfbc6688edaea47f0b011993c1ca2b6509514 (diff)
downloadsvg.js-37750c14d57eabe1d4692b5ec3db431f4cfc9fcb.tar.gz
svg.js-37750c14d57eabe1d4692b5ec3db431f4cfc9fcb.zip
fixing dmove for nested svgs (https://github.com/svgdotjs/svg.draggable.js/issues/127)
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/modules/core/containerGeometry.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/spec/modules/core/containerGeometry.js b/spec/spec/modules/core/containerGeometry.js
index 011d9a8..2bb2fca 100644
--- a/spec/spec/modules/core/containerGeometry.js
+++ b/spec/spec/modules/core/containerGeometry.js
@@ -47,6 +47,60 @@ describe('containerGeometry.js', () => {
expect(newBox.h).toBeCloseTo(oldBox.h, 4)
})
+ it('moves nested svgs in a group correctly when calling dmove', () => {
+ const canvas = SVG().addTo(container)
+ const g = canvas.group()
+ const s1 = g.nested().size(100, 100).move(100, 100)
+ s1.rect(100, 100).move(50, 50).rotate(10)
+
+ const oldBox = g.bbox()
+
+ g.dmove(10, 10)
+
+ const newBox = g.bbox()
+
+ expect(newBox.x).toBeCloseTo(oldBox.x + 10, 4)
+ expect(newBox.y).toBeCloseTo(oldBox.y + 10, 4)
+ expect(newBox.w).toBeCloseTo(oldBox.w, 4)
+ expect(newBox.h).toBeCloseTo(oldBox.h, 4)
+ })
+
+ it('moves nested svgs in a group correctly when calling dmove (2)', () => {
+ const canvas = SVG().addTo(container)
+ const g = canvas.group()
+ const s1 = g.nested().move(100, 100)
+ s1.rect(100, 100).move(50, 50).rotate(10)
+
+ const oldBox = g.bbox()
+
+ g.dmove(10, 10)
+
+ const newBox = g.bbox()
+
+ expect(newBox.x).toBeCloseTo(oldBox.x + 10, 4)
+ expect(newBox.y).toBeCloseTo(oldBox.y + 10, 4)
+ expect(newBox.w).toBeCloseTo(oldBox.w, 4)
+ expect(newBox.h).toBeCloseTo(oldBox.h, 4)
+ })
+
+ it('moves nested svgs in a group correctly when calling dmove (3)', () => {
+ const canvas = SVG().addTo(container)
+ const g = canvas.group()
+ const s1 = g.nested()
+ s1.rect(100, 100).move(50, 50).rotate(10)
+
+ const oldBox = g.bbox()
+
+ g.dmove(10, 10)
+
+ const newBox = g.bbox()
+
+ expect(newBox.x).toBeCloseTo(oldBox.x + 10, 4)
+ expect(newBox.y).toBeCloseTo(oldBox.y + 10, 4)
+ expect(newBox.w).toBeCloseTo(oldBox.w, 4)
+ expect(newBox.h).toBeCloseTo(oldBox.h, 4)
+ })
+
it('it does not fail when hitting elements without bbox', () => {
const canvas = SVG().addTo(container)
const g = canvas.group()