/*** Created by npatil2 .*/ describe('ChartController', function () { 'use strict'; var $httpBackend; beforeEach(module('myitsmApp')); beforeEach(inject(function ($injector, $rootScope, $controller, chartModel, userModel, searchModel, $q, i18nService, $timeout, configurationModel, $filter, metadataModel, authService, roles) { this.scope = $rootScope.$new(); this.controller = $controller; this.chartModel = chartModel; this.userModel = userModel; this.searchModel = searchModel; this.$q = $q; this.i18nService = i18nService; this.$timeout = $timeout; this.configurationModel = configurationModel; this.$filter = $filter; this.metadataModel = metadataModel; this.authService = authService; this.roles = roles; this.controllerInstance = this.controller('ChartController', { $scope: this.scope }); })); beforeEach(inject(function ($injector) { $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); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').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/v2/preference/details/search?clientType=UC&preferenceGroup=Dashboard').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=incident&type=workorder&type=request').respond(200); $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/foundation/items?type=company').respond(200); })); beforeEach(inject(function ($q) { var deferred = $q.defer(), data = 'success', companies = ['collabroService', 'collabro'], userConfig = ['test', 'test2'], userPreferenceGroup = 'Dashboard', stat = { label: 'critical' }; spyOn(this.userModel, 'getFullCurrentUserData').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.authService, 'isAuthorized').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchModel, 'getOperatingCompanies').and.callFake(function () { deferred.resolve(companies); return deferred.promise; }); spyOn(this.userModel, 'getUserPreferences').and.callFake(function () { deferred.resolve(userConfig); return deferred.promise; }); spyOn(this.metadataModel, 'getMetadataByTypes').and.callFake(function () { deferred.resolve(userConfig); return deferred.promise; }); spyOn(this.userModel, 'userConfig').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); spyOn(this.userModel, 'updateUserPreferences').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); spyOn(this.chartModel, 'fetchData').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); spyOn(this.chartModel, 'getChartStatisticsData').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); spyOn(this.chartModel, 'getChangeData').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); spyOn(this.chartModel, 'statsConfig').and.callFake(function () { deferred.resolve(stat); return deferred.promise; }); spyOn(this.i18nService, 'getLocalizedString').and.callFake(function () { deferred.resolve(userPreferenceGroup); return deferred.promise; }); })); it('should be defined', function () { expect(this.controllerInstance).toBeDefined(); this.scope.$apply(); }); it('should refresh Backlog Data ', function () { this.ticketType = 'workorder'; this.days = '30'; this.scope.state = []; this.scope.refreshBacklogData(this.ticketType, this.days); expect(this.scope.state['workorderBacklogIsLoading']).toBe(true); this.scope.$apply(); expect(this.scope['workorderRadioModel']).toEqual('30'); expect(this.chartModel['workorderBacklogDateRange']).toEqual('30'); expect(this.scope.state['workorderBacklogIsLoading']).toBe(false); }); it('should fetch Data By Company ', function () { this.company = 'Calbro Services'; this.scope.supportGroups = []; this.scope.selectedCompany = ''; this.scope.userData = { company: { name: 'Calbro Services', site: { name: 'Headquarters, Building 1.31', address: { 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' }, region: 'Americas', siteGroup: 'United States', siteId: 'STE_SOLN0002846' } }, personId: 'PPL000000000013', supportGroups: [ { name: 'Service Desk', company: { name: 'Calbro Services' }, organization: 'IT Support', isDefault: true, id: 'SGP000000000011' } ], groups: [ { name: 'Request Catalog Manager Computed', id: 20224 } ], roles: { change: [ { name: 'Configuration Manager', id: -16001 } ], incident: [ { name: 'APP-Management', id: -481 } ] } }; this.chartModel.statsPerspective = 'myGroups'; this.myResult = this.scope.fetchDataByCompany(this.company); expect(this.scope.selectedGroup.$$state.value).toEqual('Dashboard'); expect(this.scope.selectedGroup.$$state.processScheduled).toBe(true); this.scope.$apply(); expect(this.scope.selectedCompany).toEqual('Calbro Services'); expect(this.scope.myCompanySelected).toBe(false); }); it('should fetch Data By Group ', function () { this.group = 'myGroups'; this.myResult = this.scope.fetchDataByGroup(this.group); this.scope.$apply(); console.log(this.scope.selectedGroup); expect(this.scope.filterGroups).toBeTruthy(); expect(this.scope.selectedGroup.$$state.value).toEqual('Dashboard'); expect(this.scope.selectedGroup.$$state.processScheduled).toBe(false); expect(this.scope.state.requestDataIsLoading).toBe(true); this.group = ''; this.scope.isSRMInstalled = 'test true'; this.scope.isWOInstalled = 'test true'; this.scope.isChangeInstalled = 'test true'; this.myResult = this.scope.fetchDataByGroup(this.group); this.scope.$apply(); expect(this.scope.myCompanySelected).toBe(true); }); });