115 lines
3.9 KiB
JavaScript
115 lines
3.9 KiB
JavaScript
describe('Main controller ', function () {
|
|
var $controller,
|
|
$rootScope,
|
|
scope,
|
|
authModel,
|
|
userModel,
|
|
AUTH_EVENTS,
|
|
$modal,
|
|
$cookies,
|
|
l10nModel,
|
|
controllerInstance,
|
|
$httpBackend;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(module(function ($provide) {
|
|
$provide.value('authModel', {
|
|
logout: jasmine.createSpy('authModel.logout').and.callFake(function () {}),
|
|
isAuthenticated: jasmine.createSpy('authModel.isAuthenticated').and.returnValue(true),
|
|
isAuthorized: jasmine.createSpy('authModel.isAuthorized').and.returnValue(true),
|
|
deRegister: jasmine.createSpy('authModel.deRegister').and.callFake(function(){})
|
|
});
|
|
|
|
$provide.value('userModel', {
|
|
isAccessibleUser: false,
|
|
isAccessibleUserPreferenceId: 1,
|
|
getFullCurrentUserData: function () {
|
|
return {
|
|
then: function (cb) {
|
|
cb({id: 1, userId: 1, firstName: 'test'});
|
|
}
|
|
}
|
|
},
|
|
updateUserPreferences: jasmine.createSpy('userModel.updateUserPreferences').and.callFake(function () {}),
|
|
getUserDataForCurrentSession: jasmine.createSpy('userModel.getUserDataForCurrentSession').and.callFake(function () {}),
|
|
getUserPreferences: function () {}
|
|
});
|
|
|
|
$provide.value('$modal', {
|
|
open: jasmine.createSpy('$modal.open').and.callFake(function () {})
|
|
});
|
|
}));
|
|
|
|
beforeEach(inject(function (_$controller_, _$rootScope_, _authModel_, _userModel_, _$modal_, _$cookies_, _AUTH_EVENTS_, _l10nModel_, $injector) {
|
|
$controller = _$controller_;
|
|
$rootScope = _$rootScope_;
|
|
scope = $rootScope.$new();
|
|
authModel = _authModel_;
|
|
$modal = _$modal_;
|
|
userModel = _userModel_;
|
|
l10nModel = _l10nModel_;
|
|
$cookies = _$cookies_;
|
|
AUTH_EVENTS = _AUTH_EVENTS_;
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
controllerInstance = $controller('MainController', {
|
|
$scope: scope
|
|
});
|
|
}));
|
|
|
|
it('should be defined', function () {
|
|
expect(controllerInstance).toBeDefined();
|
|
expect(scope.appState).toEqual(scope.APP_STATES.INDETERMINATE);
|
|
});
|
|
|
|
it('should do logout', function () {
|
|
scope.onLogoutClick();
|
|
expect(scope.appState).toEqual(scope.APP_STATES.INDETERMINATE);
|
|
expect(authModel.logout).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should open modal window on about click', function () {
|
|
scope.onAboutClick();
|
|
expect($modal.open).toHaveBeenCalledWith(jasmine.objectContaining({templateUrl: 'views/about.html', windowClass: 'bmc-system-about-modal'}));
|
|
});
|
|
|
|
|
|
|
|
it('should start application init', inject(function (chatModel, userModel) {
|
|
spyOn(l10nModel, 'loadSystemMessages').and.callThrough();
|
|
spyOn(userModel, 'getUserPreferences').and.callFake(function () {
|
|
return {
|
|
then: function (cb) {
|
|
var accessibleConfig = [{value: true, id: 2}];
|
|
cb(accessibleConfig);
|
|
}
|
|
}
|
|
});
|
|
spyOn(scope, 'enableAccessibility').and.returnValue(true);
|
|
|
|
$cookies.put('accessibility', false);
|
|
localStorage.setItem('tabCount','1');
|
|
|
|
$rootScope.$broadcast(AUTH_EVENTS.SESSION_ACTIVE);
|
|
expect(authModel.deRegister).toHaveBeenCalled();
|
|
expect(userModel.getUserDataForCurrentSession).toHaveBeenCalled();
|
|
expect(l10nModel.loadSystemMessages).toHaveBeenCalled();
|
|
expect(scope.appState).toEqual(scope.APP_STATES.SHOW_MAIN);
|
|
expect(scope.chatModel).toBe(chatModel);
|
|
expect(scope.userModel).toBe(userModel);
|
|
expect(userModel.getUserPreferences).toHaveBeenCalledWith('interface');
|
|
expect(scope.enableAccessibility).toHaveBeenCalled();
|
|
expect(userModel.isAccessibleUser).toEqual(true);
|
|
expect(userModel.isAccessibleUserPreferenceId).toEqual(2);
|
|
}));
|
|
|
|
it('should enable accessibility settings for user', function () {
|
|
scope.enableAccessibility();
|
|
expect(userModel.isAccessibleUser).toEqual(true);
|
|
expect($cookies.get('accessibility')).toEqual('true');
|
|
expect(userModel.updateUserPreferences).toHaveBeenCalledWith('interface', jasmine.objectContaining({
|
|
id: userModel.isAccessibleUserPreferenceId,
|
|
name: 'accessibility',
|
|
value: userModel.isAccessibleUser
|
|
}))
|
|
});
|
|
}); |