1 import {getTestBed, TestBed} from '@angular/core/testing';
5 InstantiationStatusComponentService,
13 } from './instantiationStatus.component.service';
14 import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
15 import {AaiService} from "../shared/services/aaiService/aai.service";
16 import {MsoService} from "../shared/services/msoService/mso.service";
17 import {NgRedux} from "@angular-redux/store";
18 import {HttpClientTestingModule} from "@angular/common/http/testing";
19 import {FeatureFlagsService} from "../shared/services/featureFlag/feature-flags.service";
20 import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
21 import {RouterTestingModule} from "@angular/router/testing";
22 import {of} from "rxjs";
23 import {UrlTree} from "@angular/router";
25 class MockAppStore<T> {
31 'FLAG_1902_NEW_VIEW_EDIT': true,
42 describe('Instantiation Status Service', () => {
44 let aaiService: AaiService;
45 let msoService: MsoService;
46 let service: InstantiationStatusComponentService;
49 beforeAll(done => (async () => {
50 TestBed.configureTestingModule({
52 HttpClientTestingModule,
56 InstantiationStatusComponentService,
60 {provide: NgRedux, useClass: MockAppStore}]
62 await TestBed.compileComponents();
64 injector = getTestBed();
65 aaiService = injector.get(AaiService);
66 msoService = injector.get(MsoService);
67 service = injector.get(InstantiationStatusComponentService);
69 })().then(done).catch(done.fail));
71 test('generateServiceInfoDataMapping should return mapping of arrays', () => {
72 let data : ServiceInfoModel[] = generateServiceInfoData();
73 let result = service.generateServiceInfoDataMapping(data);
75 expect(result['1']).toBeDefined();
76 expect(result['2']).toBeDefined();
77 expect(result['3']).toBeDefined();
79 expect(result['1'].length).toEqual(2);
80 expect(result['2'].length).toEqual(2);
81 expect(result['3'].length).toEqual(1);
84 test('generateServiceInfoDataMapping if array is empty should return empty object', () => {
85 let result = service.generateServiceInfoDataMapping([]);
87 expect(result['1']).not.toBeDefined();
88 expect(result['2']).not.toBeDefined();
89 expect(result['3']).not.toBeDefined();
92 test('convertObjectToArray', () => {
94 jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
98 let data : ServiceInfoModel[] = generateServiceInfoData();
99 service.convertObjectToArray(data).subscribe((result) => {
100 expect(result).toBeDefined();
104 test('click on "Open" button should open new view edit' , ()=>{
106 serviceModelId : 'serviceModelId',
107 serviceInstanceId : 'serviceInstanceId',
108 serviceType : 'serviceType',
109 subscriberId : 'subscriberId'
111 let params:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
112 expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
113 expect(params.queryParams).toEqual(
115 serviceModelId: item.serviceModelId,
116 serviceInstanceId: item.serviceInstanceId,
117 serviceType : item.serviceType,
118 subscriberId : item.subscriberId
122 test('build the View Edit url' , ()=>{
124 serviceModelId : '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
126 let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309';
127 let suffix:string = '../../serviceModels.htm#';
128 let tree:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
129 let result = service.getViewEditUrl(tree);
130 expect (suffix + serviceModelUrl).toEqual(result);
133 for (let [status, tooltip] of Object.entries({
134 'pending': 'Pending: The action required will be sent as soon as possible.',
135 'IN_PROGRESS': 'In-progress: the service is in process of the action required.',
136 'PAUSED': 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.',
137 'FAILED': 'Failed: All planned actions have failed.',
138 'COMPLETED': 'Completed successfully: Service is successfully instantiated, updated or deleted.',
139 'STOPPED': 'Stopped: Due to previous failure, will not be instantiated.',
140 'StOpPeD': 'Stopped: Due to previous failure, will not be instantiated.',
141 '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.',
142 'UNEXPECTED_STATUS': 'Unexpected status: "UNEXPECTED_RANDOM_STATUS"',
145 test(`getStatusTooltip should return status popover: status=${status}`, () => {
146 expect(service.getStatus(status).tooltip).toEqual(tooltip);
151 test('getStatusTooltip should return correct icon per job status', () => {
152 let result : ServiceStatus = service.getStatus('pending');
153 expect(result.iconClassName).toEqual(PENDING);
155 result = service.getStatus('IN_PROGRESS');
156 expect(result.iconClassName).toEqual(INPROGRESS);
158 result = service.getStatus('PAUSED');
159 expect(result.iconClassName).toEqual(PAUSE);
161 result = service.getStatus('FAILED');
162 expect(result.iconClassName).toEqual(X_O);
164 result = service.getStatus('COMPLETED');
165 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
167 result = service.getStatus('STOPPED');
168 expect(result.iconClassName).toEqual(STOPPED);
170 result = service.getStatus('COMPLETED_WITH_ERRORS');
171 expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);
173 result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
174 expect(result.iconClassName).toEqual(UNKNOWN);
177 function generateServiceInfoData(){
178 return JSON.parse(JSON.stringify([
180 "created": 1519956533000,
181 "modified": 1521727738000,
187 "jobId": "6748648484",
189 "jobStatus": "FAILED",
191 "owningEntityId": "1234",
192 "owningEntityName": null,
201 "subscriberName": null,
202 "serviceInstanceId": "1",
203 "serviceInstanceName": null,
204 "serviceModelId": null,
205 "serviceModelName": null,
206 "serviceModelVersion": null,
207 "createdBulkDate": 1519956533000,
208 "statusModifiedDate": 1520042933000,
213 "created": 1519956533000,
214 "modified": 1521727738000,
220 "jobId": "6748648484",
222 "jobStatus": "FAILED",
224 "owningEntityId": "1234",
225 "owningEntityName": null,
234 "subscriberName": null,
235 "serviceInstanceId": "1",
236 "serviceInstanceName": null,
237 "serviceModelId": null,
238 "serviceModelName": null,
239 "serviceModelVersion": null,
240 "createdBulkDate": 1519956533000,
241 "statusModifiedDate": 1520042933000,
246 "created": 1519956533000,
247 "modified": 1521727738000,
253 "jobId": "6748648484",
255 "jobStatus": "FAILED",
257 "owningEntityId": "1234",
258 "owningEntityName": null,
267 "subscriberName": null,
268 "serviceInstanceId": "2",
269 "serviceInstanceName": null,
270 "serviceModelId": null,
271 "serviceModelName": null,
272 "serviceModelVersion": null,
273 "createdBulkDate": 1519956533000,
274 "statusModifiedDate": 1520042933000,
279 "created": 1519956533000,
280 "modified": 1521727738000,
286 "jobId": "6748648484",
288 "jobStatus": "FAILED",
290 "owningEntityId": "1234",
291 "owningEntityName": null,
300 "subscriberName": null,
301 "serviceInstanceId": "2",
302 "serviceInstanceName": null,
303 "serviceModelId": null,
304 "serviceModelName": null,
305 "serviceModelVersion": null,
306 "createdBulkDate": 1519956533000,
307 "statusModifiedDate": 1520042933000,
312 "created": 1519956533000,
313 "modified": 1521727738000,
319 "jobId": "6748648484",
321 "jobStatus": "FAILED",
323 "owningEntityId": "1234",
324 "owningEntityName": null,
333 "subscriberName": null,
334 "serviceInstanceId": "3",
335 "serviceInstanceName": null,
336 "serviceModelId": null,
337 "serviceModelName": null,
338 "serviceModelVersion": null,
339 "createdBulkDate": 1519956533000,
340 "statusModifiedDate": 1520042933000,