From c374d154079f466ac3194ac1fdfaff5e7dde7dfb Mon Sep 17 00:00:00 2001 From: ghaiklor Date: Thu, 19 Nov 2015 14:37:08 +0200 Subject: [PATCH] test(shape): Covers shapes with tests --- test/unit/shapes/Rectangle.test.js | 32 +++++++++++++++++++++++ test/unit/shapes/Text.test.js | 41 ++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/unit/shapes/Rectangle.test.js create mode 100644 test/unit/shapes/Text.test.js diff --git a/test/unit/shapes/Rectangle.test.js b/test/unit/shapes/Rectangle.test.js new file mode 100644 index 0000000..ffa6d6c --- /dev/null +++ b/test/unit/shapes/Rectangle.test.js @@ -0,0 +1,32 @@ +import { assert } from 'chai'; +import sinon from 'sinon'; +import { Rectangle } from '../../../src/shapes/Rectangle'; +import { Cursor } from '../../../src/cursor/Cursor'; + +describe('Shape::Rectangle', () => { + it('Should properly create instance', () => { + let rectangle = new Rectangle(); + assert.instanceOf(rectangle, Rectangle); + }); + + it('Should properly render with default options', () => { + let cursor = Cursor.create(); + let rectangle = new Rectangle(); + let mock = sinon.mock(cursor); + + mock.expects('fill').once().withArgs({ + x1: 10, + y1: 10, + x2: 25, + y2: 15, + background: undefined, + foreground: undefined + }); + mock.expects('write').once().withArgs(''); + mock.expects('setPosition').once().withArgs(18, 13).returns(cursor); + + rectangle.render(cursor); + + mock.verify(); + }); +}); diff --git a/test/unit/shapes/Text.test.js b/test/unit/shapes/Text.test.js new file mode 100644 index 0000000..6d72e17 --- /dev/null +++ b/test/unit/shapes/Text.test.js @@ -0,0 +1,41 @@ +import { assert } from 'chai'; +import sinon from 'sinon'; +import { Text } from '../../../src/shapes/Text'; +import { Cursor, COLORS } from '../../../src/cursor/Cursor'; + +describe('Shape::Text', () => { + it('Should properly create instance', () => { + let text = new Text(); + assert.instanceOf(text, Text); + }); + + it('Should properly render with default options', () => { + let cursor = Cursor.create(); + let text = new Text(); + let mock = sinon.mock(cursor); + + mock.expects('background').never(); + mock.expects('foreground').never(); + mock.expects('setPosition').once(10, 10); + mock.expects('write').once().withArgs(''); + + text.render(cursor); + + mock.verify(); + }); + + it('Should properly render with custom options', () => { + let cursor = Cursor.create(); + let text = Text.create({background: COLORS.YELLOW, foreground: COLORS.BLACK}).setPosition(20, 20).setText('test'); + let mock = sinon.mock(cursor); + + mock.expects('background').once().withArgs('yellow'); + mock.expects('foreground').once().withArgs('black'); + mock.expects('setPosition').once(20, 20); + mock.expects('write').once().withArgs('test'); + + text.render(cursor); + + mock.verify(); + }); +});