describe('Test person site directive', function () { var compile, scope, $httpBackend, originalTimeout, createTicketModel, field, deferred; beforeEach(module('myitsmApp','templates')); beforeEach(function(){ inject(function($compile, $rootScope, $injector, _createTicketModel_, $q){ $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/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:80%7D%7D&type=region').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:80%7D,%22regionName%22:%22Europe%22%7D&type=siteGroup').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:100%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:100%7D,%22regionName%22:%22Europe%22,%22siteGroupName%22:%22Amsterdam%22%7D&type=site').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:80%7D%7D&type=siteGroup').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:100%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:100%7D%7D&type=site').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&searchOptions=%7B%22companyName%22:%22Calbro+Services%22,%22chunkInfo%22:%7B%22startIndex%22:0,%22chunkSize%22:80%7D%7D&searchText=Americas&type=region').respond(200); compile = $compile; scope = $rootScope.$new(); createTicketModel = _createTicketModel_; deferred = $q.defer(); field = { "name": "site", "label": "Site", "value": { "site": { "name": "Amsterdam Support Center", "attributeMap": { "siteAddress": { "street": "1114 Eighth Avenue, 31st Floor", "city": "New York", "state": "New York", "country": "United States", "zip": "10036", "address": "1114 Eighth Avenue, 31st Floor\r\nNew York, New York 10036\r\nUnited States" }, "regionName": "Europe", "siteGroupName": "Amsterdam" } }, "siteGroup": { "name": "Amsterdam", "attributeMap": { "regionName": "Europe" } }, "region": { "name": "Europe" }, "company": { "name": "Calbro Services" } } }; }); }); beforeEach(function() { originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; }); afterEach(function() { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; }); beforeEach(inject(function ($q, $rootScope) { var deferred = $q.defer(), success = { objects: [ { "name": "Human Resources", "attributeMap": { "companyName": "Calbro Services", "id": "POR000000000011" }, "id": "AG00123F73CF5EDVYTSQN8FaAAZsUA", "companyName": "Calbro Services" }, { "name": "Information Technology", "attributeMap": { "companyName": "Calbro Services", "id": "POR000000000013" }, "id": "AG00123F73CF5EDVYTSQZsFaAAaMUA", "companyName": "Calbro Services" } ], exceedsChunkSize: true }; spyOn(createTicketModel, 'getList').and.callFake(function () { deferred.resolve(success); return deferred.promise; }); })); function getCompiledElement(){ var element = angular.element(''); var compiledElement = compile(element)(scope); scope.$digest(); return compiledElement; } it('should compile', function(){ scope.field = new FieldVO().build(field); var directiveElem = getCompiledElement(); var divElem = directiveElem[0]; expect(divElem).toBeDefined(); }); it('should invoke watch for setValueFlag', function(){ scope.field = new FieldVO().build(field); scope.field.setValueFlag = {}; scope.$digest(); getCompiledElement(); expect(scope.field.setValueFlag).toEqual('#$#'); }); it('should load regions', function(){ var searchResult = { objects: [ { "name": "Americas", "attributeMap": { "companyName": "Calbro Services" } } ], exceedsChunkSize: true }, result; scope.field = new FieldVO().build(field); spyOn(createTicketModel, 'getListOfRegionsByName').and.callFake(function () { deferred.resolve(searchResult); return deferred.promise; }); var directiveElem = getCompiledElement(), regionName = 'Americas', isolatedScope = directiveElem.isolateScope(); result = isolatedScope.loadRegionsByName(regionName); result.then(function(response) { expect(response.list[0].name).toBe('Americas'); }); scope.$apply(); expect(createTicketModel.getListOfRegionsByName).toHaveBeenCalled(); }); it('should load siteGroups', function(){ var searchResult = { objects: [ { "name": "United States", "attributeMap": { "companyName": "Calbro Services", "regionName": "Europe" } } ], exceedsChunkSize: true }, result; scope.field = new FieldVO().build(field); spyOn(createTicketModel, 'getListOfSiteGroupsByName').and.callFake(function () { deferred.resolve(searchResult); return deferred.promise; }); var directiveElem = getCompiledElement(), groupSite = 'United States', isolatedScope = directiveElem.isolateScope(); result = isolatedScope.loadSiteGroupsByName(groupSite); result.then(function(response) { expect(response.list[0].name).toBe('United States'); }); scope.$apply(); expect(createTicketModel.getListOfSiteGroupsByName).toHaveBeenCalled(); }); it('should load site name', function(){ var searchResult = { objects: [ { "name": "Boston Support Center", "attributeMap": { "companyName": "Calbro Services", "regionName": "Europe" } } ], exceedsChunkSize: true }, result; scope.field = new FieldVO().build(field); spyOn(createTicketModel, 'getListOfSitesByName').and.callFake(function () { deferred.resolve(searchResult); return deferred.promise; }); var directiveElem = getCompiledElement(), siteName = 'Boston Support Center', isolatedScope = directiveElem.isolateScope(); isolatedScope.loadSitesByName(siteName); result = isolatedScope.loadSitesByName('Boston'); result.then(function(response) { expect(response.list[0].name).toBe('Boston Support Center'); }); scope.$apply(); expect(createTicketModel.getListOfSitesByName).toHaveBeenCalled(); }); });