Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {getTestBed, TestBed} from '@angular/core/testing'; |
| 2 | import { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 3 | COMPLETED_WITH_ERRORS, |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 4 | INPROGRESS, |
| 5 | InstantiationStatusComponentService, |
| 6 | PAUSE, |
| 7 | PENDING, |
| 8 | ServiceStatus, |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 9 | STOPPED, |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 10 | SUCCESS_CIRCLE, |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 11 | UNKNOWN, |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 12 | X_O |
| 13 | } from './instantiationStatus.component.service'; |
| 14 | import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 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"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 24 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 25 | class 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) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 42 | describe('Instantiation Status Service', () => { |
| 43 | let injector; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 44 | let aaiService: AaiService; |
| 45 | let msoService: MsoService; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 46 | let service: InstantiationStatusComponentService; |
| 47 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 48 | |
| 49 | beforeAll(done => (async () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 50 | TestBed.configureTestingModule({ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 51 | imports: [ |
| 52 | HttpClientTestingModule, |
| 53 | RouterTestingModule, |
| 54 | ], |
| 55 | providers: [ |
| 56 | InstantiationStatusComponentService, |
| 57 | AaiService, |
| 58 | MsoService, |
| 59 | FeatureFlagsService, |
| 60 | {provide: NgRedux, useClass: MockAppStore}] |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 61 | }); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 62 | await TestBed.compileComponents(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 63 | |
| 64 | injector = getTestBed(); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 65 | aaiService = injector.get(AaiService); |
| 66 | msoService = injector.get(MsoService); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 67 | service = injector.get(InstantiationStatusComponentService); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 68 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 69 | })().then(done).catch(done.fail)); |
| 70 | |
| 71 | test('generateServiceInfoDataMapping should return mapping of arrays', () => { |
| 72 | let data : ServiceInfoModel[] = generateServiceInfoData(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 73 | 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) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 82 | }); |
| 83 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 84 | test('generateServiceInfoDataMapping if array is empty should return empty object', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 85 | 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) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 90 | }); |
| 91 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 92 | test('convertObjectToArray', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 93 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 94 | jest.spyOn(service, 'convertObjectToArray').mockReturnValue( |
| 95 | of([]) |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 96 | ); |
| 97 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 98 | let data : ServiceInfoModel[] = generateServiceInfoData(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 99 | service.convertObjectToArray(data).subscribe((result) => { |
| 100 | expect(result).toBeDefined(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 101 | }); |
| 102 | }); |
| 103 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 104 | 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 Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 111 | let params:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 112 | 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 Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 128 | let tree:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 129 | let result = service.getViewEditUrl(tree); |
| 130 | expect (suffix + serviceModelUrl).toEqual(result); |
| 131 | }); |
| 132 | |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 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"', |
| 143 | })) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 144 | |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 145 | test(`getStatusTooltip should return status popover: status=${status}`, () => { |
| 146 | expect(service.getStatus(status).tooltip).toEqual(tooltip); |
| 147 | }); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 148 | |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 149 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 150 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 151 | test('getStatusTooltip should return correct icon per job status', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 152 | 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 Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 168 | expect(result.iconClassName).toEqual(STOPPED); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 169 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 170 | result = service.getStatus('COMPLETED_WITH_ERRORS'); |
| 171 | expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS); |
Ittay Stern | a8ebb74 | 2019-10-29 17:54:54 +0200 | [diff] [blame^] | 172 | |
| 173 | result = service.getStatus('UNEXPECTED_RANDOM_STATUS'); |
| 174 | expect(result.iconClassName).toEqual(UNKNOWN); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 175 | }); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 176 | |
| 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 | }); |