145 lines
5.2 KiB
JavaScript
145 lines
5.2 KiB
JavaScript
/*** Created by npatil2.*/
|
|
describe('service: collisionModel', function () {
|
|
var $httpBackend, $rootScope, scope, response;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($rootScope, $injector, collisionService, $q) {
|
|
scope = $rootScope.$new();
|
|
this.collisionService = collisionService;
|
|
this.$q = $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('views/dashboard/index.html').respond(200);
|
|
|
|
$rootScope = $injector.get('$rootScope');
|
|
this.collisionModel = $injector.get('collisionModel');
|
|
}));
|
|
|
|
beforeEach(inject(function ($q) {
|
|
var deferred = $q.defer(), data = 'success', response = {
|
|
items: [
|
|
{
|
|
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.collisionService, 'getListOfCollisionsById').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.collisionService, 'getListOfCollisionsAndCiByDate').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.collisionService, 'getListOfCollisionsByDate').and.callFake(function () {
|
|
deferred.resolve(response);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.collisionService, 'addCollisionStatuses').and.callFake(function () {
|
|
deferred.resolve(response);
|
|
return deferred.promise;
|
|
});
|
|
|
|
}));
|
|
|
|
it('should be defined', function () {
|
|
expect(this.collisionModel).toBeDefined();
|
|
});
|
|
|
|
it('should fetch Data', function () {
|
|
this.context = 'context';
|
|
this.includeCIDetails = 'includeCIDetails';
|
|
this.myResult = this.collisionModel.getListOfCollisionsById(this.context, this.includeCIDetails);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toBe('success');
|
|
});
|
|
|
|
it('should return List Of Collisions And Ci By Date', function () {
|
|
this.start = new Date();
|
|
this.end = new Date();
|
|
this.linkedCIs = 'test';
|
|
this.myResult = this.collisionModel.getListOfCollisionsAndCiByDate(this.start, this.end, this.linkedCIs);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toBe('success');
|
|
});
|
|
|
|
it('should return List Of Collisions By Date ', function () {
|
|
this.contextId = 123;
|
|
this.start = new Date();
|
|
this.end = new Date();
|
|
this.linkedCIs = ['test', 'test1', 'test2'];
|
|
this.filters = 'test filter';
|
|
this.myResult = this.collisionModel.getListOfCollisionsByDate(this.contextId, this.start, this.end, this.linkedCIs, this.filters);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.changeRequests).toBeDefined();
|
|
expect(this.myResult.$$state.value.outages).toBeDefined();
|
|
expect(this.myResult.$$state.value.businessEvents).toBeDefined();
|
|
|
|
});
|
|
|
|
it('should add Collision Statuses ', function () {
|
|
this.collisionPayload = 'test';
|
|
this.id = '123';
|
|
this.myResult = this.collisionModel.addCollisionStatuses(this.collisionPayload, this.id);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.items).toBeDefined();
|
|
});
|
|
|
|
it('should add Collision Statuses ', function () {
|
|
this.collisionPayload = 'test';
|
|
this.id = '123';
|
|
this.myResult = this.collisionModel.addCollisionStatuses(this.collisionPayload, this.id);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.items).toBeDefined();
|
|
});
|
|
}); |