/*** Created by npatil2.*/ describe('service: chartModel', function () { var $httpBackend, $rootScope, scope; beforeEach(module('myitsmApp')); beforeEach(inject(function ($rootScope, $injector, chartService, configurationModel, $q, $filter) { scope = $rootScope.$new(); this.chartService = chartService; this.configurationModel = configurationModel; this.$q = $q; this.$filter = $filter; $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.when('POST', '/smartit/rest/v2/foundation/mtcstats/get').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/v2/metadata?type=workorder').respond(200); $rootScope = $injector.get('$rootScope'); this.chartModel = $injector.get('chartModel'); })); beforeEach(inject(function ($q) { var deferred = $q.defer(), data = 'success', response = { objects: [ { name: 'workorder-backlog-all', primaryGroupBy: 'createDate', statsMetrics: [ { name: 1506142800000, value: 0 } ] }, { name: 'workorder-backlog-critical', primaryGroupBy: 'createDate', statsMetrics: [ { name: 1506142800000, value: 0 } ] }, { name: 'workorder-kpi', primaryGroupBy: 'createDate', statsMetrics: [ { name: 1506142800000, value: 0 } ] }, { name: 'workorder-open', primaryGroupBy: 'createDate', statsMetrics: [ { name: 1506142800000, value: 0 } ] } ], totalMatches: 0 }; spyOn(this.configurationModel, 'get').and.callFake(function () { deferred.resolve(response); return deferred.promise; }); spyOn(this.chartService, 'getChangeData').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.chartService, 'getChartStatisticsData').and.callFake(function () { deferred.resolve(response); return deferred.promise; }); })); it('should be defined', function () { expect(this.chartModel).toBeDefined(); }); it('should return Chart Statistics Data', function () { this.ticketType = 'workorder'; this.chartTypes = []; this.companies = 'collabroService'; this.supportGroups = 'test supportGrup'; this.days = 365; this.myResult = this.chartModel.getChartStatisticsData(this.ticketType, this.chartTypes, this.companies, this.supportGroups, this.days); expect(this.chartModel['workorderStatsDataRetrieving']).toEqual(true); expect(this.chartModel['workorderStatsDataPromise']).toBeDefined(); }); it('should fetch Data', function () { this.ticketType = 'workorder'; this.chartTypes = []; this.companies = 'collabroService'; this.supportGroups = 'test supportGrup'; this.days = 365; this.myResult = this.chartModel.fetchData(this.ticketType, this.chartTypes, this.companies, this.supportGroups, this.days); scope.$apply(); expect(this.chartModel['workorderStatsDataCache']['workorderKeyPerformanceData']).toBeDefined(); expect(this.chartModel['workorderStatsDataCache']['workorderMultiBarChartData']).toBeDefined(); expect(this.chartModel['workorderStatsDataRetrieving']).toEqual(false); }); it('should return Change Data', function () { this.companies = 'collabroService'; this.supportGroups = 'testSupportGroup'; this.myResult = this.chartModel.getChangeData(this.companies, this.supportGroups); scope.$apply(); expect(this.chartModel.statsConfig).toBeDefined(); expect(this.chartModel.statsConfig.$$state.processScheduled).toBe(false); }); it('should clear Cache', function () { this.ticketType = 'workorder'; this.chartModel.clearCache(this.ticketType); expect(this.chartModel['workorderStatsDataCache']).toBeDefined(); }); });