aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-12 20:32:39 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-12 20:32:39 +0100
commit60792807eee29f1b748c9b12d308c477f7c1227d (patch)
tree27f5c46c02ea0acbec71668935ef72cf2749698e /spec
parentf5eff8745af43fcfcc2e837d89d549cb66220d99 (diff)
downloadsvg.js-60792807eee29f1b748c9b12d308c477f7c1227d.tar.gz
svg.js-60792807eee29f1b748c9b12d308c477f7c1227d.zip
Fix move and size of groups, removed setting of a default font so we dont act against user intention, fixed bug in `font()`
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/elements/G.js142
1 files changed, 126 insertions, 16 deletions
diff --git a/spec/spec/elements/G.js b/spec/spec/elements/G.js
index 2c2efc8..385419e 100644
--- a/spec/spec/elements/G.js
+++ b/spec/spec/elements/G.js
@@ -1,4 +1,4 @@
-import { G, Rect, makeInstance } from '../../../src/main';
+import { Box, G, Rect, makeInstance } from '../../../src/main.js';
const { any, createSpy, objectContaining } = jasmine
@@ -15,6 +15,68 @@ describe('G.js', () => {
})
})
+ describe('Container', () => {
+ describe('group()', () => {
+ it('creates a group in the container', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+ expect(g).toEqual(any(G))
+ expect(g.parent()).toBe(canvas)
+ })
+ })
+ })
+
+ describe('dmove()', () => {
+ it('moves the bbox of the group by a certain amount (1)', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+
+ g.add(new Rect({width:100, height:120, x:10, y:20}))
+ g.add(new Rect({width:70, height:100, x:50, y:60}))
+
+ g.dmove(10, 10)
+
+ const box = g.bbox()
+ expect(box).toEqual(objectContaining({
+ x: 20, y: 30, width: box.width, height: box.height
+ }))
+ })
+
+ it('moves the bbox of the group by a certain amount (2)', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+
+ g.rect(400, 200).move(123, 312).rotate(34).skew(12)
+ g.rect(100, 50).move(11, 43).translate(123, 32).skew(-12)
+ g.rect(400, 200).rotate(90)
+ g.group().rotate(23).group().skew(32).rect(100, 40).skew(11).rotate(12)
+
+ 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)
+ })
+ })
+
+ describe('move()', () => {
+ it('calls dmove() with the correct difference', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+ g.rect(100, 200).move(111, 223)
+
+ spyOn(g, 'dmove')
+
+ g.move(100, 150)
+ expect(g.dmove).toHaveBeenCalledWith(-11, -73)
+ })
+ })
+
describe('x()', () => {
it('gets the x value of the bbox', () => {
const canvas = makeInstance().addTo('#canvas')
@@ -28,19 +90,15 @@ describe('G.js', () => {
expect(g.x()).toBe(g.bbox().x)
expect(g.x()).toBe(10)
})
- it('sets the x value of the bbox by moving all children', () => {
+ it('calls move with the paramater as x', () => {
const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+ g.rect(100, 200).move(111, 223)
- const g = new G()
- g.add(new Rect({width:100, height:120, x:10, y:20}))
- g.add(new Rect({width:70, height:100, x:50, y:60}))
-
- g.addTo(canvas)
+ spyOn(g, 'move')
- expect(g.x(0)).toBe(g)
- expect(g.bbox().x).toBe(0)
- expect(g.children()[0].x()).toBe(0)
- expect(g.children()[1].x()).toBe(40)
+ g.x(100)
+ expect(g.move).toHaveBeenCalledWith(100, g.bbox().y, any(Box))
})
})
@@ -57,7 +115,20 @@ describe('G.js', () => {
expect(g.y()).toBe(g.bbox().y)
expect(g.y()).toBe(20)
})
- it('sets the y value of the bbox by moving all children', () => {
+ it('calls move with the paramater as y', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+ g.rect(100, 200).move(111, 223)
+
+ spyOn(g, 'move')
+
+ g.y(100)
+ expect(g.move).toHaveBeenCalledWith(g.bbox().x, 100, any(Box))
+ })
+ })
+
+ describe('size()', () => {
+ it('changes the dimensions of the bbox (1)', () => {
const canvas = makeInstance().addTo('#canvas')
const g = new G()
@@ -66,11 +137,50 @@ describe('G.js', () => {
g.addTo(canvas)
- expect(g.y(0)).toBe(g)
- expect(g.bbox().y).toBe(0)
- expect(g.children()[0].y()).toBe(0)
- expect(g.children()[1].y()).toBe(40)
+ const oldBox = g.bbox()
+
+ expect(g.size(100, 100)).toBe(g)
+
+ const newBox = g.bbox()
+
+ expect(newBox.x).toBeCloseTo(oldBox.x, 4)
+ expect(newBox.y).toBeCloseTo(oldBox.y, 4)
+ expect(newBox.w).toBeCloseTo(100, 4)
+ expect(newBox.h).toBeCloseTo(100, 4)
+
+ expect(g.children()[0].width()).toBeCloseTo(90.909, 3)
+ expect(g.children()[1].width()).toBeCloseTo(63.636, 3)
+
+ expect(g.children()[0].x()).toBeCloseTo(10, 3)
+ expect(g.children()[1].x()).toBeCloseTo(46.364, 3)
+ expect(g.children()[0].height()).toBeCloseTo(85.714, 3)
+ expect(g.children()[1].height()).toBeCloseTo(71.429, 3)
+ expect(g.children()[0].y()).toBeCloseTo(20, 3)
+ expect(g.children()[1].y()).toBeCloseTo(48.571, 3)
+ })
+
+ it('changes the dimensions of the bbox (2)', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const g = canvas.group()
+
+ g.rect(400, 200).move(123, 312).rotate(34).skew(12)
+ g.rect(100, 50).move(11, 43).translate(123, 32).skew(-12)
+ g.rect(400, 200).rotate(90)
+ g.group().rotate(23).group().skew(32).rect(100, 40).skew(11).rotate(12)
+
+ const oldBox = g.bbox()
+
+ g.size(100, 100)
+
+ const newBox = g.bbox()
+
+ expect(newBox.x).toBeCloseTo(oldBox.x, 4)
+ expect(newBox.y).toBeCloseTo(oldBox.y, 4)
+ expect(newBox.w).toBeCloseTo(100, 4)
+ expect(newBox.h).toBeCloseTo(100, 4)
})
+
+
})
describe('width()', () => {