SmartIT_Extensions/BMC/smart-it-full/test/app/layout-configuration/status-bar-component/status-bar-directive.spec.js

87 lines
3.5 KiB
JavaScript

describe('Test Status Bar directive', function () {
var compile, scope, $httpBackend, screenConfigurationModel;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(function () {
inject(function (_$compile_, _$rootScope_, $injector, _screenConfigurationModel_) {
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=incident').respond(200);
compile = _$compile_;
scope = _$rootScope_.$new();
screenConfigurationModel = _screenConfigurationModel_;
});
});
beforeEach(function () {
scope.ticket = {
type: "incident",
status: {
"value": "Pending",
"reason": "Client Hold"
}
};
scope.metadata = {
statuses: [
{
"isValidForCreate": true,
"index": 0,
"name": "New",
"label": "New"
}
]
};
});
function getCompiledElement() {
var element = angular.element('<status-bar ticket="ticket" metadata="metadata" is-editable=""></status-bar>'),
compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
var directiveElem = getCompiledElement(),
divElem = directiveElem[0];
expect(divElem).toBeDefined();
});
it('should set isEditable value from the status field if handleEditableFlagManually is true;', function () {
var directiveElem, isolateScope;
spyOn(screenConfigurationModel, 'getScreenNameByTicketType').and.returnValue('incidentViewScreen');
screenConfigurationModel.screensCacheByName = {
"incidentViewScreen": {
"panels": [{
"name": "statusBarPanel",
"fields": [
{
"name": "status",
"isAccessible": jasmine.createSpy('isAccessible').and.returnValue(true),
"isEditable": jasmine.createSpy('isEditable').and.returnValue(false)
}
]
}]
}
};
directiveElem = getCompiledElement();
isolateScope = directiveElem.isolateScope();
expect(isolateScope.handleEditableFlagManually).toBeTruthy();
expect(isolateScope.accessible).toBeTruthy();
expect(isolateScope.isEditable).toBeFalsy();
});
it('should values of accessible, fieldLengthForSm6 and fieldLengthForSm4 to true if status bar is newly created', function () {
var directiveElem, isolateScope;
scope.$parent.isNew = true;
directiveElem = getCompiledElement();
isolateScope = directiveElem.isolateScope();
expect(isolateScope.accessible).toBeTruthy();
expect(isolateScope.fieldLengthForSm6).toBeTruthy();
expect(isolateScope.fieldLengthForSm4).toBeTruthy();
});
});