'use strict';

describe('game', function () {
    var scope, $httpBackend;

    var cardName = 'King';
    var cardColor = 'Red';

    var createGameUrl = '/aot/rest/createGame';
    var createGameMethod = 'POST';
    var viewPossibleMovementsUrl = '/aot/rest/getPossibleSquares?card_color=' + cardColor + '&card_name=' + cardName;
    var viewPossibleMovementsMethod = 'GET';
    var playUrl = '/aot/rest/play';
    var playMethod = 'GET';

    beforeEach(angular.mock.module('lastLine'));

    beforeEach(angular.mock.inject(function ($rootScope, $controller, _$httpBackend_) {
        $httpBackend = _$httpBackend_;

        $httpBackend.when(createGameMethod, createGameUrl)
                .respond({
                    nextPlayer: {
                        name: "Toto",
                        id: "0"
                    },
                    possibleCardsNextPlayer: [
                        {
                            name: "King",
                            color: "Red"
                        }
                    ]
                });

        $httpBackend.when(viewPossibleMovementsMethod, viewPossibleMovementsUrl)
                .respond(["square-0-0", "square-1-1"]);

        $httpBackend.when(playMethod, playUrl)
                .respond({
                    "newSquare": "#0-8",
                    "nextPlayer": {
                        "name": "Toto",
                        "id": "0"
                    },
                    "possibleCardsNextPlayer": [
                        {
                            "name": "King",
                            "color": "Red"
                        }
                    ]
                });

        scope = $rootScope.$new();
        $controller('game', {$scope: scope});
    }));

    it('create game', function () {
        scope.createGame();
        $httpBackend.flush();
        expect(scope.currentPlayer).toEqual({
            name: "Toto",
            id: "0"
        });
    });

    it('view possible movements', function () {
        scope.viewPossibleMovements(cardName, cardColor);
        $httpBackend.flush();
        expect(scope.highlightedSquares).toEqual(["square-0-0", "square-1-1"]);
        expect(scope.selectedCard).toEqual({card_name: cardName, card_color: cardColor});
    });

    it('play', function () {
        var squareId = 'square-0-0';
        var x = '0';
        var y = '0';
        scope.viewPossibleMovements(cardName, cardColor);
        //scope.play(squareId, x, y);
    });

});
@@ -51,27 +51,56 @@
 var 
+$
 scope, 
-$httpBackend
+controller, $httpBackend;%0A    var square
 ;%0A%0A 
@@ -460,24 +460,25 @@
 d = 'GET';%0A%0A
+%0A
     beforeEa
@@ -509,17 +509,528 @@
 lastLine
-'
+.game'));%0A%0A    beforeEach(angular.mock.inject(function ($rootScope, $controller, $compile) %7B%0A        $scope = $rootScope.$new();%0A        controller = $controller;%0A        controller('game', %7B$scope: $scope%7D);%0A        var squareHtml = '%3Cdiv id=%22square-0-0%22%3E%3C/div%3E';%0A        square = angular.element(squareHtml);%0A        square.attr('ng-class', %22%7BhighlightedSquare: highlightedSquares.indexOf('square-0-0') %3E -1%7D%22);%0A        var compiled = $compile(square);%0A        compiled($scope);%0A        $scope.$digest();%0A    %7D
 ));%0A%0A   
@@ -1824,17 +1824,16 @@
         
-%22
 newSquar
@@ -1833,17 +1833,16 @@
 ewSquare
-%22
 : %22#0-8%22
@@ -1863,17 +1863,16 @@
         
-%22
 nextPlay
@@ -1873,17 +1873,16 @@
 xtPlayer
-%22
 : %7B%0A    
@@ -1901,22 +1901,20 @@
         
-%22
 name
-%22
 : %22Toto%22
@@ -1943,12 +1943,10 @@
     
-%22
 id
-%22
 : %220
@@ -1990,17 +1990,16 @@
         
-%22
 possible
@@ -2013,17 +2013,16 @@
 xtPlayer
-%22
 : %5B%0A    
@@ -2075,14 +2075,12 @@
     
-%22
 name
-%22
 : %22K
@@ -2117,15 +2117,13 @@
     
-%22
 color
-%22
 : %22R
@@ -2198,87 +2198,110 @@
 %7D);%0A
-%0A
     
-    scope = $rootScope.$new();%0A        $controller('game', %7B$scope: scope%7D
+%7D));%0A%0A%0A    it('should have scope to be defined', function () %7B%0A        expect($scope).toBeDefined(
 );%0A 
@@ -2301,25 +2301,24 @@
 ed();%0A    %7D)
-)
 ;%0A%0A    it('c
@@ -2320,19 +2320,54 @@
 it('
-create game
+view possible movements: correct card selected
 ', f
@@ -2391,25 +2391,56 @@
     
+$
 scope.
-createGame(
+viewPossibleMovements(cardName, cardColor
 );%0A 
@@ -2487,93 +2487,80 @@
 ect(
+$
 scope.
-currentPlayer).toEqual(%7B%0A            name: %22Toto%22,%0A            id: %220%22%0A        
+selectedCard).toEqual(%7Bcard_name: cardName, card_color: cardColor
 %7D);%0A
@@ -2599,16 +2599,49 @@
 ovements
+: correct squares are highlighted
 ', funct
@@ -2649,32 +2649,33 @@
 on () %7B%0A        
+$
 scope.viewPossib
@@ -2749,24 +2749,25 @@
      expect(
+$
 scope.highli
@@ -2831,300 +2831,92 @@
     
-expect(scope.selectedCard).toEqual(%7Bcard_name: cardName, card_color: cardColor%7D);%0A    %7D);%0A%0A    it('play', function () %7B%0A        var squareId = 'square-0-0';%0A        var x = '0';%0A        var y = '0';%0A        scope.viewPossibleMovements(cardName, cardColor);%0A        //scope.play(squareId, x, y
+$scope.$digest();%0A        expect(square.attr('class')).toContain('highlightedSquare'
 );%0A 

add tests for viewPossibleMovements.