blob: d115984f6683905490dc0eae80d779a1fe0de2a3 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {getTestBed, TestBed} from '@angular/core/testing';
2import {
Ittay Stern6f900cc2018-08-29 17:01:32 +03003 COMPLETED_WITH_ERRORS,
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03004 INPROGRESS,
5 InstantiationStatusComponentService,
6 PAUSE,
7 PENDING,
8 ServiceStatus,
Ittay Sterna8ebb742019-10-29 17:54:54 +02009 STOPPED,
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030010 SUCCESS_CIRCLE,
Ittay Sterna8ebb742019-10-29 17:54:54 +020011 UNKNOWN,
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030012 X_O
13} from './instantiationStatus.component.service';
14import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
Ittay Stern6f900cc2018-08-29 17:01:32 +030015import {AaiService} from "../shared/services/aaiService/aai.service";
16import {MsoService} from "../shared/services/msoService/mso.service";
17import {NgRedux} from "@angular-redux/store";
18import {HttpClientTestingModule} from "@angular/common/http/testing";
19import {FeatureFlagsService} from "../shared/services/featureFlag/feature-flags.service";
20import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
21import {RouterTestingModule} from "@angular/router/testing";
22import {of} from "rxjs";
23import {UrlTree} from "@angular/router";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030024
Ittay Stern6f900cc2018-08-29 17:01:32 +030025class MockAppStore<T> {
26
27 getState() {
28 return {
29 global: {
30 flags: {
31 'FLAG_1902_NEW_VIEW_EDIT': true,
32
33 }
34 }
35 }
36 }
37
38 dispatch() {
39
40 }
41}
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030042describe('Instantiation Status Service', () => {
43 let injector;
Ittay Stern6f900cc2018-08-29 17:01:32 +030044 let aaiService: AaiService;
45 let msoService: MsoService;
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030046 let service: InstantiationStatusComponentService;
47
Ittay Stern6f900cc2018-08-29 17:01:32 +030048
49 beforeAll(done => (async () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030050 TestBed.configureTestingModule({
Ittay Stern6f900cc2018-08-29 17:01:32 +030051 imports: [
52 HttpClientTestingModule,
53 RouterTestingModule,
54 ],
55 providers: [
56 InstantiationStatusComponentService,
57 AaiService,
58 MsoService,
59 FeatureFlagsService,
60 {provide: NgRedux, useClass: MockAppStore}]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030061 });
Ittay Stern6f900cc2018-08-29 17:01:32 +030062 await TestBed.compileComponents();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030063
64 injector = getTestBed();
Ittay Stern6f900cc2018-08-29 17:01:32 +030065 aaiService = injector.get(AaiService);
66 msoService = injector.get(MsoService);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030067 service = injector.get(InstantiationStatusComponentService);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030068
Ittay Stern6f900cc2018-08-29 17:01:32 +030069 })().then(done).catch(done.fail));
70
71 test('generateServiceInfoDataMapping should return mapping of arrays', () => {
72 let data : ServiceInfoModel[] = generateServiceInfoData();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030073 let result = service.generateServiceInfoDataMapping(data);
74
75 expect(result['1']).toBeDefined();
76 expect(result['2']).toBeDefined();
77 expect(result['3']).toBeDefined();
78
79 expect(result['1'].length).toEqual(2);
80 expect(result['2'].length).toEqual(2);
81 expect(result['3'].length).toEqual(1);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030082 });
83
Ittay Stern6f900cc2018-08-29 17:01:32 +030084 test('generateServiceInfoDataMapping if array is empty should return empty object', () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030085 let result = service.generateServiceInfoDataMapping([]);
86
87 expect(result['1']).not.toBeDefined();
88 expect(result['2']).not.toBeDefined();
89 expect(result['3']).not.toBeDefined();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030090 });
91
Ittay Stern6f900cc2018-08-29 17:01:32 +030092 test('convertObjectToArray', () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030093
Ittay Stern6f900cc2018-08-29 17:01:32 +030094 jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
95 of([])
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030096 );
97
Ittay Stern6f900cc2018-08-29 17:01:32 +030098 let data : ServiceInfoModel[] = generateServiceInfoData();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030099 service.convertObjectToArray(data).subscribe((result) => {
100 expect(result).toBeDefined();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300101 });
102 });
103
Ittay Stern6f900cc2018-08-29 17:01:32 +0300104 test('click on "Open" button should open new view edit' , ()=>{
105 const item = {
106 serviceModelId : 'serviceModelId',
107 serviceInstanceId : 'serviceInstanceId',
108 serviceType : 'serviceType',
109 subscriberId : 'subscriberId'
110 };
Ittay Sternf7926712019-07-07 19:23:03 +0300111 let params:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300112 expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
113 expect(params.queryParams).toEqual(
114 {
115 serviceModelId: item.serviceModelId,
116 serviceInstanceId: item.serviceInstanceId,
117 serviceType : item.serviceType,
118 subscriberId : item.subscriberId
119 });
120 });
121
122 test('build the View Edit url' , ()=>{
123 const item = {
124 serviceModelId : '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
125 };
126 let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309';
127 let suffix:string = '../../serviceModels.htm#';
Ittay Sternf7926712019-07-07 19:23:03 +0300128 let tree:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300129 let result = service.getViewEditUrl(tree);
130 expect (suffix + serviceModelUrl).toEqual(result);
131 });
132
Ittay Sterna8ebb742019-10-29 17:54:54 +0200133 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"',
143 })) {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300144
Ittay Sterna8ebb742019-10-29 17:54:54 +0200145 test(`getStatusTooltip should return status popover: status=${status}`, () => {
146 expect(service.getStatus(status).tooltip).toEqual(tooltip);
147 });
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300148
Ittay Sterna8ebb742019-10-29 17:54:54 +0200149 }
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300150
Ittay Stern6f900cc2018-08-29 17:01:32 +0300151 test('getStatusTooltip should return correct icon per job status', () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300152 let result : ServiceStatus = service.getStatus('pending');
153 expect(result.iconClassName).toEqual(PENDING);
154
155 result = service.getStatus('IN_PROGRESS');
156 expect(result.iconClassName).toEqual(INPROGRESS);
157
158 result = service.getStatus('PAUSED');
159 expect(result.iconClassName).toEqual(PAUSE);
160
161 result = service.getStatus('FAILED');
162 expect(result.iconClassName).toEqual(X_O);
163
164 result = service.getStatus('COMPLETED');
165 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
166
167 result = service.getStatus('STOPPED');
Ittay Sterna8ebb742019-10-29 17:54:54 +0200168 expect(result.iconClassName).toEqual(STOPPED);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300169
Ittay Stern6f900cc2018-08-29 17:01:32 +0300170 result = service.getStatus('COMPLETED_WITH_ERRORS');
171 expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);
Ittay Sterna8ebb742019-10-29 17:54:54 +0200172
173 result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
174 expect(result.iconClassName).toEqual(UNKNOWN);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300175 });
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300176
177 function generateServiceInfoData(){
178 return JSON.parse(JSON.stringify([
179 {
180 "created": 1519956533000,
181 "modified": 1521727738000,
182 "createdId": null,
183 "modifiedId": null,
184 "rowNum": null,
185 "auditUserId": null,
186 "auditTrail": null,
187 "jobId": "6748648484",
188 "userId": "2222",
189 "jobStatus": "FAILED",
190 "pause": false,
191 "owningEntityId": "1234",
192 "owningEntityName": null,
193 "project": null,
194 "aicZoneId": null,
195 "aicZoneName": null,
196 "tenantId": null,
197 "tenantName": null,
198 "regionId": null,
199 "regionName": null,
200 "serviceType": 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,
209 "templateId": "1",
210 "hidden": false
211 },
212 {
213 "created": 1519956533000,
214 "modified": 1521727738000,
215 "createdId": null,
216 "modifiedId": null,
217 "rowNum": null,
218 "auditUserId": null,
219 "auditTrail": null,
220 "jobId": "6748648484",
221 "userId": "2222",
222 "jobStatus": "FAILED",
223 "pause": false,
224 "owningEntityId": "1234",
225 "owningEntityName": null,
226 "project": null,
227 "aicZoneId": null,
228 "aicZoneName": null,
229 "tenantId": null,
230 "tenantName": null,
231 "regionId": null,
232 "regionName": null,
233 "serviceType": 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,
242 "templateId": "1",
243 "hidden": false
244 },
245 {
246 "created": 1519956533000,
247 "modified": 1521727738000,
248 "createdId": null,
249 "modifiedId": null,
250 "rowNum": null,
251 "auditUserId": null,
252 "auditTrail": null,
253 "jobId": "6748648484",
254 "userId": "2222",
255 "jobStatus": "FAILED",
256 "pause": false,
257 "owningEntityId": "1234",
258 "owningEntityName": null,
259 "project": null,
260 "aicZoneId": null,
261 "aicZoneName": null,
262 "tenantId": null,
263 "tenantName": null,
264 "regionId": null,
265 "regionName": null,
266 "serviceType": 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,
275 "templateId": "2",
276 "hidden": false
277 },
278 {
279 "created": 1519956533000,
280 "modified": 1521727738000,
281 "createdId": null,
282 "modifiedId": null,
283 "rowNum": null,
284 "auditUserId": null,
285 "auditTrail": null,
286 "jobId": "6748648484",
287 "userId": "2222",
288 "jobStatus": "FAILED",
289 "pause": false,
290 "owningEntityId": "1234",
291 "owningEntityName": null,
292 "project": null,
293 "aicZoneId": null,
294 "aicZoneName": null,
295 "tenantId": null,
296 "tenantName": null,
297 "regionId": null,
298 "regionName": null,
299 "serviceType": 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,
308 "templateId": "2",
309 "hidden": false
310 },
311 {
312 "created": 1519956533000,
313 "modified": 1521727738000,
314 "createdId": null,
315 "modifiedId": null,
316 "rowNum": null,
317 "auditUserId": null,
318 "auditTrail": null,
319 "jobId": "6748648484",
320 "userId": "2222",
321 "jobStatus": "FAILED",
322 "pause": false,
323 "owningEntityId": "1234",
324 "owningEntityName": null,
325 "project": null,
326 "aicZoneId": null,
327 "aicZoneName": null,
328 "tenantId": null,
329 "tenantName": null,
330 "regionId": null,
331 "regionName": null,
332 "serviceType": 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,
341 "templateId": "3",
342 "hidden": false
343 }
344 ]));
345 }
346
347});