/** * Created by mkumar1 on 27-03-2018. */ describe('Test console directive', function() { var scope, compile, $httpBackend; beforeEach(module('myitsmApp', 'templates','assetModule')); beforeEach(function(){ inject(function($compile, $rootScope, $injector, assetModel){ $httpBackend = $injector.get('$httpBackend'); this.assetModel = assetModel; 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); $httpBackend.whenGET('/smartit/rest/action/search?resourceType=asset').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=asset').respond(200); $httpBackend.whenGET('/smartit/rest/person').respond(200); $httpBackend .whenGET('/smartit/rest/v2/preference/details/search?clientType=UC&preferenceGroup=assetConsoleColumns') .respond(200, []); $httpBackend .whenGET('/smartit/rest/v2/preference/details/search?clientType=UC&preferenceGroup=CIFilter') .respond(200, []); compile = $compile; scope = $rootScope.$new(); }); }); function getCompiledElement() { var element = angular.element(''); var compiledElement = compile(element)(scope); scope.$digest(); return compiledElement; } it('should compile add people directive', function() { var directiveElem = getCompiledElement(); var divElem = directiveElem[0]; expect(divElem).toBeDefined(); }); it('should call cancelFilter', function() { var directiveElem = getCompiledElement(); var directiveScope = directiveElem.isolateScope(); directiveScope.filter = {isOpen: true}; spyOn(directiveScope,'cancelFilter'); scope.$broadcast("$stateChangeStart"); expect(directiveScope.cancelFilter).toHaveBeenCalled(); }); });