SmartIT_Extensions/BMC/smart-it-full/test/app/common/alert-carousel-directive.sp...

64 lines
2.4 KiB
JavaScript

describe('Test approval alert directive', function () {
var compile, scope, $httpBackend;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(function () {
inject(function ($compile, $rootScope, $injector) {
$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/v2/metadata?type=global').respond(200);
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
compile = $compile;
scope = $rootScope.$new();
});
});
function getCompiledElement(alertDetails, basicData) {
var element = angular.element('<alert-carousel alert-details="alertDetails" basic-data="basicData"></alert-carousel>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
scope.alertDetails = {alertItems: []};
var directiveElem = getCompiledElement(scope.alertDetails);
var divElem = directiveElem[0];
expect(divElem).toBeDefined();
expect(divElem.className).toContain('alert-banner');
});
it('should not show alerts if no alert items', function () {
scope.alertDetails = {
alertItems: []
};
var directiveElem = getCompiledElement(scope.alertDetails);
var isolatedScope = directiveElem.isolateScope();
isolatedScope.nextAlert();
isolatedScope.prevAlert();
expect(isolatedScope.alertIndex).not.toBeLessThan(-1);
expect(isolatedScope.alertIndex).toBeLessThan(isolatedScope.alertDetails.alertItems.length);
});
it('should show approval banner', function () {
scope.alertDetails = {
alertItems: ["approval_banner", "approval_banner"]
};
scope.basicData = new ReleaseVO();
var directiveElem = getCompiledElement(scope.alertDetails, scope.basicData);
var isolatedScope = directiveElem.isolateScope();
isolatedScope.nextAlert();
isolatedScope.prevAlert();
expect(directiveElem.find('.approval-banner').length).toEqual(1);
});
});