describe('Test activity-feed-directive', function() { var element, scope, compile, rootScope, $httpBackend, elementScope, noteData, 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'); }, getMetadata = function (type) { return readJSON('mocks/' + type + '-metadata.json'); }, getTimelineInfo = function (type) { var mockFileName = 'mocks/timeline-' + type + '-mcsm.json'; return readJSON(mockFileName); }, getGlobalMetadata = function () { return readJSON('mocks/metadata-global.json'); }, getSupportGroupPersonResponse = function () { return [ { items: [ { id: 'test', loginId: 'test' } ] } ] }; $httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale()); $httpBackend.whenGET("/smartit/rest/v2/metadata?type=incident").respond(getMetadata(EntityVO.TYPE_INCIDENT)); $httpBackend.whenGET("/smartit/rest/v2/metadata?type=change").respond(getMetadata(EntityVO.TYPE_CHANGE)); $httpBackend.whenGET("/smartit/rest/v2/metadata?type=global").respond(200, getGlobalMetadata()); $httpBackend.whenGET("/smartit/restapi/person/supportgroupperson").respond(200, getSupportGroupPersonResponse()); $httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(''); $httpBackend.whenGET('/smartit/rest/serverstates').respond(''); $httpBackend.whenGET(/^\/smartit\/rest\/timeline\/incident/).respond(getTimelineInfo(EntityVO.TYPE_INCIDENT)); $httpBackend.whenGET(/^\/smartit\/rest\/timeline\/change/).respond(getTimelineInfo(EntityVO.TYPE_CHANGE)); compile = $compile; rootScope = $rootScope; scope = $rootScope.$new(); events = _events_; }); }); function getCompiledElement(type) { element = angular.element(''); switch (type) { case EntityVO.TYPE_INCIDENT: scope.parentContext = new IncidentVO(); break; case EntityVO.TYPE_CHANGE: scope.parentContext = new ChangeVO(); break; } scope.parentContext.id = 'IDGAA5V0GEXKMAOU28QBFDNOLEIUCE'; scope.type = type; scope.id = 'IDGAA5V0GEXKMAOU28QBFDNOLEIUCE'; var directiveElem = compile(element)(scope); scope.$digest(); $('body').append(element); $httpBackend.flush(); scope.$digest(); elementScope = element.isolateScope(); return directiveElem; } it('should compile', function () { var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT); var divElem = directiveElem[0]; expect(divElem).toBeDefined(); }); it('should process and display the correct activity items for incident activity', function () { var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT); scope.$digest(); var feedItemElements = directiveElem.find('.feed-item'); expect(elementScope.feed.length).toEqual(8); expect(feedItemElements.length).toEqual(8); expect(feedItemElements[0].innerText).toContain('AWS Changed ticket status : Closed'); expect(feedItemElements[1].innerText).toContain('AWS added a note'); expect(feedItemElements[2].innerText).toContain('Allen Allbrook shared a note with Salesforce'); expect(feedItemElements[3].innerText).toContain('Business rules sent ticket to AWS'); expect(feedItemElements.find('.icon-cloud_user').length).toEqual(2); expect(feedItemElements.find('.icon-incident-brokered').length).toEqual(1); }); it('should process and display the correct activity items for change activity', function () { var directiveElem = getCompiledElement(EntityVO.TYPE_CHANGE); scope.$digest(); var feedItemElements = directiveElem.find('.feed-item'), ticketLinks = directiveElem.find('a[href="https://console.aws.amazon.com/support/v1#/case/?displayId=4976865711&language=en"]'), userLinks = directiveElem.find('a[href="#/person/allen"]'), googleLinks = directiveElem.find('a[href="http://www.google.com"]'); expect(elementScope.feed.length).toEqual(8); expect(feedItemElements.length).toEqual(8); expect(ticketLinks.length).toEqual(3); expect(userLinks.length).toEqual(1); expect(googleLinks.length).toEqual(1); expect(feedItemElements[0].innerText).toContain('AWS ticket'); expect(feedItemElements[0].innerText).toContain('status changed to Closed'); expect(feedItemElements[1].innerText).toContain('Note added to AWS ticket '); expect(feedItemElements[2].innerText).toContain('Allen Allbrook shared a note with Salesforce'); expect(feedItemElements[3].innerText).toContain('Business rules created ticket '); expect(feedItemElements[3].innerText).toContain(' in AWS'); expect(feedItemElements.find('.icon-cloud_user').length).toEqual(2); expect(feedItemElements.find('.icon-change-brokered').length).toEqual(1); }); });