gaf-mobile
Version:
GAF mobile Web site
80 lines (61 loc) • 2.25 kB
JavaScript
'use strict';
describe('Controller: LanguageSelectCtrl', function() {
// Vars
var $scope, $rootScope, $q, createCtrl;
// Mocks
var LocalizationMock, LocalizedRouteMock;
// Load the controller's module
beforeEach(module('gafMobileApp'));
// Initialize the controller
beforeEach(inject(function($controller, _$rootScope_, _$q_) {
$scope = _$rootScope_.$new();
$rootScope = _$rootScope_.$new();
$q = _$q_;
// Controller constructer to enable to tweak the
// mock ups before instantiate it
createCtrl = function() {
return $controller('LanguageSelectCtrl', {
$rootScope: $rootScope,
Localization: LocalizationMock,
LocalizedRoute: LocalizedRouteMock
});
};
}));
// Create the mock ups
beforeEach(function() {
LocalizationMock = jasmine.createSpyObj('Localization', ['language']);
LocalizedRouteMock = jasmine.createSpyObj('LocalizedRoute', ['languages']);
LocalizationMock.language.and.returnValue('en');
LocalizedRouteMock.languages.and.returnValue(['en', 'fil']);
});
it('should set current and supported languages', function() {
var ctrl = createCtrl();
$scope.$digest();
expect(ctrl.language).toBe('en');
expect(ctrl.languages).toEqual(['en', 'fil']);
});
describe('Method: setLanguage()', function() {
it('should set selected language', function() {
LocalizationMock.language.and.returnValue($q.when());
var ctrl = createCtrl();
$scope.$digest();
ctrl.setLanguage('en');
expect($rootScope.isViewLoading).toBeTruthy();
expect(LocalizationMock.language).toHaveBeenCalledWith('en');
});
it('should hide loading when setting language is successful', function() {
LocalizationMock.language.and.returnValue($q.when());
var ctrl = createCtrl();
ctrl.setLanguage('en');
$scope.$digest();
expect($rootScope.isViewLoading).toBeFalsy();
});
it('should hide loading even when setting language fails', function() {
LocalizationMock.language.and.returnValue($q.reject());
var ctrl = createCtrl();
ctrl.setLanguage('en');
$scope.$digest();
expect($rootScope.isViewLoading).toBeFalsy();
});
});
});