mirror of
https://github.com/ansible/awx.git
synced 2026-01-22 06:58:06 -03:30
161 lines
5.6 KiB
JavaScript
161 lines
5.6 KiB
JavaScript
describe('Components | Layout', () => {
|
|
let $compile;
|
|
let $rootScope;
|
|
let element;
|
|
let scope;
|
|
|
|
beforeEach(() => {
|
|
angular.mock.module('gettext');
|
|
angular.mock.module('I18N');
|
|
angular.mock.module('ui.router');
|
|
angular.mock.module('at.lib.services');
|
|
angular.mock.module('at.lib.components');
|
|
});
|
|
|
|
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
|
$compile = _$compile_;
|
|
$rootScope = _$rootScope_;
|
|
scope = $rootScope.$new();
|
|
|
|
element = angular.element('<at-layout></at-layout>');
|
|
element = $compile(element)(scope);
|
|
scope.$digest();
|
|
}));
|
|
|
|
describe('AtLayoutController', () => {
|
|
let controller;
|
|
|
|
beforeEach(() => {
|
|
controller = element.controller('atLayout');
|
|
});
|
|
|
|
it('$scope.$on($stateChangeSuccess) should assign toState name to currentState', () => {
|
|
const next = { name: 'dashboard' };
|
|
$rootScope.$broadcast('$stateChangeSuccess', next);
|
|
expect(controller.currentState).toBe('dashboard');
|
|
});
|
|
|
|
describe('$root.current_user watcher should assign value to ', () => {
|
|
beforeEach(() => {
|
|
const val = {
|
|
username: 'admin',
|
|
id: 1
|
|
};
|
|
$rootScope.current_user = val;
|
|
scope.$digest();
|
|
});
|
|
|
|
it('isLoggedIn', () => {
|
|
expect(controller.isLoggedIn).toBe('admin');
|
|
|
|
$rootScope.current_user = { id: 1 };
|
|
scope.$digest();
|
|
expect(controller.isLoggedIn).not.toBeDefined();
|
|
});
|
|
|
|
it('isSuperUser', () => {
|
|
$rootScope.current_user = 'one';
|
|
$rootScope.user_is_superuser = true;
|
|
$rootScope.user_is_system_auditor = false;
|
|
scope.$digest();
|
|
expect(controller.isSuperUser).toBe(true);
|
|
|
|
$rootScope.current_user = 'two';
|
|
$rootScope.user_is_superuser = false;
|
|
$rootScope.user_is_system_auditor = true;
|
|
scope.$digest();
|
|
expect(controller.isSuperUser).toBe(true);
|
|
|
|
$rootScope.current_user = 'three';
|
|
$rootScope.user_is_superuser = true;
|
|
$rootScope.user_is_system_auditor = true;
|
|
scope.$digest();
|
|
expect(controller.isSuperUser).toBe(true);
|
|
|
|
$rootScope.current_user = 'four';
|
|
$rootScope.user_is_superuser = false;
|
|
$rootScope.user_is_system_auditor = false;
|
|
scope.$digest();
|
|
expect(controller.isSuperUser).toBe(false);
|
|
});
|
|
|
|
it('currentUsername', () => {
|
|
expect(controller.currentUsername).toBeTruthy();
|
|
expect(controller.currentUsername).toBe('admin');
|
|
});
|
|
|
|
it('currentUserId', () => {
|
|
expect(controller.currentUserId).toBeTruthy();
|
|
expect(controller.currentUserId).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe('$root.socketStatus watcher should assign newStatus to', () => {
|
|
const statuses = ['connecting', 'error', 'ok'];
|
|
|
|
it('socketState', () => {
|
|
_.forEach(statuses, (status) => {
|
|
$rootScope.socketStatus = status;
|
|
scope.$digest();
|
|
expect(controller.socketState).toBeTruthy();
|
|
expect(controller.socketState).toBe(status);
|
|
});
|
|
});
|
|
|
|
it('socketIconClass', () => {
|
|
_.forEach(statuses, (status) => {
|
|
$rootScope.socketStatus = status;
|
|
scope.$digest();
|
|
expect(controller.socketIconClass).toBe(`icon-socket-${status}`);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('$root.licenseMissing watcher should assign true or false to', () => {
|
|
it('licenseIsMissing', () => {
|
|
$rootScope.licenseMissing = true;
|
|
scope.$digest();
|
|
expect(controller.licenseIsMissing).toBe(true);
|
|
|
|
$rootScope.licenseMissing = false;
|
|
scope.$digest();
|
|
expect(controller.licenseIsMissing).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('getString()', () => {
|
|
it('calls ComponentsStrings get() method', angular.mock.inject((_ComponentsStrings_) => {
|
|
spyOn(_ComponentsStrings_, 'get');
|
|
controller.getString('VIEW_DOCS');
|
|
expect(_ComponentsStrings_.get).toHaveBeenCalled();
|
|
}));
|
|
|
|
it('ComponentsStrings get() method should throw an error if string is not a property name of the layout class', () => {
|
|
expect(controller.getString.bind(null, 'SUBMISSION_ERROR_TITLE')).toThrow();
|
|
});
|
|
|
|
it('should return layout string', () => {
|
|
const layoutStrings = {
|
|
CURRENT_USER_LABEL: 'Logged in as',
|
|
VIEW_DOCS: 'View Documentation',
|
|
LOGOUT: 'Logout',
|
|
};
|
|
|
|
_.forEach(layoutStrings, (value, key) => {
|
|
expect(controller.getString(key)).toBe(value);
|
|
});
|
|
});
|
|
|
|
it('should return default string', () => {
|
|
const defaultStrings = {
|
|
BRAND_NAME: 'AWX'
|
|
};
|
|
|
|
_.forEach(defaultStrings, (value, key) => {
|
|
expect(controller.getString(key)).toBe(value);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|