--- /dev/null
+'use strict';
+
+beforeEach(module('AlloWebadminApp'));
+
+describe('Product Controllers', function() {
+
+ var $controller, $routeParams, $http, $scope = {}, productCtrl, $httpBackend, allo_server_url, mock_data;
+
+ beforeEach(inject(function($injector) {
+ $httpBackend = $injector.get('$httpBackend');
+ allo_server_url = $injector.get('allo_server_url');
+ mock_data = $injector.get('mock-data');
+
+ // SIMULATING BACKEND SERVER (GET REQUESTS FOR NOW)
+ for(var url in mock_data) {
+ $httpBackend.when('GET', allo_server_url + url).respond(mock_data[url]);
+ }
+
+ $httpBackend.when('GET', 'partials/product-list-full.html').respond('');
+
+ $httpBackend.when('GET', 'partials/login.html').respond('');
+
+ $httpBackend.when('POST', allo_server_url+'?action=session_login',
+ function(postData) {
+ return (postData === "login=admin&password=admin");
+ })
+ .respond({
+ "retour": "OK",
+ "message": "",
+ "result": {
+ "login": "admin",
+ "is_loggued": true
+ }
+ });
+
+ $httpBackend.when('POST', allo_server_url+'?action=session_login')
+ .respond({
+ "retour": "KO",
+ "message": "Mauvais login ou mot de passe"
+ });
+ }));
+
+ it('should log in successfully with admin / admin', inject(function($controller, $rootScope, $location, AuthenticationService) {
+ var $scope = {login: 'admin', password: 'admin', error:''},
+ loginCtrl = $controller('LoginCtrl', {
+ $scope: $scope,
+ $rootScope: $rootScope,
+ $location: $location,
+ AuthenticationService: AuthenticationService
+ });
+ $scope.loginAction();
+ $httpBackend.flush();
+ expect($scope.dataLoading).toEqual(true);
+ }));
+
+ describe('Product Detail Controller', function() {
+
+ beforeEach(inject(function($injector) {
+ $controller = $injector.get('$controller');
+ $routeParams = $injector.get('$routeParams');
+ $http = $injector.get('$http');
+ productCtrl = $controller('ProductDetailCtrl', { $scope: $scope, $routeParams: $routeParams, $http: $http });
+ $httpBackend.flush();
+ }));
+
+ it('should exist', function() {
+ expect(productCtrl).toBeDefined();
+ });
+
+ it('should have gotten an object as response', function() {
+ expect(typeof $scope.patches).toBe('object');
+ });
+
+ });
+
+ describe('Product List Controller', function() {
+
+ beforeEach(inject(function($injector) {
+ $controller = $injector.get('$controller');
+ $routeParams = $injector.get('$routeParams');
+ $http = $injector.get('$http');
+ productCtrl = $controller('ProductListCtrl', { $scope: $scope, $routeParams: $routeParams, $http: $http });
+ $httpBackend.flush();
+ }));
+
+ it('should exist', function() {
+ expect(productCtrl).toBeDefined();
+ });
+
+ it('should have gotten an object as response', function() {
+ expect(typeof $scope.products).toBe('object');
+ });
+ });
+
+});
\ No newline at end of file