From: Ulrich-Matthias Schäfer Date: Thu, 9 Apr 2020 10:45:11 +0000 (+1000) Subject: added tests for ellipse X-Git-Tag: 3.1.0~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=25461a4733d7dcfc6f8127e8419f5eddbbb4b4aa;p=svg.js.git added tests for ellipse --- diff --git a/spec/spec/elements/Ellipse.js b/spec/spec/elements/Ellipse.js new file mode 100644 index 0000000..56e5d11 --- /dev/null +++ b/spec/spec/elements/Ellipse.js @@ -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)) + }) + }) + }) +})