SmartIT_Extensions/BMC/smart-it-full/test/app/change/create-change-v2-controller...

77 lines
2.8 KiB
JavaScript

describe('CreateChangeV2Controller', function () {
'use strict';
var ctrl,
$controller,
$rootScope,
$httpBackend,
scope,
configurationModel,
relationModel,
objectValueMapperService;
beforeEach(module('myitsmApp'));
beforeEach(inject(function (_$controller_, _$rootScope_, $injector, _configurationModel_, _relationModel_, _objectValueMapperService_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
configurationModel = _configurationModel_;
scope = $rootScope.$new();
relationModel = _relationModel_;
objectValueMapperService = _objectValueMapperService_;
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=change').respond(200);
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/customization/screenlayout?screen=createChangeScreen').respond(200, []);
$httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=createChangeScreen').respond(200, []);
$httpBackend.whenPOST('/smartit/rest/v2/change').respond('[{"items": [{"objects": [], "totalMatches": 0}], "numMatch": 0}]');
configurationModel.isServerApplicationEnabled = jasmine.createSpy('isServerApplicationEnabled').and.callFake(function () {
return function () {
return true;
};
});
ctrl = $controller('CreateChangeV2Controller', {
$scope: scope
});
scope.template = {
selected: {
id: 'AG00123F73CF5EK3sTSQD73rAAa_QA'
}
};
}));
it('should exist', function () {
expect(ctrl).toBeDefined();
});
it('should call getRelations', function () {
spyOn(scope, 'createDraftChange').and.callThrough();
spyOn(relationModel, 'getRelations').and.callThrough();
});
it('should set the timing value when added as non-widget field', function () {
var fieldValue = {
value: {
name: 'No Impact'
}
};
spyOn(objectValueMapperService, 'getFieldByName').and.returnValue(fieldValue);
spyOn(objectValueMapperService, 'setValueByFieldName');
scope.createChangeRequest();
scope.$apply();
expect(objectValueMapperService.setValueByFieldName).toHaveBeenCalled();
});
});