gaf-mobile
Version:
GAF mobile Web site
105 lines (88 loc) • 3.3 kB
JavaScript
/* global LocationMock */
describe('Controller: updatelocationModal', function() {
var $rootScope, $scope, $q, ctrl;
var UsersMock, AuthMock, ProjectLocationMock;
var mockLocation, createCtrl;
beforeEach(module('gafMobileApp'));
beforeEach(inject(function($controller, _$rootScope_, _$q_) {
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$q = _$q_;
ProjectLocationMock = jasmine.createSpyObj('ProjectLocation',
['getLocation', 'isValidPlace', 'denormaliseLatLng']);
UsersMock = jasmine.createSpyObj('Users', [
'setLocation',
'updateUserInfo'
]);
AuthMock = {
isAuthenticated: function() {
return true;
}
};
mockLocation = LocationMock();
createCtrl = function() {
return $controller('UpdateLocationModalCtrl', {
$scope: $scope,
Users: UsersMock,
Auth: AuthMock,
ProjectLocation: ProjectLocationMock
});
};
ctrl = createCtrl();
ctrl.success = jasmine.createSpy('success');
}));
describe('Method: updateLocation', function() {
it('it should execute success function', function() {
ProjectLocationMock.isValidPlace.and.returnValue(true);
ProjectLocationMock.denormaliseLatLng.and.returnValue(mockLocation);
UsersMock.setLocation.and.returnValue(true);
UsersMock.updateUserInfo.and.returnValue(true);
ctrl.location = { someLoc: 'some location' };
ctrl.updateLocation();
$scope.$digest();
expect(ProjectLocationMock.denormaliseLatLng).toHaveBeenCalled();
expect(UsersMock.setLocation).toHaveBeenCalled();
expect(ctrl.notifyInput).toBeTruthy();
expect(ctrl.success).toHaveBeenCalled();
});
it('it should throw an error on failure', function() {
ProjectLocationMock.isValidPlace.and.returnValue(true);
ProjectLocationMock.denormaliseLatLng.and.returnValue(mockLocation);
UsersMock.setLocation.and.returnValue($q.reject());
ctrl.location = { someLoc: 'some location' };
ctrl.updateLocation();
$scope.$digest();
expect(ctrl.error).toBe('errorOcurred');
});
it('should return an error when it\'s not a valid location',
function() {
ctrl.location = 'invalid location';
ctrl.updateLocation();
expect(ctrl.error).toBe('invalidLocation');
});
it('should return an error when it\'s not a valid location',
function() {
ctrl.location = { invalid: 'location' };
ProjectLocationMock.isValidPlace.and.returnValue(false);
ctrl.updateLocation();
expect(ctrl.error).toBe('invalidLocation');
});
});
describe('Method: getCurrentLocation', function() {
it('should return browser location if available',
function() {
ProjectLocationMock.getLocation.and.returnValue($q.when(mockLocation));
ctrl.getCurrentLocation();
$scope.$digest();
expect(ctrl.location).toBe(mockLocation);
});
it('should have an error when location is no available',
function() {
ProjectLocationMock.getLocation.and.returnValue($q.reject({ code: 1 }));
ctrl.getCurrentLocation();
$scope.$digest();
expect(ctrl.error).toBe('locationNotAvailable');
});
});
});
;