-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(shape): Covers shapes with tests
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |