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} 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";
14 class MockAppStore<T> {
20 'FLAG_1902_NEW_VIEW_EDIT': true,
31 describe('Instantiation Status Service', () => {
33 let aaiService: AaiService;
34 let msoService: MsoService;
35 let service: InstantiationStatusComponentService;
38 beforeAll(done => (async () => {
39 TestBed.configureTestingModule({
41 HttpClientTestingModule,
45 InstantiationStatusComponentService,
49 {provide: NgRedux, useClass: MockAppStore}]
51 await TestBed.compileComponents();
53 injector = getTestBed();
54 aaiService = injector.get(AaiService);
55 msoService = injector.get(MsoService);
56 service = injector.get(InstantiationStatusComponentService);
58 })().then(done).catch(done.fail));
60 test('generateServiceInfoDataMapping should return mapping of arrays', () => {
61 let data : ServiceInfoModel[] = generateServiceInfoData();
62 let result = service.generateServiceInfoDataMapping(data);
64 expect(result['1']).toBeDefined();
65 expect(result['2']).toBeDefined();
66 expect(result['3']).toBeDefined();
68 expect(result['1'].length).toEqual(2);
69 expect(result['2'].length).toEqual(2);
70 expect(result['3'].length).toEqual(1);
73 test('generateServiceInfoDataMapping if array is empty should return empty object', () => {
74 let result = service.generateServiceInfoDataMapping([]);
76 expect(result['1']).not.toBeDefined();
77 expect(result['2']).not.toBeDefined();
78 expect(result['3']).not.toBeDefined();
81 test('convertObjectToArray', () => {
83 jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
87 let data : ServiceInfoModel[] = generateServiceInfoData();
88 service.convertObjectToArray(data).subscribe((result) => {
89 expect(result).toBeDefined();
93 describe('navigations tests:', () => {
96 serviceModelId: '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
97 serviceInstanceId: 'myInstanceId',
98 serviceType: 'myService',
99 subscriberId: 'mySubscriber',
103 test('click on "Open" button should open new view edit', () => {
104 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
105 expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
106 expect(params.queryParams).toEqual(
108 serviceModelId: item.serviceModelId,
109 serviceInstanceId: item.serviceInstanceId,
110 serviceType: item.serviceType,
111 subscriberId: item.subscriberId,
116 test('build the View Edit url', () => {
118 let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309' +
119 '&serviceInstanceId=myInstanceId&serviceType=myService&subscriberId=mySubscriber&jobId=aJobId';
120 let prefix: string = '../../serviceModels.htm#';
121 let tree: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
122 let result = service.getViewEditUrl(tree);
123 expect(result).toEqual(prefix + serviceModelUrl);
126 test('recreate url shall contains mode RECREATE and only jobId and serviceModelId', () =>{
127 let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.RECREATE);
128 expect(params.toString().startsWith('/servicePlanning/RECREATE')).toBeTruthy();
129 expect(params.queryParams).toEqual(
131 serviceModelId: item.serviceModelId,
137 for (let [status, tooltip] of Object.entries({
138 'pending': 'Pending: The action required will be sent as soon as possible.',
139 'IN_PROGRESS': 'In-progress: the service is in process of the action required.',
140 'PAUSED': 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.',
141 'FAILED': 'Failed: All planned actions have failed.',
142 'COMPLETED': 'Completed successfully: Service is successfully instantiated, updated or deleted.',
143 'STOPPED': 'Stopped: Due to previous failure, will not be instantiated.',
144 'StOpPeD': 'Stopped: Due to previous failure, will not be instantiated.',
145 '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.',
146 'UNEXPECTED_RANDOM_STATUS': 'Unexpected status: "UNEXPECTED_RANDOM_STATUS"',
149 test(`getStatusTooltip should return status popover: status=${status}`, () => {
150 expect(service.getStatus(status).tooltip).toEqual(tooltip);
155 test(`service.getStatus should handle undefined status`, () => {
156 const statusResult = service.getStatus(undefined);
157 expect(statusResult.tooltip).toEqual('Unexpected status: "undefined"');
158 expect(statusResult.iconClassName).toEqual(UNKNOWN);
161 test('getStatusTooltip should return correct icon per job status', () => {
162 let result : ServiceStatus = service.getStatus('pending');
163 expect(result.iconClassName).toEqual(PENDING);
165 result = service.getStatus('IN_PROGRESS');
166 expect(result.iconClassName).toEqual(INPROGRESS);
168 result = service.getStatus('PAUSED');
169 expect(result.iconClassName).toEqual(PAUSE);
171 result = service.getStatus('FAILED');
172 expect(result.iconClassName).toEqual(X_O);
174 result = service.getStatus('COMPLETED');
175 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
177 result = service.getStatus('STOPPED');
178 expect(result.iconClassName).toEqual(STOPPED);
180 result = service.getStatus('COMPLETED_WITH_ERRORS');
181 expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);
183 result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
184 expect(result.iconClassName).toEqual(UNKNOWN);
186 result = service.getStatus(undefined);
187 expect(result.iconClassName).toEqual(UNKNOWN);
190 function generateServiceInfoData(){
191 return JSON.parse(JSON.stringify([
193 "created": 1519956533000,
194 "modified": 1521727738000,
200 "jobId": "6748648484",
202 "jobStatus": "FAILED",
204 "owningEntityId": "1234",
205 "owningEntityName": null,
214 "subscriberName": null,
215 "serviceInstanceId": "1",
216 "serviceInstanceName": null,
217 "serviceModelId": null,
218 "serviceModelName": null,
219 "serviceModelVersion": null,
220 "createdBulkDate": 1519956533000,
221 "statusModifiedDate": 1520042933000,
226 "created": 1519956533000,
227 "modified": 1521727738000,
233 "jobId": "6748648484",
235 "jobStatus": "FAILED",
237 "owningEntityId": "1234",
238 "owningEntityName": null,
247 "subscriberName": null,
248 "serviceInstanceId": "1",
249 "serviceInstanceName": null,
250 "serviceModelId": null,
251 "serviceModelName": null,
252 "serviceModelVersion": null,
253 "createdBulkDate": 1519956533000,
254 "statusModifiedDate": 1520042933000,
259 "created": 1519956533000,
260 "modified": 1521727738000,
266 "jobId": "6748648484",
268 "jobStatus": "FAILED",
270 "owningEntityId": "1234",
271 "owningEntityName": null,
280 "subscriberName": null,
281 "serviceInstanceId": "2",
282 "serviceInstanceName": null,
283 "serviceModelId": null,
284 "serviceModelName": null,
285 "serviceModelVersion": null,
286 "createdBulkDate": 1519956533000,
287 "statusModifiedDate": 1520042933000,
292 "created": 1519956533000,
293 "modified": 1521727738000,
299 "jobId": "6748648484",
301 "jobStatus": "FAILED",
303 "owningEntityId": "1234",
304 "owningEntityName": null,
313 "subscriberName": null,
314 "serviceInstanceId": "2",
315 "serviceInstanceName": null,
316 "serviceModelId": null,
317 "serviceModelName": null,
318 "serviceModelVersion": null,
319 "createdBulkDate": 1519956533000,
320 "statusModifiedDate": 1520042933000,
325 "created": 1519956533000,
326 "modified": 1521727738000,
332 "jobId": "6748648484",
334 "jobStatus": "FAILED",
336 "owningEntityId": "1234",
337 "owningEntityName": null,
346 "subscriberName": null,
347 "serviceInstanceId": "3",
348 "serviceInstanceName": null,
349 "serviceModelId": null,
350 "serviceModelName": null,
351 "serviceModelVersion": null,
352 "createdBulkDate": 1519956533000,
353 "statusModifiedDate": 1520042933000,