SmartIT_Extensions/BMC/smart-it-full/test/app/ticket/draft-ticket-controller.spe...

145 lines
4.5 KiB
JavaScript

describe('DraftTicketController', function () {
'use strict';
var ctrl,
$controller,
$rootScope,
$scope,
ticketModel,
events,
$httpBackend,
smartRecorderModel,
metadataModel,
layoutConfigurationModel,
deferred,
$q;
beforeEach(module('myitsmApp'));
beforeEach(inject(function (_$controller_, _$rootScope_, _ticketModel_, _events_, $injector, _smartRecorderModel_, _metadataModel_, _layoutConfigurationModel_, _$q_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
ticketModel =_ticketModel_;
events = _events_;
$httpBackend = $injector.get('$httpBackend');
smartRecorderModel = _smartRecorderModel_;
metadataModel = _metadataModel_;
layoutConfigurationModel = _layoutConfigurationModel_;
deferred = _$q_.defer();
$q = _$q_;
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('smartit/rest/map_api_properties').respond(200);
$httpBackend.whenGET('views/smart-recorder/smart-recorder.html').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2').respond(200);
ctrl = $controller('DraftTicketController', {
$scope: $scope
});
$scope.basicData = {
"type": "incident",
"resolvedDate": null,
"resCategorizations": [],
"impact": "4-Minor/Localized",
"urgency": "4-Low",
"resolution": null,
"templateId": "",
"serviceType": "User Service Restoration",
"brokerVendorName": "",
"id": "IDGAA5V0GEWV1API445SPH7P0UJ9MW",
"displayId": "INC6036",
"summary": "Paula Abdul",
"desc": "Paula Abdul",
"customer": {},
"categorizations": [],
"customFields": {},
"accessMappings": {},
"allCategories": [],
"noCategories": 0,
"ticketType": "incident",
"attachments": [],
"priority": "Low"
};
}));
it('should exist', function () {
expect(ctrl).toBeDefined();
});
it('should broadcast HIDE_TICKET_DRAFT_LOADER if there is any error while saving incident', function () {
var errorMsg = { "data": "Dummy Error Message" };
spyOn($scope, '$broadcast');
spyOn(ticketModel, 'saveDraft').and.callFake(function () {
deferred.reject(errorMsg);
return deferred.promise;
});
$scope.state = {};
$scope.type = "incident";
$scope.saveDraft();
$scope.$digest();
expect($scope.$broadcast).toHaveBeenCalledWith(events.HIDE_TICKET_DRAFT_LOADER);
});
it('should test if the user input desc and template desc are added', function () {
var data = {
id: 123,
desc: 'SmartIT123'
};
spyOn(ticketModel, 'getDraft').and.callFake(function () {
var def = $q.defer();
def.resolve(data);
return def.promise;
});
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
var def = $q.defer();
def.resolve({
configurationParameters : {
affectedServiceRelation : true
}
});
return def.promise;
});
spyOn(layoutConfigurationModel, 'loadScreenLayout').and.callFake(function () {
var def = $q.defer();
def.resolve({});
return def.promise;
});
spyOn($q, 'all').and.callFake(function () {
var def = $q.defer();
def.resolve({});
return def.promise;
});
smartRecorderModel.smartRecorderData = {
desc: 'Test123'
};
$scope.basicData = {
desc: 'SmartIT123'
};
$scope.itemId = 123;
$scope.relationCounters = {};
$scope.initDetails();
$scope.$digest();
expect($scope.basicData.desc).toBe('Test123' + '\n' + 'SmartIT123 ');
});
});