1 import {getTestBed, TestBed} from '@angular/core/testing';
5 InstantiationStatusComponentService,
14 } from './instantiationStatus.component.service';
15 import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
16 import {AaiService} from "../shared/services/aaiService/aai.service";
17 import {MsoService} from "../shared/services/msoService/mso.service";
18 import {NgRedux} from "@angular-redux/store";
19 import {HttpClientTestingModule} from "@angular/common/http/testing";
20 import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
21 import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
22 import {RouterTestingModule} from "@angular/router/testing";
23 import {of} from "rxjs";
24 import {UrlTree} from "@angular/router";
25 import each from "jest-each";
26 import {ServiceAction} from "../shared/models/serviceInstanceActions";
27 import {instance, mock, when} from "ts-mockito";
29 class MockAppStore<T> {
33 describe('Instantiation Status Service', () => {
35 let aaiService: AaiService;
36 let msoService: MsoService;
37 let service: InstantiationStatusComponentService;
38 let mockFeatureFlagsService: FeatureFlagsService = mock(FeatureFlagsService);
41 beforeAll(done => (async () => {
42 TestBed.configureTestingModule({
44 HttpClientTestingModule,
48 InstantiationStatusComponentService,
52 {provide: NgRedux, useClass: MockAppStore},
53 {provide: FeatureFlagsService, useValue: instance(mockFeatureFlagsService)}
56 await TestBed.compileComponents();
58 injector = getTestBed();
59 aaiService = injector.get(AaiService);
60 msoService = injector.get(MsoService);
61 service = injector.get(InstantiationStatusComponentService);
63 })().then(done).catch(done.fail));
65 test('generateServiceInfoDataMapping should return mapping of arrays', () => {
66 let data : ServiceInfoModel[] = generateServiceInfoData();
67 let result = service.generateServiceInfoDataMapping(data);
69 expect(result['1']).toBeDefined();
70 expect(result['2']).toBeDefined();
71 expect(result['3']).toBeDefined();
73 expect(result['1'].length).toEqual(2);
74 expect(result['2'].length).toEqual(2);
75 expect(result['3'].length).toEqual(1);
78 test('generateServiceInfoDataMapping if array is empty should return empty object', () => {
79 let result = service.generateServiceInfoDataMapping([]);
81 expect(result['1']).not.toBeDefined();
82 expect(result['2']).not.toBeDefined();
83 expect(result['3']).not.toBeDefined();
86 test('convertObjectToArray', () => {
88 jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
92 let data : ServiceInfoModel[] = generateServiceInfoData();
93 service.convertObjectToArray(data).subscribe((result) => {
94 expect(result).toBeDefined();
98 describe('navigations tests:', () => {
101 serviceModelId: '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
102 serviceInstanceId: 'myInstanceId',
103 serviceType: 'myService',
104 subscriberId: 'mySubscriber',
108 test('click on "Open" button should open new view edit', () => {
109 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
110 expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
111 expect(params.queryParams).toEqual(
113 serviceModelId: item.serviceModelId,
114 serviceInstanceId: item.serviceInstanceId,
115 serviceType: item.serviceType,
116 subscriberId: item.subscriberId,
121 test('build the View Edit url', () => {
123 let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309' +
124 '&serviceInstanceId=myInstanceId&serviceType=myService&subscriberId=mySubscriber&jobId=aJobId';
125 let prefix: string = '../../serviceModels.htm#';
126 let tree: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
127 let result = service.getViewEditUrl(tree);
128 expect(result).toEqual(prefix + serviceModelUrl);
131 test('recreate url shall contains mode RECREATE and only jobId and serviceModelId', () =>{
132 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.RECREATE);
133 expect(params.toString().startsWith('/servicePlanning/RECREATE')).toBeTruthy();
134 expect(params.queryParams).toEqual(
136 serviceModelId: item.serviceModelId,
142 for (let [status, tooltip] of Object.entries({
143 'pending': 'Pending: The action required will be sent as soon as possible.',
144 'IN_PROGRESS': 'In-progress: the service is in process of the action required.',
145 'PAUSED': 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.',
146 'FAILED': 'Failed: All planned actions have failed.',
147 'COMPLETED': 'Completed successfully: Service is successfully instantiated, updated or deleted.',
148 'STOPPED': 'Stopped: Due to previous failure, will not be instantiated.',
149 'StOpPeD': 'Stopped: Due to previous failure, will not be instantiated.',
150 'COMPLETED_WITH_ERRORS': 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.',
151 'UNEXPECTED_RANDOM_STATUS': 'Unexpected status: "UNEXPECTED_RANDOM_STATUS"',
152 'COMPLETED_AND_PAUSED': 'Pause upon completion. you may resume the instantiation.\n Open the service to check it out.',
155 test(`getStatusTooltip should return status popover: status=${status}`, () => {
156 expect(service.getStatus(status).tooltip).toEqual(tooltip);
161 test(`service.getStatus should handle undefined status`, () => {
162 const statusResult = service.getStatus(undefined);
163 expect(statusResult.tooltip).toEqual('Unexpected status: "undefined"');
164 expect(statusResult.iconClassName).toEqual(UNKNOWN);
169 [true, ServiceAction.INSTANTIATE],
170 [false, ServiceAction.UPDATE],
171 [false, ServiceAction.DELETE],
173 test('isRecreateEnabled: should be %s if action is %s', (expected:boolean, action:ServiceAction) => {
174 let serviceInfoModel = new ServiceInfoModel();
175 serviceInfoModel.action = action;
176 expect(service.isRecreateEnabled(serviceInfoModel)).toBe(expected);
183 test('isRecreateVisible: should be %s if flag is %s', (expected:boolean, flag:boolean) => {
184 when(mockFeatureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(flag);
185 expect(service.isRecreateVisible()).toEqual(expected);
188 test('getStatusTooltip should return correct icon per job status', () => {
189 let result : ServiceStatus = service.getStatus('pending');
190 expect(result.iconClassName).toEqual(PENDING);
192 result = service.getStatus('IN_PROGRESS');
193 expect(result.iconClassName).toEqual(INPROGRESS);
195 result = service.getStatus('PAUSED');
196 expect(result.iconClassName).toEqual(PAUSE);
198 result = service.getStatus('FAILED');
199 expect(result.iconClassName).toEqual(X_O);
201 result = service.getStatus('COMPLETED');
202 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
204 result = service.getStatus('STOPPED');
205 expect(result.iconClassName).toEqual(STOPPED);
207 result = service.getStatus('COMPLETED_WITH_ERRORS');
208 expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);
210 result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
211 expect(result.iconClassName).toEqual(UNKNOWN);
213 result = service.getStatus('COMPLETED_AND_PAUSED');
214 expect(result.iconClassName).toEqual(PAUSE_UPON_COMPLETION);
216 result = service.getStatus(undefined);
217 expect(result.iconClassName).toEqual(UNKNOWN);
220 function generateServiceInfoData(){
221 return JSON.parse(JSON.stringify([
223 "created": 1519956533000,
224 "modified": 1521727738000,
230 "jobId": "6748648484",
232 "jobStatus": "FAILED",
234 "owningEntityId": "1234",
235 "owningEntityName": null,
244 "subscriberName": null,
245 "serviceInstanceId": "1",
246 "serviceInstanceName": null,
247 "serviceModelId": null,
248 "serviceModelName": null,
249 "serviceModelVersion": null,
250 "createdBulkDate": 1519956533000,
251 "statusModifiedDate": 1520042933000,
256 "created": 1519956533000,
257 "modified": 1521727738000,
263 "jobId": "6748648484",
265 "jobStatus": "FAILED",
267 "owningEntityId": "1234",
268 "owningEntityName": null,
277 "subscriberName": null,
278 "serviceInstanceId": "1",
279 "serviceInstanceName": null,
280 "serviceModelId": null,
281 "serviceModelName": null,
282 "serviceModelVersion": null,
283 "createdBulkDate": 1519956533000,
284 "statusModifiedDate": 1520042933000,
289 "created": 1519956533000,
290 "modified": 1521727738000,
296 "jobId": "6748648484",
298 "jobStatus": "FAILED",
300 "owningEntityId": "1234",
301 "owningEntityName": null,
310 "subscriberName": null,
311 "serviceInstanceId": "2",
312 "serviceInstanceName": null,
313 "serviceModelId": null,
314 "serviceModelName": null,
315 "serviceModelVersion": null,
316 "createdBulkDate": 1519956533000,
317 "statusModifiedDate": 1520042933000,
322 "created": 1519956533000,
323 "modified": 1521727738000,
329 "jobId": "6748648484",
331 "jobStatus": "FAILED",
333 "owningEntityId": "1234",
334 "owningEntityName": null,
343 "subscriberName": null,
344 "serviceInstanceId": "2",
345 "serviceInstanceName": null,
346 "serviceModelId": null,
347 "serviceModelName": null,
348 "serviceModelVersion": null,
349 "createdBulkDate": 1519956533000,
350 "statusModifiedDate": 1520042933000,
355 "created": 1519956533000,
356 "modified": 1521727738000,
362 "jobId": "6748648484",
364 "jobStatus": "FAILED",
366 "owningEntityId": "1234",
367 "owningEntityName": null,
376 "subscriberName": null,
377 "serviceInstanceId": "3",
378 "serviceInstanceName": null,
379 "serviceModelId": null,
380 "serviceModelName": null,
381 "serviceModelVersion": null,
382 "createdBulkDate": 1519956533000,
383 "statusModifiedDate": 1520042933000,