diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 20:45:11 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 20:45:11 +1000 |
commit | 25461a4733d7dcfc6f8127e8419f5eddbbb4b4aa (patch) | |
tree | 2b329ccdcd49d87f16170e3d374f82ff8d794083 | |
parent | 78d3ca83e3a7b74bdda246f78afdb26a19348668 (diff) | |
download | svg.js-25461a4733d7dcfc6f8127e8419f5eddbbb4b4aa.tar.gz svg.js-25461a4733d7dcfc6f8127e8419f5eddbbb4b4aa.zip |
added tests for ellipse
-rw-r--r-- | spec/spec/elements/Ellipse.js | 60 |
1 files changed, 60 insertions, 0 deletions
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)) + }) + }) + }) +}) |