87 lines
3.2 KiB
JavaScript
87 lines
3.2 KiB
JavaScript
/*** Created by npatil2.*/
|
|
describe('service: approvalModel', function () {
|
|
var $httpBackend, $rootScope, scope;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($injector, $rootScope, approvalService, $q, systemAlertService, $filter) {
|
|
scope = $rootScope.$new();
|
|
$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.approvalModel = $injector.get('approvalModel');
|
|
this.approvalService = approvalService;
|
|
this.$q = $q;
|
|
this.systemAlertService = systemAlertService;
|
|
this.$filter = $filter;
|
|
}));
|
|
|
|
beforeEach(inject(function ($q) {
|
|
var deferred = $q.defer(), params = ['test', 'test1', 'test2'], error = {
|
|
data: {
|
|
error: 'test error'
|
|
}
|
|
}, searchText = 'incident';
|
|
|
|
spyOn(this.approvalService, 'getListOfApprovers').and.callFake(function () {
|
|
deferred.resolve(params);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.approvalService, 'sendReviewResult').and.callFake(function () {
|
|
deferred.resolve(searchText);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.approvalService, 'getApproverByText').and.callFake(function () {
|
|
deferred.resolve(params);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.approvalService, 'addApprover').and.callFake(function () {
|
|
deferred.resolve(searchText);
|
|
return deferred.promise;
|
|
});
|
|
}));
|
|
|
|
it('should return List Of Approvers ', function () {
|
|
this.approvalModel.approvals = ['test', 'test1', 'test2', 'test3'];
|
|
this.context = {
|
|
id: 123
|
|
};
|
|
|
|
this.ignoreCache = null;
|
|
this.myResult = this.approvalModel.getListOfApprovers(this.context, this.ignoreCache);
|
|
scope.$apply();
|
|
expect(this.approvalModel.approvals).toBeTruthy();
|
|
expect(this.myResult.$$state.status).toEqual(1);
|
|
expect(this.myResult.$$state.value[0]).toEqual('test');
|
|
});
|
|
|
|
it('should send review results', function () {
|
|
this.approval = [parentId = 'test'];
|
|
this.myResult = this.approvalModel.sendReviewResult(this.approval);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toEqual('incident');
|
|
});
|
|
|
|
it('should return Approver By Text', function () {
|
|
this.searchText = 'incident';
|
|
this.myResult = this.approvalModel.getApproverByText(this.searchText);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value[0]).toEqual('test');
|
|
});
|
|
|
|
it('should add Approver ', function () {
|
|
this.myResult = this.approvalModel.addApprover();
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toEqual('incident');
|
|
});
|
|
}); |