describe('AssignController', function () { 'use strict'; var ctrl, $controller, $rootScope, $scope, $httpBackend, modalInstance, assignParams, screenConfigurationModel, $timeout, objectValueMapperService, systemAlertService; beforeEach(module('myitsmApp', 'ticketModule')); beforeEach(inject(function (_$controller_, _$rootScope_, $injector, _screenConfigurationModel_, _$timeout_, _objectValueMapperService_, _systemAlertService_) { $controller = _$controller_; $rootScope = _$rootScope_; $scope = $rootScope.$new(); $httpBackend = $injector.get('$httpBackend'); screenConfigurationModel = _screenConfigurationModel_; $timeout = _$timeout_; objectValueMapperService = _objectValueMapperService_; systemAlertService = _systemAlertService_; assignParams = { "ticket": {}, "isDraft": true, "role": null, "activeRole": "workordermanager" }; 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); modalInstance = { close: jasmine.createSpy('modalInstance.close'), dismiss: jasmine.createSpy('modalInstance.dismiss'), result: { then: jasmine.createSpy('modalInstance.result.then') } }; })); function initController() { ctrl = $controller('AssignController', { $scope: $scope, $modalInstance: modalInstance, assignParams: assignParams }); } it('should exist', function () { initController(); expect(ctrl).toBeDefined(); }); it('should successfully assign support manager group', function () { initController(); $scope.ticket = { 'type': 'workorder', 'id': 'IDGAA5V0GEWV1API69O1PH9U93CFED' }; $scope.submit(); $scope.$digest(); expect(modalInstance.close).toHaveBeenCalled(); }); describe('if ticket type is task then it', function () { beforeEach(function () { assignParams = { "ticket": { "name": "task title updateTask [Administrator@clm-aus-003527] Sat Jul 25 06:58:22 EEST 2015", "id": "TMGAA5V0HG8PDANSAZB471EWVKRIMG", "type": "task", "status": { "value": "Staged" }, "assignee": { "fullName": "Allen Allbrook", "loginId": "Allen", "thumbnail": "", "customFields": {}, "id": "Allen" }, "supportGroup": { "name": "Frontoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000010", "supportGroups": "Frontoffice Support" }, "customFields": {}, "company": { "name": "Calbro Services" }, "ticketType": "task" }, "isDraft": false, "role": null, "activeRole": "ticketassignee" }; spyOn(screenConfigurationModel, 'getAssignmentPanel').and.returnValue({}); spyOn(screenConfigurationModel, 'initFieldValues'); }); it('should initialize default values according to assignParams', function () { initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.isDraft).toBeFalsy(); expect($scope.ticketassignee).toBeTruthy(); expect($scope.hideTabs).toBeTruthy(); expect($scope.ticket.type).toBe('task'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Frontoffice Support'); expect($scope.selectedAssignee.person.id).toBe('Allen'); expect($scope.state.isDraft).toBeFalsy(); }); }); describe('if ticket type is change then it', function () { var currentAssignee, curSupportGroup, curChangeManager, curChangeManagerSupportGroup; function setActiveRole(activeRole) { assignParams.activeRole = activeRole; } beforeEach(function () { assignParams = { "ticket": { "type": "change", "manager": { "fullName": "Mary Mann", "loginId": "Mary", "thumbnail": "", "customFields": {}, "id": "Mary" }, "managerGroup": { "name": "Service Desk", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000011" }, "id": "AG00123F73CF5EWtETSQsWU8Ag_UgB", "status": { "value": "Draft" }, "assignee": { "fullName": "Ian Plyment", "company": { "name": "Calbro Services" }, "loginId": "Ian", "thumbnail": "", "organization": "IT Support", "customFields": {}, "id": "Ian" }, "supportGroup": { "name": "Frontoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000010" }, "customFields": {}, "company": { "name": "Calbro Services" }, "ticketType": "change" }, "isDraft": false, "role": null, "activeRole": "changemanager" }; currentAssignee = { isReadOnly: false, value: { "fullName": "Ian Plyment", "company": { "name": "Calbro Services" }, "loginId": "Ian", "thumbnail": "", "organization": "IT Support", "customFields": {}, "id": "Ian", "supportGroupId": "SGP000000000010", "supportGroup": "Frontoffice Support" }, assigneeLoginId: "Ian" }; curSupportGroup = { value: { "name": "Frontoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000010", "supportGroups": "Frontoffice Support" } }; curChangeManager = { isReadOnly: false, value: { "fullName": "Mary Mann", "loginId": "Mary", "thumbnail": "", "customFields": {}, "id": "Mary", "supportGroupId": "SGP000000000010", "supportGroup": "Frontoffice Support" }, assigneeLoginId: "Mary" }; curChangeManagerSupportGroup = { value: { "name": "Service Desk", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000011", "supportGroups": "Service Desk" } } spyOn(screenConfigurationModel, 'getAssignmentPanel').and.returnValue({}); spyOn(screenConfigurationModel, 'initFieldValues'); spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function (input) { if(input === 'changeCoordinator') { input = currentAssignee; } else if(input === 'changeCoordinatorSupportGroups') { input = curSupportGroup; } else if(input === 'changeManager') { input = curChangeManager; } else if(input === 'changeManagerSupportGroups') { input = curChangeManagerSupportGroup; } return input; }); }); it('should initialize default values in case of change manager according to assignParams', function () { setActiveRole('changemanager'); initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.isDraft).toBeFalsy(); expect($scope.changemanager).toBeTruthy(); expect($scope.hideTabs).toBeFalsy(); expect($scope.ticket.type).toBe('change'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Frontoffice Support'); expect($scope.selectedAssignee.person.id).toBe('Ian'); expect($scope.selectedManager.person.id).toBe('Mary'); expect($scope.state.isDraft).toBeFalsy(); }); it('should initialize default values in case of change coordinator according to assignParams', function () { setActiveRole('changecoordinator'); initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.isDraft).toBeFalsy(); expect($scope.changecoordinator).toBeTruthy(); expect($scope.hideTabs).toBeFalsy(); expect($scope.ticket.type).toBe('change'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Frontoffice Support'); expect($scope.selectedAssignee.person.id).toBe('Ian'); expect($scope.selectedManager.person.id).toBe('Mary'); expect($scope.state.isDraft).toBeFalsy(); }); }); describe('if ticket type is incident then it', function () { beforeEach(function () { var curAssignee = { "fullName": "Ian Plyment", "loginId": "Ian", "thumbnail": "", "customFields": {}, "id": "Ian", "jid": "ian_000000000000001", "available": "offline" }, curSupportGroup = { "name": "Frontoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000010", "supportGroups": "Frontoffice Support" }; assignParams = { "ticket": { "type": "incident", "id": "AG00123F73CF5Eqc4TSQTOQxAgc0QB", "status": { "value": "Pending", "reason": "Client Hold" }, "assignee": { "fullName": "Ian Plyment", "loginId": "Ian", "thumbnail": "", "customFields": {}, "id": "Ian", "jid": "ian_000000000000001", "available": "offline" }, "supportGroup": { "name": "Frontoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000010" }, "customFields": {}, "company": { "name": "Calbro Services" }, }, "isDraft": false, "role": null, "activeRole": "ticketassignee" }; spyOn(screenConfigurationModel, 'getAssignmentPanel').and.returnValue({}); spyOn(screenConfigurationModel, 'initFieldValues'); spyOn(objectValueMapperService, 'getValueByFieldName').and.callFake(function (input) { if(input === 'assignee') { input = curAssignee; } else if(input === 'assigneeSupportGroups') { input = curSupportGroup; } return input; }); $scope.assignActionForm = {}; }); it('should initialize default values according to assignParams', function () { initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.isDraft).toBeFalsy(); expect($scope.ticketassignee).toBeTruthy(); expect($scope.hideTabs).toBeTruthy(); expect($scope.ticket.type).toBe('incident'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Frontoffice Support'); expect($scope.selectedAssignee.person.id).toBe('Ian'); expect($scope.state.isDraft).toBeFalsy(); expect($scope.assignActionForm.$dirty).toBeFalsy(); }); it('should close the blade if form is not dirty', function () { initController(); $scope.assignActionForm.$dirty = false; $scope.close(); $scope.$apply(); expect(modalInstance.dismiss).toHaveBeenCalled(); }); it('should show the popup if form is dirty and should close the blade if user click on yes', function () { var modalResult = { result: { then: jasmine.createSpy('result') } }; initController(); $scope.assignActionForm.$dirty = true; spyOn(systemAlertService, 'modal').and.returnValue(modalResult); $scope.close(); $scope.$apply(); expect(systemAlertService.modal).toHaveBeenCalled(); }); }); describe('if ticket type is known error then it', function () { beforeEach(function () { var panel = { "name": "Assignment", "type": "simplePanel", "columnCount": 1, "fields": [], "parentScreenId": "a5757415-07d9-4a9a-8ea0-f7940f163fe1", "parentScreenTitle": "Known Error View", "parentScreenName": "knownErrorScreen", "shortId": "assignment", "dataSource": "KnownError", "id": "knownErrorScreen.assignment" }; assignParams = { "ticket": { "type": "knownerror", "id": "AG00123F73CF5Ea4wTSQAyEvAQpA0B", "status": { "value": "Scheduled For Correction", "reason": "Pending Infrastructure Change" }, "assignee": { "fullName": "Ian Plyment", "loginId": "Ian", "thumbnail": "", "customFields": {}, "id": "Ian", "jid": "ian_000000000000001", "available": "offline" }, "supportGroup": { "name": "Service Desk", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000011" }, "customFields": {}, "company": { "name": "Calbro Services" }, "coordinator": { "fullName": "Bob Baxter", "loginId": "Bob", "thumbnail": "", "customFields": {}, "id": "Bob", "jid": "bob_000000000000002", "available": "offline" }, "coordinatorGroup": { "name": "Backoffice Support", "company": { "name": "Calbro Services" }, "organization": "IT Support", "id": "SGP000000000009" }, "ticketType": "knownerror" }, "isDraft": false, "role": null }; spyOn(screenConfigurationModel, 'getAssignmentPanel').and.returnValue(new PanelVO().build(panel)); spyOn(screenConfigurationModel, 'initFieldValues'); }); it('should initialize default values according to assignParams', function () { initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.isDraft).toBeFalsy(); expect($scope.hideTabs).toBeFalsy(); expect($scope.ticket.type).toBe('knownerror'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Service Desk'); expect($scope.selectedAssignee.person.id).toBe('Ian'); expect($scope.state.isDraft).toBeFalsy(); }); }); describe('if ticket type is work order then it', function () { function setActiveRole(activeRole) { assignParams.activeRole = activeRole; } beforeEach(function () { var curAssignee = { "fullName": "Harry Potter", "loginId": "Harry", "thumbnail": "", "customFields": {}, "id": "Harry" }, curSupportGroup = { "name": "Petramco Support Group1", "company": { "name": "Petramco" }, "organization": "Petramco Support Org1", "id": "GGP000000000016", "supportGroups": "Petramco Support Group1", "persons": [] }, curRequestManagerSupportGroup = { isReadOnly: false, value: { "name": "Petramco Support Group1", "company": { "name": "Petramco" }, "organization": "Petramco Support Org1", "id": "GGP000000000016", "supportGroups": "Petramco Support Group1", "persons": [] } }, curRequestManager = { value: { "fullName": "Harry Potter", "loginId": "Harry", "thumbnail": "", "customFields": {}, "id": "Harry" }, isReadOnly: false }; assignParams = { "ticket": { "type": "workorder", "workorderType": "General", "manager": { "fullName": "Harry Potter", "loginId": "Harry", "thumbnail": "", "customFields": {}, "id": "Harry" }, "managerGroup": { "name": "Petramco Support Group1", "company": { "name": "Petramco" }, "organization": "Petramco Support Org1", "id": "GGP000000000016" }, "id": "IDGAA5V0HG8PDANPF31S5HFEBSCEOI", "status": { "value": "Assigned" }, "assignee": { "fullName": "Harry Potter", "loginId": "Harry", "thumbnail": "", "customFields": {}, "id": "Harry" }, "supportGroup": { "name": "Petramco Support Group1", "company": { "name": "Petramco" }, "organization": "Petramco Support Org1", "id": "GGP000000000016" }, "customFields": {}, "company": { "name": "Petramco" }, "ticketType": "workorder", }, "isDraft": false, "role": null, "activeRole": "workordermanager" }; spyOn(screenConfigurationModel, 'getAssignmentPanel').and.returnValue({}); spyOn(screenConfigurationModel, 'initFieldValues'); spyOn(objectValueMapperService, 'getValueByFieldName').and.callFake(function (input) { if(input === 'assignee') { input = curAssignee; } else if(input === 'assigneeSupportGroups') { input = curSupportGroup; } return input; }); spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function (input) { if(input === 'requestManager') { input = curRequestManager; } else if(input === 'requestManagerSupportGroups') { input = curRequestManagerSupportGroup; } return input; }); }); it('should initialize default values in case of work order manager according to assignParams', function () { setActiveRole('workordermanager'); initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.workordermanager).toBeTruthy(); expect($scope.isDraft).toBeFalsy(); expect($scope.hideTabs).toBeFalsy(); expect($scope.ticket.type).toBe('workorder'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Petramco Support Group1'); expect($scope.selectedAssignee.person.id).toBe('Harry'); expect($scope.selectedManager.person.id).toBe('Harry'); expect($scope.state.isDraft).toBeFalsy(); }); it('should initialize default values in case of ticket assignee according to assignParams', function () { setActiveRole('ticketassignee'); initController(); $timeout.flush(); expect($scope.hideTabOnExpression.changeManager).toBeFalsy(); expect($scope.hideTabOnExpression.changeCoordinator).toBeFalsy(); expect($scope.ticketassignee).toBeTruthy(); expect($scope.isDraft).toBeFalsy(); expect($scope.hideTabs).toBeFalsy(); expect($scope.ticket.type).toBe('workorder'); expect($scope.groups.length).toBe(0); expect($scope.customFields.length).toBe(0); expect(screenConfigurationModel.initFieldValues).toHaveBeenCalledWith([], $scope.ticket); expect($scope.selectedAssignee.group.name).toBe('Petramco Support Group1'); expect($scope.selectedAssignee.person.id).toBe('Harry'); expect($scope.selectedManager.person.id).toBe('Harry'); expect($scope.state.isDraft).toBeFalsy(); }); }); });