SmartIT_Extensions/BMC/smart-it-full/test/app/ticket/preview-ticket-controller.s...

261 lines
11 KiB
JavaScript

describe('PreviewTicketController', function () {
var $httpBackend;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($injector, $rootScope, $controller, $q, ticketModel, categoriesService, ticketActionService, screenConfigurationModel, followService, events, systemAlertService, srdModel, metadataModel, layoutConfigurationModel) {
$httpBackend = $injector.get('$httpBackend');
this.$rootScope = $rootScope;
this.scope = $rootScope.$new();
this.controller = $controller;
this.$q = $q;
this.ticketModel = ticketModel;
this.categoriesService = categoriesService;
this.ticketActionService = ticketActionService;
this.followService = followService;
this.screenConfigurationModel = screenConfigurationModel;
this.events = events;
this.systemAlertService = systemAlertService;
this.srdModel = srdModel;
this.metadataModel = metadataModel;
this.layoutConfigurationModel = layoutConfigurationModel;
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/%5Bobject%20Object%5D/%5Bobject%20Object%5D').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=%7B%7D').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2').respond(200);
$httpBackend.whenGET('/smartit/rest/customization/screenlayout?datasource=%7B%22testType%22:%22test+foo%22%7D&screenId=incidentViewScreen').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=global').respond(200);
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
this.controllerInstance = this.controller('PreviewTicketController', {
$scope: this.scope
});
}));
beforeEach(function () {
this.id = {
id: 1233
};
this.type = {
testType: 'test foo'
};
});
afterEach(inject(function ($rootScope) {
$rootScope.$apply();
}));
it('should defined', function () {
expect(this.controllerInstance).toBeDefined();
});
it('should run init for set all objects', function () {
this.scope.init(this.id, this.type);
});
describe('init() for INCIDENCE OBJECT', function () {
beforeEach(inject(function ($q, $rootScope) {
var deferred = $q.defer(), incidenceVOForElse = {
type: 'incident',
resolvedDate: null,
resCategorizations: [
{
name: 'resolutionProduct',
tiers: {}
},
{
name: 'resolution',
tiers: {}
}
],
status: {
value: 'Assigned'
},
assignee: {
customFields: {}
},
customer: {
firstName: 'Allen',
lastName: 'Allbrook',
company: {
name: 'Calbro Services'
}
},
contact: {
firstName: 'Allen',
lastName: 'Allbrook',
company: {
name: 'Calbro Services'
}
},
categorizations: [
{
name: 'operational',
tiers: {}
},
{
name: 'product',
tiers: {}
}
],
accessMappings: {
detailsEditAllowed: true,
statusEditAllowed: true,
priorityEditAllowed: true,
timelineEditAllowed: true,
relationsEditAllowed: true,
tasksEditAllowed: true,
assigneeSelfAssignmentAllowed: true,
incidentTypeEditAllowed: true,
requestedforEditAllowed: true,
resolutionNoteEditAllowed: true,
copyActionAllowed: true,
duplicateActionAllowed: true,
reopenActionAllowed: false
},
dynamicFields: [],
company: {
name: 'Calbro Services'
},
isClosed: function () {
return false;
}
}, layoutDataVO = {
id: 'AGGAA5V0HG8SIAOSYVXNABCS8RNIK3',
name: 'incidentViewScreen',
layout: 'row'
},
screenConfigurationVO = {
type: 'incident',
resolvedDate: null,
resCategorizations: [
{
name: 'resolutionProduct',
tiers: {}
},
{
name: 'resolution',
tiers: {}
}
],
impactedService: {
needsReconciliation: false,
verified: false,
customFields: {}
},
causalCI: {
needsReconciliation: false,
verified: false,
customFields: {}
},
brokerVendorName: 'test fooo',
customer: {
firstName: 'Allen',
lastName: 'Allbrook',
company: {
name: 'Calbro Services'
}
},
contact: {
firstName: 'Allen',
lastName: 'Allbrook',
company: {
name: 'Calbro Services'
}
},
categorizations: [
{
name: 'operational',
tiers: {}
},
{
name: 'product',
tiers: {}
}
],
customFields: {},
following: false,
accessMappings: {
detailsEditAllowed: true,
statusEditAllowed: true,
priorityEditAllowed: true,
timelineEditAllowed: true,
relationsEditAllowed: true,
tasksEditAllowed: true,
assigneeSelfAssignmentAllowed: true,
incidentTypeEditAllowed: true,
requestedforEditAllowed: true,
resolutionNoteEditAllowed: true,
copyActionAllowed: true,
duplicateActionAllowed: true,
reopenActionAllowed: false
},
locationCompany: {
name: 'Calbro Services'
},
ownerGroup: {
company: {
name: 'Calbro Services'
},
id: 'SGP000000000011'
},
isClosed: function () {
return false;
}
}, success = 'success';
spyOn(this.layoutConfigurationModel, 'loadScreenLayout').and.callFake(function () {
deferred.resolve(layoutDataVO);
return deferred.promise;
});
spyOn(this.ticketModel, 'getTicketForPreview').and.callFake(function () {
deferred.resolve(incidenceVOForElse);
return deferred.promise;
});
spyOn(this.screenConfigurationModel, 'getScreenNameByTicketType').and.callFake(function () {
deferred.resolve(screenConfigurationVO);
return deferred.promise;
});
spyOn(this.screenConfigurationModel, 'loadFieldsLabels').and.callFake(function () {
deferred.resolve(screenConfigurationVO);
return deferred.promise;
});
spyOn(this.screenConfigurationModel, 'loadScreenConfigurationAndCustomFieldLabels').and.callFake(function () {
deferred.resolve(screenConfigurationVO);
return deferred.promise;
});
spyOn(this.ticketModel, 'getVendorInfo').and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
}));
it('should assign correct flows values ticket of type INCIDENCE', function () {
this.scope.init(this.id, this.type);
this.scope.$apply();
expect(this.scope.isFullVersion).toBeFalsy();
expect(this.scope.basicData.accessMappings.detailsEditAllowed).toBeFalsy();
expect(this.scope.basicData.accessMappings.statusEditAllowed).toBeFalsy();
expect(this.scope.basicData.accessMappings.riskEditAllowed).toBeFalsy();
expect(this.scope.basicData.accessMappings.datesEditAllowed).toBeFalsy();
expect(this.scope.basicData.categorizations).toBeTruthy();
expect(this.scope.basicData.categorizations).toContain({ name: 'operational', tiers: {}});
expect(this.scope.basicData.brokerVendorName).toBe('test fooo');
expect(this.scope.metadata).toBeTruthy();
expect(this.scope.screenLayout).toBeTruthy();
});
});
});