]> source.dussan.org Git - svg.js.git/commitdiff
added tests for circled.js and gradiented.js
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Sat, 11 Apr 2020 02:21:53 +0000 (12:21 +1000)
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Sat, 11 Apr 2020 02:21:53 +0000 (12:21 +1000)
spec/spec/modules/core/circled.js [new file with mode: 0644]
spec/spec/modules/core/gradiented.js [new file with mode: 0644]
src/modules/core/circled.js

diff --git a/spec/spec/modules/core/circled.js b/spec/spec/modules/core/circled.js
new file mode 100644 (file)
index 0000000..f74332a
--- /dev/null
@@ -0,0 +1,98 @@
+/* globals describe, expect, it, beforeEach, spyOn, jasmine, container */
+
+import { Ellipse, SVG } from '../../../../src/main.js'
+
+const { objectContaining } = jasmine
+
+describe('circled.js', () => {
+  let element
+
+  beforeEach(() => {
+    element = new Ellipse(50, 50)
+  })
+
+  describe('rx()', () => {
+    it('calls attribute with rx and returns itself', () => {
+      const spy = spyOn(element, 'attr').and.callThrough()
+      expect(element.rx(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith('rx', 50)
+    })
+  })
+
+  describe('ry()', () => {
+    it('calls attribute with ry and returns itself', () => {
+      const spy = spyOn(element, 'attr').and.callThrough()
+      expect(element.ry(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith('ry', 50)
+    })
+  })
+
+  describe('x()', () => {
+    it('sets x position and returns itself', () => {
+      element = SVG().addTo(container).ellipse(50, 50)
+      expect(element.x(50)).toBe(element)
+      expect(element.bbox().x).toBe(50)
+    })
+
+    it('gets the x position', () => {
+      element.x(50)
+      expect(element.x()).toBe(50)
+    })
+  })
+
+  describe('y()', () => {
+    it('sets y position and returns itself', () => {
+      element = SVG().addTo(container).ellipse(50, 50)
+      expect(element.y(50)).toBe(element)
+      expect(element.bbox().y).toBe(50)
+    })
+
+    it('gets the y position', () => {
+      element.y(50)
+      expect(element.y()).toBe(50)
+    })
+  })
+
+  describe('cx()', () => {
+    it('calls attribute with cx and returns itself', () => {
+      const spy = spyOn(element, 'attr').and.callThrough()
+      expect(element.cx(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith('cx', 50)
+    })
+  })
+
+  describe('cy()', () => {
+    it('calls attribute with cy and returns itself', () => {
+      const spy = spyOn(element, 'attr').and.callThrough()
+      expect(element.cy(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith('cy', 50)
+    })
+  })
+
+  describe('width()', () => {
+    it('sets rx by half the given width', () => {
+      const spy = spyOn(element, 'rx').and.callThrough()
+      expect(element.width(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith(objectContaining({ value: 25 }))
+    })
+
+    it('gets the width of the element', () => {
+      element.width(100)
+      expect(element.width()).toBe(100)
+    })
+  })
+
+  describe('height()', () => {
+    it('sets ry by half the given height', () => {
+      const spy = spyOn(element, 'ry').and.callThrough()
+      expect(element.height(50)).toBe(element)
+      expect(spy).toHaveBeenCalledWith(objectContaining({ value: 25 }))
+    })
+
+    it('gets the height of the element', () => {
+      element.height(100)
+      expect(element.height()).toBe(100)
+    })
+  })
+
+})
diff --git a/spec/spec/modules/core/gradiented.js b/spec/spec/modules/core/gradiented.js
new file mode 100644 (file)
index 0000000..ba159f5
--- /dev/null
@@ -0,0 +1,39 @@
+/* globals describe, expect, it */
+
+import { Gradient } from '../../../../src/main.js'
+
+describe('gradiented.js', () => {
+
+  describe('from()', () => {
+    it('sets fx and fy for radial gradients and returns itself', () => {
+      const gradient = new Gradient('radial')
+      expect(gradient.from(10, 20)).toBe(gradient)
+      expect(gradient.attr('fx')).toBe(10)
+      expect(gradient.attr('fy')).toBe(20)
+    })
+
+    it('sets x1 and y1 for linear gradients and returns itself', () => {
+      const gradient = new Gradient('linear')
+      expect(gradient.from(10, 20)).toBe(gradient)
+      expect(gradient.attr('x1')).toBe(10)
+      expect(gradient.attr('y1')).toBe(20)
+    })
+  })
+
+  describe('to()', () => {
+    it('sets cx and cy for radial gradients and returns itself', () => {
+      const gradient = new Gradient('radial')
+      expect(gradient.to(10, 20)).toBe(gradient)
+      expect(gradient.attr('cx')).toBe(10)
+      expect(gradient.attr('cy')).toBe(20)
+    })
+
+    it('sets x2 and y2 for linear gradients and returns itself', () => {
+      const gradient = new Gradient('linear')
+      expect(gradient.to(10, 20)).toBe(gradient)
+      expect(gradient.attr('x2')).toBe(10)
+      expect(gradient.attr('y2')).toBe(20)
+    })
+  })
+
+})
index 597d2524c722208e5b28ffb114d622ec4916486f..a03e29b0c3fbbc4a0f29ec4973f211b94e361364 100644 (file)
@@ -26,16 +26,12 @@ export function y (y) {
 
 // Move by center over x-axis
 export function cx (x) {
-  return x == null
-    ? this.attr('cx')
-    : this.attr('cx', x)
+  return this.attr('cx', x)
 }
 
 // Move by center over y-axis
 export function cy (y) {
-  return y == null
-    ? this.attr('cy')
-    : this.attr('cy', y)
+  return this.attr('cy', y)
 }
 
 // Set width of element