SmartIT_Extensions/BMC/smart-it-full/test/app/resource/rs-directive.spec.js

51 lines
1.8 KiB
JavaScript

describe('Test rs directive', function () {
var compile, scope, $httpBackend, events;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(function () {
inject(function ($compile, $rootScope, $injector, _events_) {
$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);
compile = $compile;
scope = $rootScope.$new();
events = _events_;
});
});
beforeEach(function () {
scope.context = {
id: 'AG00123F73CF5Eqc4TSQTOQxAgc0QB'
};
});
function getCompiledElement() {
var element = angular.element('<rs context="context"></rs>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
var directiveElem = getCompiledElement(),
divElem = directiveElem[0];
expect(divElem).toBeDefined();
});
it('should toggle KA search mode and broadcast event in case of back button', function () {
var directiveElem = getCompiledElement(),
isolateScope = directiveElem.isolateScope();
spyOn(isolateScope, '$broadcast');
isolateScope.state.kaSearchEnabled = true;
isolateScope.toggleSearchKa();
isolateScope.$digest();
expect(isolateScope.state.kaSearchEnabled).toBeFalsy();
expect(isolateScope.$broadcast).toHaveBeenCalledWith(events.REFRESH_RECOMMENDED_KNOWLEDGE);
});
});