1 | import chai from 'chai';
|
2 | import Turn from '../src/Turn';
|
3 | import Feel from '../src/abilities/senses/Feel';
|
4 |
|
5 | const should = chai.should();
|
6 |
|
7 | describe('Turn', function () {
|
8 | beforeEach(function () {
|
9 | this.feel = new Feel({});
|
10 | this.sinon.stub(this.feel, '_getSpace').returns({ toPlayerObject: () => null });
|
11 | this.turn = new Turn({
|
12 | 'walk': null,
|
13 | 'attack': null,
|
14 | 'feel': this.feel,
|
15 | });
|
16 | });
|
17 |
|
18 | describe('with actions', function () {
|
19 | it('should have no action performed at first', function () {
|
20 | should.equal(this.turn.action, null);
|
21 | });
|
22 |
|
23 | it('should be able to perform action and recall it', function () {
|
24 | this.turn.walk();
|
25 | this.turn.action.should.eql(['walk', []]);
|
26 | });
|
27 |
|
28 | it('should include arguments passed to action', function () {
|
29 | this.turn.walk('forward');
|
30 | this.turn.action.should.eql(['walk', ['forward']]);
|
31 | });
|
32 |
|
33 | it('should not be able to call multiple actions per turn', function () {
|
34 | this.turn.walk();
|
35 | this.turn.attack.bind(this.turn).should.throw(Error, 'Only one action can be performed per turn.');
|
36 | });
|
37 | });
|
38 |
|
39 | describe('with senses', function () {
|
40 | it('should be able to call multiple senses per turn', function () {
|
41 | this.turn.feel();
|
42 | this.turn.feel.bind(this.turn, 'backward').should.not.throw(Error);
|
43 | should.equal(this.turn.action, null);
|
44 | });
|
45 | });
|
46 |
|
47 | describe('player object', function () {
|
48 | beforeEach(function () {
|
49 | this.playerObject = this.turn.toPlayerObject();
|
50 | });
|
51 |
|
52 | it('should be able to call actions and senses', function () {
|
53 | this.playerObject.feel.bind(this.turn).should.not.throw(Error);
|
54 | this.playerObject.attack.bind(this.turn).should.not.throw(Error);
|
55 | });
|
56 |
|
57 | it('should not be able to access restricted properties', function () {
|
58 | should.equal(this.playerObject._addAction, undefined);
|
59 | should.equal(this.playerObject._addSense, undefined);
|
60 | should.equal(this.playerObject.action, undefined);
|
61 | should.equal(this.playerObject._action, undefined);
|
62 | should.equal(this.playerObject._senses, undefined);
|
63 | });
|
64 | });
|
65 | });
|