1 | import chai from 'chai';
|
2 | import chaiPassed from './helpers/chaiPassed';
|
3 | import Floor from '../src/Floor';
|
4 | import Level from '../src/Level';
|
5 | import Unit from '../src/units/Unit';
|
6 | import Warrior from '../src/units/Warrior';
|
7 |
|
8 | chai.should();
|
9 | chai.use(chaiPassed);
|
10 |
|
11 | describe('Level', function () {
|
12 | beforeEach(function () {
|
13 | this.floor = new Floor(0, 0);
|
14 | this.level = new Level();
|
15 | this.level.floor = this.floor;
|
16 | this.sinon.stub(this.level, '_failed').returns(false);
|
17 | this.level.warrior = { score: () => null };
|
18 | });
|
19 |
|
20 | it('should consider passed when warrior is on stairs', function () {
|
21 | this.level.warrior = new Warrior();
|
22 | this.floor.addUnit(this.level.warrior, 0, 0, 'north');
|
23 | this.floor.placeStairs(0, 0);
|
24 | this.level.should.be.passed;
|
25 | });
|
26 |
|
27 | it('should default time bonus to zero', function () {
|
28 | this.level.timeBonus.should.equal(0);
|
29 | });
|
30 |
|
31 | describe('playing', function () {
|
32 | it('should call prepareTurn and playTurn on each unit specified number of times', function () {
|
33 | const unit = new Unit();
|
34 | const mock = this.sinon.mock(unit);
|
35 | const expectationOne = mock.expects('prepareTurn').twice();
|
36 | const expectationTwo = mock.expects('performTurn').twice();
|
37 | this.floor.addUnit(unit, 0, 0, 'north');
|
38 | this.level.play(2);
|
39 | expectationOne.verify();
|
40 | expectationTwo.verify();
|
41 | });
|
42 |
|
43 | it('should return immediately when passed', function () {
|
44 | const unit = new Unit();
|
45 | const expectation = this.sinon.mock(unit).expects('performTurn').never();
|
46 | this.floor.addUnit(unit, 0, 0, 'north');
|
47 | this.sinon.stub(this.level, '_passed').returns(true);
|
48 | this.level.play(2);
|
49 | expectation.verify();
|
50 | });
|
51 |
|
52 | it('should count down time bonus once each turn', function () {
|
53 | this.level.timeBonus = 10;
|
54 | this.level.play(3);
|
55 | this.level.timeBonus.should.equal(7);
|
56 | });
|
57 |
|
58 | it('should not count down time bonus below 0', function () {
|
59 | this.level.timeBonus = 2;
|
60 | this.level.play(5);
|
61 | this.level.timeBonus.should.equal(0);
|
62 | });
|
63 | });
|
64 | });
|