Skip to content

Commit

Permalink
test(shape): Covers shapes with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaiklor committed Nov 19, 2015
1 parent 777aa91 commit c374d15
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/unit/shapes/Rectangle.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
41 changes: 41 additions & 0 deletions test/unit/shapes/Text.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit c374d15

Please sign in to comment.