describe('Test editable layout section directive', function () { 'use strict'; var compile, scope, element, $httpBackend, directiveElem, divElem, objectValueMapperService, deferred, ticketModel, ctrlScope, spyGetFieldList, resNoteFieldList, personSiteFieldList, metadata = new MetadataVO(); beforeEach(module('myitsmApp', 'templates')); beforeEach(function () { inject(function ($compile, $rootScope, $injector, $q, events) { this.events = events; $httpBackend = $injector.get('$httpBackend'); deferred = $q.defer(); 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/v2/metadata?type=global').respond(200, 'success'); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200, 'success'); $httpBackend.expect('GET', '/smartit/rest/v2/metadata').respond(200, 'success'); compile = $compile; scope = $rootScope.$new(); scope.ticket = { type: EntityVO.TYPE_INCIDENT, customFields: { reportedSource: 2000 } }; }); }); beforeEach(function () { inject(function (_objectValueMapperService_, _ticketModel_) { var deskLocation = { 'name': 'deskLocation', 'label': 'Desk Location', 'arFieldName': 'Desk Location', 'type': 'characterField', 'dataType': 'text', 'required': false, 'requiredCondition': '', 'requiredConditionFlag': 0, 'itsmRequired': false, 'editable': true, 'readOnly': false, 'readOnlyCondition': '', 'readOnlyConditionFlag': 0, 'hide': false, 'hideCondition': '', 'hideConditionFlag': 0, 'setValueCondition': '', 'setValueConditionFlag': false, 'displayOrder': 1, 'order': 0, 'columnIndex': 0, 'hideLabel': false, 'accessible': true, 'min': 0, 'max': 0, 'maxLength': 30, 'precision': 0, 'availability': 0, 'menu': null, 'dependency': [], 'fieldUnavailableOn': [], 'valueField': null, 'members': [], 'options': [], 'groupMember': false, 'rowCount': 1, 'expanded': false, 'sealed': false, 'hasValue': true, 'isDynamic': false, 'widgetMember': false, 'value': 'test', 'extension': [], 'isRequired': false, 'isReadOnly': false, 'isHidden': false, 'isMapped': false, 'selectionDisabled': false, 'mappedAction': null, 'selectedIcon': '', 'setValueFlag': '#$#', 'id': 'IDGAA5V0H4A0NAPGB70UPFEVD34PDM', 'itsmFieldId': 1000000035, 'ootb': false }; deskLocation = new FieldVO().build(deskLocation); var reportedSource = { 'name': 'reportedSource', 'label': 'Reported Source', 'arFieldName': 'Reported Source', 'type': 'staticSelectionField', 'dataType': 'dropdown', 'required': false, 'requiredCondition': '', 'requiredConditionFlag': 0, 'itsmRequired': false, 'editable': true, 'readOnly': false, 'readOnlyCondition': '', 'readOnlyConditionFlag': 0, 'hide': false, 'hideCondition': '', 'hideConditionFlag': 0, 'setValueCondition': '', 'setValueConditionFlag': false, 'displayOrder': 0, 'order': 0, 'columnIndex': 0, 'hideLabel': false, 'accessible': true, 'min': 0, 'max': 0, 'maxLength': 0, 'precision': 0, 'availability': 0, 'menu': null, 'dependency': [], 'fieldUnavailableOn': [], 'valueField': null, 'members': [], 'options': [{ 'index': 1000, 'name': 'Direct Input', 'label': 'Direct Input', '$$hashKey': 'object:1394' }, { 'index': 2000, 'name': 'Email', 'label': 'Email', '$$hashKey': 'object:1395' }, { 'index': 3000, 'name': 'External Escalation', 'label': 'External Escalation', '$$hashKey': 'object:1396' }, { 'index': 4000, 'name': 'Fax', 'label': 'Fax', '$$hashKey': 'object:1397' }, { 'index': 4200, 'name': 'Self Service', 'label': 'Self Service', '$$hashKey': 'object:1398' }, { 'index': 5000, 'name': 'Systems Management', 'label': 'Systems Management', '$$hashKey': 'object:1399' }, { 'index': 6000, 'name': 'Phone', 'label': 'Phone', '$$hashKey': 'object:1400' }, { 'index': 7000, 'name': 'Voice Mail', 'label': 'Voice Mail', '$$hashKey': 'object:1401' }, { 'index': 8000, 'name': 'Walk In', 'label': 'Walk In', '$$hashKey': 'object:1402' }, { 'index': 9000, 'name': 'Web', 'label': 'Web', '$$hashKey': 'object:1403' }, { 'index': 10000, 'name': 'Other', 'label': 'Other', '$$hashKey': 'object:1404' }, { 'index': 11000, 'name': 'BMC Impact Manager Event', 'label': 'BMC Impact Manager Event', '$$hashKey': 'object:1405' }], 'groupMember': false, 'rowCount': 0, 'expanded': false, 'sealed': false, 'hasValue': true, 'isDynamic': false, 'widgetMember': false, 'value': 2000, 'extension': [], 'isRequired': false, 'isReadOnly': false, 'isHidden': false, 'isMapped': false, 'selectionDisabled': false, 'mappedAction': null, 'selectedIcon': '', 'setValueFlag': '#$#', 'id': 'IDGAA5V0H4A0NAPGB5WXPFETP74OUD', 'itsmFieldId': 1000000215, 'ootb': false, 'radioFieldVal': 2000 }; reportedSource = new FieldVO().build(reportedSource); var status = { "name": "status", "label": "", "arFieldName": "", "type": "characterField", "dataType": "text", "required": false, "requiredCondition": "", "requiredConditionFlag": 0, "itsmRequired": false, "editable": true, "readOnly": false, "readOnlyCondition": "", "readOnlyConditionFlag": 0, "hide": false, "hideCondition": "", "hideConditionFlag": 0, "setValueCondition": "", "setValueConditionFlag": false, "displayOrder": 0, "order": 0, "columnIndex": 0, "hideLabel": false, "accessible": true, "min": 0, "max": 0, "maxLength": 0, "precision": 0, "availability": 0, "menu": null, "dependency": [], "fieldUnavailableOn": [], "valueField": null, "members": [], "options": [], "groupMember": false, "rowCount": 0, "expanded": false, "sealed": false, "hasValue": false, "isDynamic": false, "widgetMember": false, "value": "Scheduled For Review", "extension": [], "isRequired": false, "isReadOnly": false, "isHidden": false, "isMapped": false, "selectionDisabled": false, "mappedAction": null, "selectedIcon": "", "setValueFlag": "#$#", "ootb": true }; status = new FieldVO().build(status); var fieldsList = {}; fieldsList.deskLocation = deskLocation; fieldsList.reportedSource = reportedSource; fieldsList.status = status; resNoteFieldList = {}; resNoteFieldList.resolution = { "name": "resolution", "type": "characterField", "dataType": "text", "widgetMember": false, "value": "test", "extension": [], "isRequired": false, "isReadOnly": true, "isHidden": false, "setValueFlag": "#$#", "ootb": true, "isSupportGroupWidget": function() {return null}, "hasDataTypeValueFormat": function() {return null}, "linkedFieldExist": function () {return null} }; personSiteFieldList = { name: 'site', type: 'personSite', value: { 'site': { 'name': 'Headquarters, Building 1.31', 'id': 'STE_SOLN0002846', 'attributeMap': { 'companyName': 'Calbro Services', 'regionName': 'Americas', 'siteId': 'STE_SOLN0002846', 'siteAddress': { 'street': '1114 Eighth Avenue, 31st Floor.', 'state': 'New York', 'country': 'United States', 'zip': '10036', 'address': '1114 Eighth Avenue, 31st Floor.\r\nNew York, New York 10036\r\nUnited States' }, 'siteGroupName': 'United States' } }, 'siteGroup': { 'name': 'United States', 'attributeMap': { 'regionName': 'Americas' } }, 'region': { 'name': 'Americas' }, 'company': { 'name': 'Calbro Services' } } }; personSiteFieldList = new FieldVO().build(personSiteFieldList); objectValueMapperService = _objectValueMapperService_; ticketModel = _ticketModel_; spyOn(objectValueMapperService, 'changeMode').and.callFake(function () { deferred.resolve({}); return deferred.promise; }); spyGetFieldList = spyOn(objectValueMapperService, 'getFieldList').and.callFake(function (data) { return fieldsList; }); spyOn(objectValueMapperService, 'getWidgetMembers').and.callFake(function () { deferred.resolve({}); return deferred.promise; }); spyOn(objectValueMapperService, 'getValueByFieldName').and.callFake(function () { return; }); spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function () { return {}; }); spyOn(ticketModel, 'update').and.callFake(function () { deferred.resolve({}); return deferred.promise; }); }); }); function getCompiledElement() { var compiledElement; element = angular.element(''); compiledElement = compile(element)(scope); scope.$digest(); scope.$apply(); ctrlScope = element.isolateScope() || element.scope(); spyOn(ctrlScope, '$emit'); return compiledElement; } it('should compile', function () { directiveElem = getCompiledElement(); divElem = directiveElem[0]; expect(divElem.className).toBeDefined(); }); it('should send all custom fields if ticket in draft mode', function () { metadata.ootbMapping = { status: ["status.value"] }; directiveElem = getCompiledElement(); divElem = directiveElem[0]; ctrlScope.ticket = scope.ticket; ctrlScope.ticket.isDraft = true; ctrlScope.isDraft = true; ctrlScope.metadata = metadata; ctrlScope.onEditButtonClick(); ctrlScope.$apply(); ctrlScope.$parent.$parent.$parent = {}; ctrlScope.onSaveClick(); ctrlScope.$apply(); expect(ctrlScope.ticket.customFields).toEqual({ deskLocation: 'test', reportedSource: 2000 }); }); it('should return empty changelist for change ticket type if change coordinator not set', function () { metadata.ootbMapping = { status: ["status.value"] }; scope.ticket.type = EntityVO.TYPE_CHANGE; directiveElem = getCompiledElement(); divElem = directiveElem[0]; ctrlScope.ticket = scope.ticket; ctrlScope.metadata = metadata; ctrlScope.onEditButtonClick(); ctrlScope.$apply(); ctrlScope.$parent.$parent.$parent = {}; ctrlScope.onSaveClick(); ctrlScope.$apply(); expect(ctrlScope.ticket.status).toEqual(undefined); }); it('should set the ticket.resolution with resNote value for draft tickets while saving incident tickets', function () { metadata.ootbMapping = { status: ["status.value"] }; scope.ticket.type = EntityVO.TYPE_CHANGE; directiveElem = getCompiledElement(); divElem = directiveElem[0]; ctrlScope.ticket = scope.ticket; ctrlScope.metadata = metadata; ctrlScope.onEditButtonClick(); ctrlScope.$apply(); ctrlScope.$parent.$parent.$parent = {}; ctrlScope.isDraft = true; ctrlScope.ticket.resolution = null; spyGetFieldList.and.returnValue(resNoteFieldList); ctrlScope.onSaveClick(); ctrlScope.$apply(); expect(ctrlScope.ticket.resolution).toEqual("test"); }); it(' should set site address fields to blank if no value is set for the same', function () { scope.ticket.type = EntityVO.TYPE_INCIDENT; scope.ticket.customer = { site: {} }; directiveElem = getCompiledElement(); divElem = directiveElem[0]; ctrlScope.ticket = scope.ticket; ctrlScope.onEditButtonClick(); ctrlScope.$apply(); ctrlScope.$parent.$parent.$parent = {}; ctrlScope.isDraft = true; spyGetFieldList.and.returnValue({ site: personSiteFieldList }); ctrlScope.onSaveClick(); ctrlScope.$apply(); expect(ctrlScope.ticket.customer.site.address.city).toEqual(''); expect(ctrlScope.ticket.customer.site.address.state).toEqual('New York'); }); });