From 9a67cc3bbaf2e3f83368dc9706a06ec245a22c6a Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Wed, 8 Apr 2020 11:07:53 +1000 Subject: added tests for Circle --- spec/spec/elements/Circle.js | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 spec/spec/elements/Circle.js (limited to 'spec') diff --git a/spec/spec/elements/Circle.js b/spec/spec/elements/Circle.js new file mode 100644 index 0000000..e9b8b56 --- /dev/null +++ b/spec/spec/elements/Circle.js @@ -0,0 +1,66 @@ +/* globals describe, expect, it, beforeEach, spyOn, jasmine */ + +import { Circle, G } from '../../../src/main.js' + +const { any, objectContaining } = jasmine + +describe('Circle.js', () => { + let circle + + beforeEach(() => { + circle = new Circle() + }) + + describe('()', () => { + it('creates a new object of type Circle', () => { + expect(new Circle()).toEqual(any(Circle)) + }) + + it('sets passed attributes on the element', () => { + expect(new Circle({ id: 'foo' }).id()).toBe('foo') + }) + }) + + describe('radius()', () => { + it('calls attr with r', () => { + const spy = spyOn(circle, 'attr').and.callThrough() + circle.radius(123) + expect(spy).toHaveBeenCalledWith('r', 123) + }) + }) + + describe('rx()', () => { + it('calls attr with r', () => { + const spy = spyOn(circle, 'attr') + circle.rx(123) + expect(spy).toHaveBeenCalledWith('r', 123) + }) + }) + + describe('ry()', () => { + it('calls rx', () => { + const spy = spyOn(circle, 'rx') + circle.ry(123) + expect(spy).toHaveBeenCalledWith(123) + }) + }) + + describe('size()', () => { + it('calls radius with half of the size', () => { + const spy = spyOn(circle, 'radius') + circle.size(100) + expect(spy).toHaveBeenCalledWith(objectContaining({ value: 50 })) + }) + }) + + describe('Container', () => { + describe('circle()', () => { + it('creates a circle with given size', () => { + const group = new G() + const circle = group.circle(50) + expect(circle.attr('r')).toBe(25) + expect(circle).toEqual(any(Circle)) + }) + }) + }) +}) -- cgit v1.2.3