2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 require('./change-management-manual-tasks.controller');
22 const jestMock = require('jest-mock');
24 describe('changeManagementManualTasksController testing', () => {
26 let $uibModalInstance = jestMock.fn();
27 let $MsoService = jestMock.fn();
28 let $log = jestMock.fn();
31 angular.mock.module('app')
34 beforeEach(inject(function (_$controller_) {
35 $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
36 {data: [manualTaskResponse]});
37 $log.error = jestMock.fn();
39 $controller = _$controller_('changeManagementManualTasksController', {
40 "MsoService": $MsoService,
41 "$uibModalInstance": $uibModalInstance,
44 requestState: job.requestStatus.requestState,
45 details: job.requestStatus.statusMessage,
49 MANUAL_TASKS: ["manualTaskName1", "manualTaskName2"]
55 "requestId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
56 "requestScope": "vnf",
58 "percentProgress": 100.0,
59 "requestState": "FAILED",
60 "statusMessage": "Error validating request. No valid catalog entry is specified",
61 "finishTime": "Thu, 05 Oct 2017 18:58:29 GMT"
63 "requestType": "replaceInstance",
64 "startTime": "Thu, 05 Oct 2017 18:58:29 GMT",
65 "instanceReferences": {
66 "serviceInstanceId": "cc8fa0a9-7576-4c39-af31-7ad61d057ac9",
67 "vnfInstanceId": "bec0c3d3-09ae-4eb1-b694-057987a10982",
68 "requestorId": "pa2396"
72 const manualTaskResponse = {
73 "taskId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
74 "validResponses": ["rollback", "abort", "skip", "resume", "retry"]
77 test('should populate vm.manualTasks (while init)', () => {
78 expect($controller.manualTasks).toEqual(
79 manualTaskResponse.validResponses);
82 test('should populate vm.MANUAL_TASKS from COMPONENT (while init)', () => {
83 expect($controller.MANUAL_TASKS).toEqual(
84 ["manualTaskName1", "manualTaskName2"]);
87 test('should populate vm.task (while init)', () => {
88 expect($controller.task).toEqual(manualTaskResponse);
91 test('should find manual task using isTaskAvailable', () => {
92 expect($controller.isTaskAvailable('abort')).toBeTruthy();
93 expect($controller.isTaskAvailable('resume')).toBeTruthy();
95 expect($controller.isTaskAvailable('foo')).toBeFalsy();
96 expect($controller.isTaskAvailable(undefined)).toBeFalsy();
99 test('should call MsoService upon completeTask', () => {
100 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
102 $controller.completeTask("taskName");
103 expect($MsoService.completeTask).toBeCalledWith(
104 manualTaskResponse.taskId, "taskName");
107 test('should close modal upon completeTask', done => {
108 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
109 $uibModalInstance.close = jestMock.fn(() => {
113 $controller.completeTask("taskName");
116 test('should close modal upon failed completeTask', done => {
117 $MsoService.completeTask = jestMock.fn().mockRejectedValue();
118 $uibModalInstance.close = jestMock.fn(() => {
122 $controller.completeTask("taskName");