/** * Created by npatil2 on 11/3/2017. */ describe('createPersonController', function () { var $httpBackend, modalInstance; beforeEach(module('myitsmApp')); beforeEach(inject(function ($injector, $rootScope, $controller, $state, $q, i18nService, systemAlertService, userModel, searchModel, personModel, metadataModel, screenConfigurationModel) { $httpBackend = $injector.get('$httpBackend'); this.$rootScope = $rootScope; this.scope = $rootScope.$new(); this.controller = $controller; this.$state = $state; this.i18nService = i18nService; this.$state = $state; this.systemAlertService = systemAlertService; this.userModel = userModel; this.searchModel = searchModel; this.personModel = personModel; this.metadataModel = metadataModel; this.$q = $q; this.screenConfigurationModel = screenConfigurationModel; var getLocale = function () { return readJSON('scripts/app/i18n/resources-locale_en.json'); }; modalInstance = { close: jasmine.createSpy('modalInstance.close'), dismiss: jasmine.createSpy('modalInstance.dismiss'), result: { then: jasmine.createSpy('modalInstance.result.then') } }; $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('views/dashboard/index.html').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata/person').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200); $httpBackend.whenGET('components/system-alert/system-alert-modal.html').respond(200); $httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=personDetailsScreen').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&type=company').respond(200); $httpBackend.whenGET('/smartit/rest/foundation/items?type=company').respond(200); this.controllerInstance = this.controller('createPersonController', { $scope: this.scope, $modalInstance: modalInstance }); })); beforeEach(inject(function ($q, $rootScope) { this.scope.createCustomerForm = { $dirty: true }; var toState = { name: 'test' }, toParams = { name: 'test' }; this.scope.$emit('$stateChangeStart', toState, toParams); var deferred = $q.defer(), data = [ { "name": "Calbro Services", "id": "AG00123F73CF5EDFYTSQRbxaAAFsUA", "attributeMap": {} }, { "name": "Invention, Inc.", "id": "AG00123F73CF5EDFYTSQdLxaAAGcUA", "attributeMap": {} }, { "name": "Petramco", "id": "AG005056AC2B58tgEgTQRvVoBwQzAD", "attributeMap": {} }, { "name": "Phylum", "id": "AG005056AC2B582QEgTQVn9pBwUDAD", "attributeMap": {} }, { "name": "Phyto", "id": "AG005056AC2B58HwIgTQxpBqBwajAD", "attributeMap": {} }, { "name": "Pico Systems", "id": "AG005056AC2B58QgIgTQ-xlrBwdjAD", "attributeMap": {} }, { "name": "Psilon", "id": "AG005056AC2B58_AEgTQHghqBwXjAD", "attributeMap": {} } ], personData = { "impacts": [], "availableValueFields": {}, "priorities": [], "urgencies": [], "metadatatype": "person", "statuses": [], "types": [] }; spyOn(this.searchModel, 'getOperatingCompanies').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.metadataModel, 'getPersonMetadata').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); spyOn(this.personModel, 'createPerson').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); spyOn(modalInstance, 'result').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); spyOn(this.personModel, 'getSiteList').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); spyOn(this.personModel, 'getDepartmentList').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); spyOn(this.searchModel, 'getCompaniesByText').and.callFake(function () { var companiesData = {companies: data}; deferred.resolve(companiesData); return deferred.promise; }); spyOn(this.personModel, 'getOrganizationList').and.callFake(function () { deferred.resolve(personData); return deferred.promise; }); })); afterEach(inject(function ($rootScope) { var $rootScope = $rootScope; $rootScope.$apply(); })); it('should be defined', function () { expect(this.controllerInstance).toBeDefined(); }); it('should update Company', function () { this.newCompany = { "name": "Calbro Services", "id": "AG00123F73CF5EDFYTSQRbxaAAFsUA", "attributeMap": {} }; this.scope.updateCompany(this.newCompany); expect(this.scope.person.company.name).toEqual('Calbro Services'); expect(this.scope.person.company.id).toEqual('AG00123F73CF5EDFYTSQRbxaAAFsUA'); expect(this.scope.person.organization).toEqual(''); expect(this.scope.person.department ).toEqual(''); expect(this.scope.person.site).toEqual(''); }); it('should create Person', function () { this.scope.createPerson(); expect(this.scope.state.dataIsLoading).toBe(true); this.scope.$apply(); expect(this.scope.state.dataIsLoading).toBe(false); }); it('should return Sites And Update', function () { this.company = { name: 'Calbro Services' }; this.scope.getSitesAndUpdate(this.company); expect(this.scope.sitesLoading).toBe(true); this.scope.$apply(); expect(this.scope.sites).toBeTruthy(); expect(this.scope.sitesLoading).toBe(false) }); it('should return Departments And Update', function () { this.company = { name: 'Calbro Services' }; this.organization = 'test organization'; this.scope.getDepartmentsAndUpdate(this.organization, this.company); expect(this.scope.departmentsLoading).toBe(true); this.scope.$apply(); expect(this.scope.departments).toBeTruthy(); expect(this.scope.departmentsLoading).toBe(false) }); it('should return Companies By Name', function () { this.name = 'Calbro Services'; this.myResult = this.scope.getCompaniesByName(this.name); this.scope.$apply(); expect(this.myResult.$$state.value[0].name).toEqual('Calbro Services'); expect(this.myResult.$$state.value[0].id).toEqual('AG00123F73CF5EDFYTSQRbxaAAFsUA'); }); it('should return Organizations And Update', function () { this.company = { "name": "Calbro Services", "id": "AG00123F73CF5EDFYTSQRbxaAAFsUA", "attributeMap": {} }; this.myResult = this.scope.getOrganizationsAndUpdate(this.company); expect(this.scope.organizationsLoading).toBe(true); this.scope.$apply(); expect(this.scope.organizations).toBeTruthy(); expect(this.scope.organizationsLoading).toBe(false); }); });