--- /dev/null
+'use strict';
+
+describe('ALLO Webadmin Controllers', function() {
+
+ beforeEach(module('AlloWebadminApp'));
+
+ var $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"
+ });
+ }));
+
+ describe('Menu Controller', function() {
+
+ it('should exist', inject(function($controller) {
+ var $scope = {},
+ menuCtrl = $controller('MenuCtrl', { $scope: $scope });
+ expect(menuCtrl).toBeDefined();
+ }));
+
+ it('should contain 3 options', inject(function($controller) {
+ var $scope = {},
+ menuCtrl = $controller('MenuCtrl', { $scope: $scope });
+ expect($scope.menuItems.length).toEqual(3);
+ }));
+
+ });
+
+ describe('Login Controller', function() {
+
+ 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);
+ }));
+
+ it('should not log in successfully with user / password', inject(function($controller, $rootScope, $location, AuthenticationService) {
+ var $scope = {login: 'user', password: 'password', error:''},
+ loginCtrl = $controller('LoginCtrl', {
+ $scope: $scope,
+ $rootScope: $rootScope,
+ $location: $location,
+ AuthenticationService: AuthenticationService
+ });
+ $scope.loginAction();
+ $httpBackend.flush();
+ expect($scope.dataLoading).toEqual(false);
+ }));
+ });
+
+ describe('Logout Controller', function() {
+
+ it('should logout successfully', inject(function($controller, $rootScope, $location, AuthenticationService) {
+ var $scope = {error:''},
+ logoutCtrl = $controller('LogoutCtrl', {
+ $scope: $scope,
+ $rootScope: $rootScope,
+ $location: $location,
+ AuthenticationService: AuthenticationService
+ });
+ $httpBackend.flush();
+ expect($scope.result.login).toEqual(false);
+ expect($scope.result.is_loggued).toEqual(false);
+ }));
+ });
+});
\ No newline at end of file