]> source.dussan.org Git - svg.js.git/commitdiff
added tests for ellipse
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 9 Apr 2020 10:45:11 +0000 (20:45 +1000)
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 9 Apr 2020 10:45:11 +0000 (20:45 +1000)
spec/spec/elements/Ellipse.js [new file with mode: 0644]

diff --git a/spec/spec/elements/Ellipse.js b/spec/spec/elements/Ellipse.js
new file mode 100644 (file)
index 0000000..56e5d11
--- /dev/null
@@ -0,0 +1,60 @@
+/* globals describe, expect, it, spyOn, jasmine, container */
+
+import { Ellipse, SVG, G } from '../../../src/main.js'
+
+const { any, objectContaining } = jasmine
+
+describe('Ellipse.js', () => {
+  describe('()', () => {
+    it('creates a new object of type Ellipse', () => {
+      expect(new Ellipse()).toEqual(any(Ellipse))
+    })
+
+    it('sets passed attributes on the element', () => {
+      expect(new Ellipse({ id: 'foo' }).id()).toBe('foo')
+    })
+  })
+
+  describe('size()', () => {
+    it('calls rx and ry with passed parameters and returns itself', () => {
+      const ellipse = new Ellipse()
+      const spyrx = spyOn(ellipse, 'rx').and.callThrough()
+      const spyry = spyOn(ellipse, 'ry').and.callThrough()
+      expect(ellipse.size(4, 2)).toBe(ellipse)
+      expect(spyrx).toHaveBeenCalledWith(objectContaining({ value: 2 }))
+      expect(spyry).toHaveBeenCalledWith(objectContaining({ value: 1 }))
+    })
+
+    it('changes ry proportionally if null', () => {
+      const canvas = SVG().addTo(container)
+      const ellipse = canvas.ellipse(100, 100)
+      const spyrx = spyOn(ellipse, 'rx').and.callThrough()
+      const spyry = spyOn(ellipse, 'ry').and.callThrough()
+      expect(ellipse.size(200, null)).toBe(ellipse)
+      expect(spyrx).toHaveBeenCalledWith(objectContaining({ value: 100 }))
+      expect(spyry).toHaveBeenCalledWith(objectContaining({ value: 100 }))
+    })
+
+    it('changes rx proportionally if null', () => {
+      const canvas = SVG().addTo(container)
+      const ellipse = canvas.ellipse(100, 100)
+      const spyrx = spyOn(ellipse, 'rx').and.callThrough()
+      const spyry = spyOn(ellipse, 'ry').and.callThrough()
+      expect(ellipse.size(null, 200)).toBe(ellipse)
+      expect(spyrx).toHaveBeenCalledWith(objectContaining({ value: 100 }))
+      expect(spyry).toHaveBeenCalledWith(objectContaining({ value: 100 }))
+    })
+  })
+
+  describe('Container', () => {
+    describe('ellipse()', () => {
+      it('creates a ellipse with given size', () => {
+        const group = new G()
+        const ellipse = group.ellipse(50, 50)
+        expect(ellipse.attr('rx')).toBe(25)
+        expect(ellipse.attr('ry')).toBe(25)
+        expect(ellipse).toEqual(any(Ellipse))
+      })
+    })
+  })
+})