From 78799e40e160815248e1f786e214a835ebe8ffba Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 14 May 2012 17:40:11 -0700 Subject: [PATCH] more tests --- test/unit/gameSpec.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/test/unit/gameSpec.js b/test/unit/gameSpec.js index 13a497d..2a88e23 100644 --- a/test/unit/gameSpec.js +++ b/test/unit/gameSpec.js @@ -29,12 +29,13 @@ describe('Game', function() { beforeEach(function() { + // this is messy because Game constructor is non-deterministic - it should be refactored tile1a = game.grid[0][0]; - // this is weird because Game constructor is non-deterministic, this should be refactored if (tile1a.title === game.grid[0][1].title) { tile1b = game.grid[0][1]; tile2a = game.grid[1][0]; + tile2b = game.grid[1][1]; } else { tile2a = game.grid[0][1]; @@ -56,14 +57,6 @@ describe('Game', function() { }); - xit('should update the image name when a tile is flipped', function() { - expect(tile1a.imgName()).toBe('back'); - - game.flipTile(tile1a); - expect(tile1a.imgName()).not.toBe('back'); - }); - - it('should turn back first two cards when miss and third card is flipped', function() { game.flipTile(tile1a); game.flipTile(tile2a); @@ -102,5 +95,28 @@ describe('Game', function() { expect(tile2b.flipped).toBe(true); expect(game.unmatchedPairs).toBe(0); }); + + + it('should keep the message model up to date during the game', function() { + expect(game.message).toBe(Game.MESSAGE_CLICK); + + game.flipTile(tile1a); + expect(game.message).toBe(Game.MESSAGE_ONE_MORE); + + game.flipTile(tile2b); + expect(game.message).toBe(Game.MESSAGE_MISS); + + game.flipTile(tile1b); + expect(game.message).toBe(Game.MESSAGE_ONE_MORE); + + game.flipTile(tile1a); + expect(game.message).toBe(Game.MESSAGE_MATCH); + + game.flipTile(tile2b); + expect(game.message).toBe(Game.MESSAGE_ONE_MORE); + + game.flipTile(tile2a); + expect(game.message).toBe(Game.MESSAGE_WON); + }); }); });