summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-12 23:21:10 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-12 23:21:10 +0100
commit33e82b796e7870a9523b6e9653877a2613f8f7a2 (patch)
tree7450136c1178008d9ba17bc2408ee5f43c71e9c4 /spec
parent7b02d60829d1151a9fd1e726a0a995b92b165328 (diff)
downloadsvg.js-33e82b796e7870a9523b6e9653877a2613f8f7a2.tar.gz
svg.js-33e82b796e7870a9523b6e9653877a2613f8f7a2.zip
Release 3.0.53.0.5
Diffstat (limited to 'spec')
-rw-r--r--spec/SpecRunner.html2
-rw-r--r--spec/SpecRunnerEs6.html1
-rw-r--r--spec/runSVGDomTest.js3
-rw-r--r--spec/spec/elements/G.js139
4 files changed, 143 insertions, 2 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html
index da55e82..a1c6249 100644
--- a/spec/SpecRunner.html
+++ b/spec/SpecRunner.html
@@ -56,7 +56,7 @@
<!-- include spec files here... -->
- <!--<script src="es5TestBundle.js"></script>-->
+ <script src="es5TestBundle.js"></script>
<script src="spec/adopter.js"></script>
<script src="spec/arrange.js"></script>
diff --git a/spec/SpecRunnerEs6.html b/spec/SpecRunnerEs6.html
index cca33c0..3f8f90a 100644
--- a/spec/SpecRunnerEs6.html
+++ b/spec/SpecRunnerEs6.html
@@ -25,6 +25,7 @@
<script type="module" src="spec/types/Base.js"></script>
<script type="module" src="spec/types/Box.js"></script>
<script type="module" src="spec/utils/adopter.js"></script>
+ <script type="module" src="spec/elements/G.js"></script>
</body>
</html>
diff --git a/spec/runSVGDomTest.js b/spec/runSVGDomTest.js
index 0db744d..57055f4 100644
--- a/spec/runSVGDomTest.js
+++ b/spec/runSVGDomTest.js
@@ -12,7 +12,8 @@ jasmine.loadConfig({
"spec_dir": "spec/",
"spec_files": [
"spec/types/*.js",
- "spec/utils/*.js"
+ "spec/utils/*.js",
+ "spec/elements/*.js"
],
"helpers": [
"setupSVGDom.js"
diff --git a/spec/spec/elements/G.js b/spec/spec/elements/G.js
new file mode 100644
index 0000000..2c2efc8
--- /dev/null
+++ b/spec/spec/elements/G.js
@@ -0,0 +1,139 @@
+import { G, Rect, makeInstance } from '../../../src/main';
+
+const { any, createSpy, objectContaining } = jasmine
+
+
+describe('G.js', () => {
+
+ describe('()', () => {
+ it('creates a new object of type G', () => {
+ expect(new G()).toEqual(any(G))
+ })
+
+ it('sets passed attributes on the element', () => {
+ expect(new G({id:'foo'}).id()).toBe('foo')
+ })
+ })
+
+ describe('x()', () => {
+ it('gets the x value of the bbox', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.x()).toBe(g.bbox().x)
+ expect(g.x()).toBe(10)
+ })
+ it('sets the x value of the bbox by moving all children', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ 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)
+ })
+ })
+
+ describe('y()', () => {
+ it('gets the y value of the bbox', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.y()).toBe(g.bbox().y)
+ expect(g.y()).toBe(20)
+ })
+ it('sets the y value of the bbox by moving all children', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ 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)
+ })
+ })
+
+ describe('width()', () => {
+ it('gets the width value of the bbox', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.width()).toBe(g.bbox().width)
+ expect(g.width()).toBe(110)
+ })
+ it('sets the width value of the bbox by moving all children', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.width(100)).toBe(g)
+ expect(g.bbox().width).toBe(100)
+ 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)
+ })
+ })
+
+ describe('height()', () => {
+ it('gets the height value of the bbox', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.height()).toBe(g.bbox().height)
+ expect(g.height()).toBe(140)
+ })
+ it('sets the height value of the bbox by moving all children', () => {
+ const canvas = makeInstance().addTo('#canvas')
+
+ 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)
+
+ expect(g.height(100)).toBe(g)
+ expect(g.bbox().height).toBe(100)
+ 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)
+ })
+ })
+})