1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {COMPLETED_WITH_ERRORS, INPROGRESS, InstantiationStatusComponentService, PAUSE, PENDING, ServiceStatus, STOPPED, SUCCESS_CIRCLE, UNKNOWN, X_O} from './instantiationStatus.component.service';
3 import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
4 import {AaiService} from "../shared/services/aaiService/aai.service";
5 import {MsoService} from "../shared/services/msoService/mso.service";
6 import {NgRedux} from "@angular-redux/store";
7 import {HttpClientTestingModule} from "@angular/common/http/testing";
8 import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
9 import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
10 import {RouterTestingModule} from "@angular/router/testing";
11 import {of} from "rxjs";
12 import {UrlTree} from "@angular/router";
13 import each from "jest-each";
14 import {ServiceAction} from "../shared/models/serviceInstanceActions";
15 import {instance, mock, when} from "ts-mockito";
17 class MockAppStore<T> {
21 describe('Instantiation Status Service', () => {
23 let aaiService: AaiService;
24 let msoService: MsoService;
25 let service: InstantiationStatusComponentService;
26 let mockFeatureFlagsService: FeatureFlagsService = mock(FeatureFlagsService);
29 beforeAll(done => (async () => {
30 TestBed.configureTestingModule({
32 HttpClientTestingModule,
36 InstantiationStatusComponentService,
40 {provide: NgRedux, useClass: MockAppStore},
41 {provide: FeatureFlagsService, useValue: instance(mockFeatureFlagsService)}
44 await TestBed.compileComponents();
46 injector = getTestBed();
47 aaiService = injector.get(AaiService);
48 msoService = injector.get(MsoService);
49 service = injector.get(InstantiationStatusComponentService);
51 })().then(done).catch(done.fail));
53 test('generateServiceInfoDataMapping should return mapping of arrays', () => {
54 let data : ServiceInfoModel[] = generateServiceInfoData();
55 let result = service.generateServiceInfoDataMapping(data);
57 expect(result['1']).toBeDefined();
58 expect(result['2']).toBeDefined();
59 expect(result['3']).toBeDefined();
61 expect(result['1'].length).toEqual(2);
62 expect(result['2'].length).toEqual(2);
63 expect(result['3'].length).toEqual(1);
66 test('generateServiceInfoDataMapping if array is empty should return empty object', () => {
67 let result = service.generateServiceInfoDataMapping([]);
69 expect(result['1']).not.toBeDefined();
70 expect(result['2']).not.toBeDefined();
71 expect(result['3']).not.toBeDefined();
74 test('convertObjectToArray', () => {
76 jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
80 let data : ServiceInfoModel[] = generateServiceInfoData();
81 service.convertObjectToArray(data).subscribe((result) => {
82 expect(result).toBeDefined();
86 describe('navigations tests:', () => {
89 serviceModelId: '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
90 serviceInstanceId: 'myInstanceId',
91 serviceType: 'myService',
92 subscriberId: 'mySubscriber',
96 test('click on "Open" button should open new view edit', () => {
97 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
98 expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
99 expect(params.queryParams).toEqual(
101 serviceModelId: item.serviceModelId,
102 serviceInstanceId: item.serviceInstanceId,
103 serviceType: item.serviceType,
104 subscriberId: item.subscriberId,
109 test('build the View Edit url', () => {
111 let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309' +
112 '&serviceInstanceId=myInstanceId&serviceType=myService&subscriberId=mySubscriber&jobId=aJobId';
113 let prefix: string = '../../serviceModels.htm#';
114 let tree: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
115 let result = service.getViewEditUrl(tree);
116 expect(result).toEqual(prefix + serviceModelUrl);
119 test('recreate url shall contains mode RECREATE and only jobId and serviceModelId', () =>{
120 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.RECREATE);
121 expect(params.toString().startsWith('/servicePlanning/RECREATE')).toBeTruthy();
122 expect(params.queryParams).toEqual(
124 serviceModelId: item.serviceModelId,
130 for (let [status, tooltip] of Object.entries({
131 'pending': 'Pending: The action required will be sent as soon as possible.',
132 'IN_PROGRESS': 'In-progress: the service is in process of the action required.',
133 'PAUSED': 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.',
134 'FAILED': 'Failed: All planned actions have failed.',
135 'COMPLETED': 'Completed successfully: Service is successfully instantiated, updated or deleted.',
136 'STOPPED': 'Stopped: Due to previous failure, will not be instantiated.',
137 'StOpPeD': 'Stopped: Due to previous failure, will not be instantiated.',
138 '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.',
139 'UNEXPECTED_RANDOM_STATUS': 'Unexpected status: "UNEXPECTED_RANDOM_STATUS"',
142 test(`getStatusTooltip should return status popover: status=${status}`, () => {
143 expect(service.getStatus(status).tooltip).toEqual(tooltip);
148 test(`service.getStatus should handle undefined status`, () => {
149 const statusResult = service.getStatus(undefined);
150 expect(statusResult.tooltip).toEqual('Unexpected status: "undefined"');
151 expect(statusResult.iconClassName).toEqual(UNKNOWN);
156 [true, ServiceAction.INSTANTIATE],
157 [false, ServiceAction.UPDATE],
158 [false, ServiceAction.DELETE],
160 test('isRecreateEnabled: should be %s if action is %s', (expected:boolean, action:ServiceAction) => {
161 let serviceInfoModel = new ServiceInfoModel();
162 serviceInfoModel.action = action;
163 expect(service.isRecreateEnabled(serviceInfoModel)).toBe(expected);
170 test('isRecreateVisible: should be %s if flag is %s', (expected:boolean, flag:boolean) => {
171 when(mockFeatureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(flag);
172 expect(service.isRecreateVisible()).toEqual(expected);
175 test('getStatusTooltip should return correct icon per job status', () => {
176 let result : ServiceStatus = service.getStatus('pending');
177 expect(result.iconClassName).toEqual(PENDING);
179 result = service.getStatus('IN_PROGRESS');
180 expect(result.iconClassName).toEqual(INPROGRESS);
182 result = service.getStatus('PAUSED');
183 expect(result.iconClassName).toEqual(PAUSE);
185 result = service.getStatus('FAILED');
186 expect(result.iconClassName).toEqual(X_O);
188 result = service.getStatus('COMPLETED');
189 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
191 result = service.getStatus('STOPPED');
192 expect(result.iconClassName).toEqual(STOPPED);
194 result = service.getStatus('COMPLETED_WITH_ERRORS');
195 expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);
197 result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
198 expect(result.iconClassName).toEqual(UNKNOWN);
200 result = service.getStatus(undefined);
201 expect(result.iconClassName).toEqual(UNKNOWN);
204 function generateServiceInfoData(){
205 return JSON.parse(JSON.stringify([
207 "created": 1519956533000,
208 "modified": 1521727738000,
214 "jobId": "6748648484",
216 "jobStatus": "FAILED",
218 "owningEntityId": "1234",
219 "owningEntityName": null,
228 "subscriberName": null,
229 "serviceInstanceId": "1",
230 "serviceInstanceName": null,
231 "serviceModelId": null,
232 "serviceModelName": null,
233 "serviceModelVersion": null,
234 "createdBulkDate": 1519956533000,
235 "statusModifiedDate": 1520042933000,
240 "created": 1519956533000,
241 "modified": 1521727738000,
247 "jobId": "6748648484",
249 "jobStatus": "FAILED",
251 "owningEntityId": "1234",
252 "owningEntityName": null,
261 "subscriberName": null,
262 "serviceInstanceId": "1",
263 "serviceInstanceName": null,
264 "serviceModelId": null,
265 "serviceModelName": null,
266 "serviceModelVersion": null,
267 "createdBulkDate": 1519956533000,
268 "statusModifiedDate": 1520042933000,
273 "created": 1519956533000,
274 "modified": 1521727738000,
280 "jobId": "6748648484",
282 "jobStatus": "FAILED",
284 "owningEntityId": "1234",
285 "owningEntityName": null,
294 "subscriberName": null,
295 "serviceInstanceId": "2",
296 "serviceInstanceName": null,
297 "serviceModelId": null,
298 "serviceModelName": null,
299 "serviceModelVersion": null,
300 "createdBulkDate": 1519956533000,
301 "statusModifiedDate": 1520042933000,
306 "created": 1519956533000,
307 "modified": 1521727738000,
313 "jobId": "6748648484",
315 "jobStatus": "FAILED",
317 "owningEntityId": "1234",
318 "owningEntityName": null,
327 "subscriberName": null,
328 "serviceInstanceId": "2",
329 "serviceInstanceName": null,
330 "serviceModelId": null,
331 "serviceModelName": null,
332 "serviceModelVersion": null,
333 "createdBulkDate": 1519956533000,
334 "statusModifiedDate": 1520042933000,
339 "created": 1519956533000,
340 "modified": 1521727738000,
346 "jobId": "6748648484",
348 "jobStatus": "FAILED",
350 "owningEntityId": "1234",
351 "owningEntityName": null,
360 "subscriberName": null,
361 "serviceInstanceId": "3",
362 "serviceInstanceName": null,
363 "serviceModelId": null,
364 "serviceModelName": null,
365 "serviceModelVersion": null,
366 "createdBulkDate": 1519956533000,
367 "statusModifiedDate": 1520042933000,