summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-11 12:21:53 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-11 12:21:53 +1000
commitcaaeba44902e91451770d7513355ef70460db18d (patch)
tree54f54f77474ba8a6f5043878e71f9d8bacb5c281 /spec
parentd7b149afa7cde9e51ca74180b369b1e1b5770cf7 (diff)
downloadsvg.js-caaeba44902e91451770d7513355ef70460db18d.tar.gz
svg.js-caaeba44902e91451770d7513355ef70460db18d.zip
added tests for circled.js and gradiented.js
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/modules/core/circled.js98
-rw-r--r--spec/spec/modules/core/gradiented.js39
2 files changed, 137 insertions, 0 deletions
diff --git a/spec/spec/modules/core/circled.js b/spec/spec/modules/core/circled.js
new file mode 100644
index 0000000..f74332a
--- /dev/null
+++ b/spec/spec/modules/core/circled.js
@@ -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
index 0000000..ba159f5
--- /dev/null
+++ b/spec/spec/modules/core/gradiented.js
@@ -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)
+ })
+ })
+
+})