UNPKG

2.08 kBJavaScriptView Raw
1import chai from 'chai';
2import chaiPassed from './helpers/chaiPassed';
3import Floor from '../src/Floor';
4import Level from '../src/Level';
5import Unit from '../src/units/Unit';
6import Warrior from '../src/units/Warrior';
7
8chai.should();
9chai.use(chaiPassed);
10
11describe('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});