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, |
| 9 | STOPED, |
| 10 | SUCCESS_CIRCLE, |
| 11 | X_O |
| 12 | } from './instantiationStatus.component.service'; |
| 13 | import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 14 | import {AaiService} from "../shared/services/aaiService/aai.service"; |
| 15 | import {MsoService} from "../shared/services/msoService/mso.service"; |
| 16 | import {NgRedux} from "@angular-redux/store"; |
| 17 | import {HttpClientTestingModule} from "@angular/common/http/testing"; |
| 18 | import {FeatureFlagsService} from "../shared/services/featureFlag/feature-flags.service"; |
| 19 | import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes"; |
| 20 | import {RouterTestingModule} from "@angular/router/testing"; |
| 21 | import {of} from "rxjs"; |
| 22 | import {UrlTree} from "@angular/router"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 23 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 24 | class MockAppStore<T> { |
| 25 | |
| 26 | getState() { |
| 27 | return { |
| 28 | global: { |
| 29 | flags: { |
| 30 | 'FLAG_1902_NEW_VIEW_EDIT': true, |
| 31 | |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | dispatch() { |
| 38 | |
| 39 | } |
| 40 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 41 | describe('Instantiation Status Service', () => { |
| 42 | let injector; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 43 | let aaiService: AaiService; |
| 44 | let msoService: MsoService; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 45 | let service: InstantiationStatusComponentService; |
| 46 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 47 | |
| 48 | beforeAll(done => (async () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 49 | TestBed.configureTestingModule({ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 50 | imports: [ |
| 51 | HttpClientTestingModule, |
| 52 | RouterTestingModule, |
| 53 | ], |
| 54 | providers: [ |
| 55 | InstantiationStatusComponentService, |
| 56 | AaiService, |
| 57 | MsoService, |
| 58 | FeatureFlagsService, |
| 59 | {provide: NgRedux, useClass: MockAppStore}] |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 60 | }); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 61 | await TestBed.compileComponents(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 62 | |
| 63 | injector = getTestBed(); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 64 | aaiService = injector.get(AaiService); |
| 65 | msoService = injector.get(MsoService); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 66 | service = injector.get(InstantiationStatusComponentService); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 67 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 68 | })().then(done).catch(done.fail)); |
| 69 | |
| 70 | test('generateServiceInfoDataMapping should return mapping of arrays', () => { |
| 71 | let data : ServiceInfoModel[] = generateServiceInfoData(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 72 | let result = service.generateServiceInfoDataMapping(data); |
| 73 | |
| 74 | expect(result['1']).toBeDefined(); |
| 75 | expect(result['2']).toBeDefined(); |
| 76 | expect(result['3']).toBeDefined(); |
| 77 | |
| 78 | expect(result['1'].length).toEqual(2); |
| 79 | expect(result['2'].length).toEqual(2); |
| 80 | expect(result['3'].length).toEqual(1); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 81 | }); |
| 82 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 83 | test('generateServiceInfoDataMapping if array is empty should return empty object', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 84 | let result = service.generateServiceInfoDataMapping([]); |
| 85 | |
| 86 | expect(result['1']).not.toBeDefined(); |
| 87 | expect(result['2']).not.toBeDefined(); |
| 88 | expect(result['3']).not.toBeDefined(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 89 | }); |
| 90 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 91 | test('convertObjectToArray', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 92 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 93 | jest.spyOn(service, 'convertObjectToArray').mockReturnValue( |
| 94 | of([]) |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 95 | ); |
| 96 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 97 | let data : ServiceInfoModel[] = generateServiceInfoData(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 98 | service.convertObjectToArray(data).subscribe((result) => { |
| 99 | expect(result).toBeDefined(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 100 | }); |
| 101 | }); |
| 102 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 103 | test('click on "Open" button should open new view edit' , ()=>{ |
| 104 | const item = { |
| 105 | serviceModelId : 'serviceModelId', |
| 106 | serviceInstanceId : 'serviceInstanceId', |
| 107 | serviceType : 'serviceType', |
| 108 | subscriberId : 'subscriberId' |
| 109 | }; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 110 | let params:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 111 | expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy(); |
| 112 | expect(params.queryParams).toEqual( |
| 113 | { |
| 114 | serviceModelId: item.serviceModelId, |
| 115 | serviceInstanceId: item.serviceInstanceId, |
| 116 | serviceType : item.serviceType, |
| 117 | subscriberId : item.subscriberId |
| 118 | }); |
| 119 | }); |
| 120 | |
| 121 | test('build the View Edit url' , ()=>{ |
| 122 | const item = { |
| 123 | serviceModelId : '28aeb8f6-5620-4148-8bfb-a5fb406f0309', |
| 124 | }; |
| 125 | let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309'; |
| 126 | let suffix:string = '../../serviceModels.htm#'; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 127 | let tree:UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 128 | let result = service.getViewEditUrl(tree); |
| 129 | expect (suffix + serviceModelUrl).toEqual(result); |
| 130 | }); |
| 131 | |
| 132 | test('getStatusTooltip should return status popover', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 133 | let result : ServiceStatus = service.getStatus('pending'); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 134 | expect(result.tooltip).toEqual('Pending: The action required will be sent as soon as possible.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 135 | |
| 136 | result = service.getStatus('IN_PROGRESS'); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 137 | expect(result.tooltip).toEqual('In-progress: the service is in process of the action required.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 138 | |
| 139 | result = service.getStatus('PAUSED'); |
| 140 | expect(result.tooltip).toEqual('Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.'); |
| 141 | |
| 142 | result = service.getStatus('FAILED'); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 143 | expect(result.tooltip).toEqual('Failed: All planned actions have failed.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 144 | |
| 145 | result = service.getStatus('COMPLETED'); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 146 | expect(result.tooltip).toEqual('Completed successfully: Service is successfully instantiated, updated or deleted.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 147 | |
| 148 | result = service.getStatus('STOPPED'); |
| 149 | expect(result.tooltip).toEqual('Stopped: Due to previous failure, will not be instantiated.'); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 150 | |
| 151 | result = service.getStatus('COMPLETED_WITH_ERRORS'); |
| 152 | expect(result.tooltip).toEqual('Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 153 | }); |
| 154 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 155 | test('getStatusTooltip should return correct icon per job status', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 156 | let result : ServiceStatus = service.getStatus('pending'); |
| 157 | expect(result.iconClassName).toEqual(PENDING); |
| 158 | |
| 159 | result = service.getStatus('IN_PROGRESS'); |
| 160 | expect(result.iconClassName).toEqual(INPROGRESS); |
| 161 | |
| 162 | result = service.getStatus('PAUSED'); |
| 163 | expect(result.iconClassName).toEqual(PAUSE); |
| 164 | |
| 165 | result = service.getStatus('FAILED'); |
| 166 | expect(result.iconClassName).toEqual(X_O); |
| 167 | |
| 168 | result = service.getStatus('COMPLETED'); |
| 169 | expect(result.iconClassName).toEqual(SUCCESS_CIRCLE); |
| 170 | |
| 171 | result = service.getStatus('STOPPED'); |
| 172 | expect(result.iconClassName).toEqual(STOPED); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 173 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 174 | result = service.getStatus('COMPLETED_WITH_ERRORS'); |
| 175 | expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS); |
| 176 | }); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 177 | |
| 178 | function generateServiceInfoData(){ |
| 179 | return JSON.parse(JSON.stringify([ |
| 180 | { |
| 181 | "created": 1519956533000, |
| 182 | "modified": 1521727738000, |
| 183 | "createdId": null, |
| 184 | "modifiedId": null, |
| 185 | "rowNum": null, |
| 186 | "auditUserId": null, |
| 187 | "auditTrail": null, |
| 188 | "jobId": "6748648484", |
| 189 | "userId": "2222", |
| 190 | "jobStatus": "FAILED", |
| 191 | "pause": false, |
| 192 | "owningEntityId": "1234", |
| 193 | "owningEntityName": null, |
| 194 | "project": null, |
| 195 | "aicZoneId": null, |
| 196 | "aicZoneName": null, |
| 197 | "tenantId": null, |
| 198 | "tenantName": null, |
| 199 | "regionId": null, |
| 200 | "regionName": null, |
| 201 | "serviceType": null, |
| 202 | "subscriberName": null, |
| 203 | "serviceInstanceId": "1", |
| 204 | "serviceInstanceName": null, |
| 205 | "serviceModelId": null, |
| 206 | "serviceModelName": null, |
| 207 | "serviceModelVersion": null, |
| 208 | "createdBulkDate": 1519956533000, |
| 209 | "statusModifiedDate": 1520042933000, |
| 210 | "templateId": "1", |
| 211 | "hidden": false |
| 212 | }, |
| 213 | { |
| 214 | "created": 1519956533000, |
| 215 | "modified": 1521727738000, |
| 216 | "createdId": null, |
| 217 | "modifiedId": null, |
| 218 | "rowNum": null, |
| 219 | "auditUserId": null, |
| 220 | "auditTrail": null, |
| 221 | "jobId": "6748648484", |
| 222 | "userId": "2222", |
| 223 | "jobStatus": "FAILED", |
| 224 | "pause": false, |
| 225 | "owningEntityId": "1234", |
| 226 | "owningEntityName": null, |
| 227 | "project": null, |
| 228 | "aicZoneId": null, |
| 229 | "aicZoneName": null, |
| 230 | "tenantId": null, |
| 231 | "tenantName": null, |
| 232 | "regionId": null, |
| 233 | "regionName": null, |
| 234 | "serviceType": null, |
| 235 | "subscriberName": null, |
| 236 | "serviceInstanceId": "1", |
| 237 | "serviceInstanceName": null, |
| 238 | "serviceModelId": null, |
| 239 | "serviceModelName": null, |
| 240 | "serviceModelVersion": null, |
| 241 | "createdBulkDate": 1519956533000, |
| 242 | "statusModifiedDate": 1520042933000, |
| 243 | "templateId": "1", |
| 244 | "hidden": false |
| 245 | }, |
| 246 | { |
| 247 | "created": 1519956533000, |
| 248 | "modified": 1521727738000, |
| 249 | "createdId": null, |
| 250 | "modifiedId": null, |
| 251 | "rowNum": null, |
| 252 | "auditUserId": null, |
| 253 | "auditTrail": null, |
| 254 | "jobId": "6748648484", |
| 255 | "userId": "2222", |
| 256 | "jobStatus": "FAILED", |
| 257 | "pause": false, |
| 258 | "owningEntityId": "1234", |
| 259 | "owningEntityName": null, |
| 260 | "project": null, |
| 261 | "aicZoneId": null, |
| 262 | "aicZoneName": null, |
| 263 | "tenantId": null, |
| 264 | "tenantName": null, |
| 265 | "regionId": null, |
| 266 | "regionName": null, |
| 267 | "serviceType": null, |
| 268 | "subscriberName": null, |
| 269 | "serviceInstanceId": "2", |
| 270 | "serviceInstanceName": null, |
| 271 | "serviceModelId": null, |
| 272 | "serviceModelName": null, |
| 273 | "serviceModelVersion": null, |
| 274 | "createdBulkDate": 1519956533000, |
| 275 | "statusModifiedDate": 1520042933000, |
| 276 | "templateId": "2", |
| 277 | "hidden": false |
| 278 | }, |
| 279 | { |
| 280 | "created": 1519956533000, |
| 281 | "modified": 1521727738000, |
| 282 | "createdId": null, |
| 283 | "modifiedId": null, |
| 284 | "rowNum": null, |
| 285 | "auditUserId": null, |
| 286 | "auditTrail": null, |
| 287 | "jobId": "6748648484", |
| 288 | "userId": "2222", |
| 289 | "jobStatus": "FAILED", |
| 290 | "pause": false, |
| 291 | "owningEntityId": "1234", |
| 292 | "owningEntityName": null, |
| 293 | "project": null, |
| 294 | "aicZoneId": null, |
| 295 | "aicZoneName": null, |
| 296 | "tenantId": null, |
| 297 | "tenantName": null, |
| 298 | "regionId": null, |
| 299 | "regionName": null, |
| 300 | "serviceType": null, |
| 301 | "subscriberName": null, |
| 302 | "serviceInstanceId": "2", |
| 303 | "serviceInstanceName": null, |
| 304 | "serviceModelId": null, |
| 305 | "serviceModelName": null, |
| 306 | "serviceModelVersion": null, |
| 307 | "createdBulkDate": 1519956533000, |
| 308 | "statusModifiedDate": 1520042933000, |
| 309 | "templateId": "2", |
| 310 | "hidden": false |
| 311 | }, |
| 312 | { |
| 313 | "created": 1519956533000, |
| 314 | "modified": 1521727738000, |
| 315 | "createdId": null, |
| 316 | "modifiedId": null, |
| 317 | "rowNum": null, |
| 318 | "auditUserId": null, |
| 319 | "auditTrail": null, |
| 320 | "jobId": "6748648484", |
| 321 | "userId": "2222", |
| 322 | "jobStatus": "FAILED", |
| 323 | "pause": false, |
| 324 | "owningEntityId": "1234", |
| 325 | "owningEntityName": null, |
| 326 | "project": null, |
| 327 | "aicZoneId": null, |
| 328 | "aicZoneName": null, |
| 329 | "tenantId": null, |
| 330 | "tenantName": null, |
| 331 | "regionId": null, |
| 332 | "regionName": null, |
| 333 | "serviceType": null, |
| 334 | "subscriberName": null, |
| 335 | "serviceInstanceId": "3", |
| 336 | "serviceInstanceName": null, |
| 337 | "serviceModelId": null, |
| 338 | "serviceModelName": null, |
| 339 | "serviceModelVersion": null, |
| 340 | "createdBulkDate": 1519956533000, |
| 341 | "statusModifiedDate": 1520042933000, |
| 342 | "templateId": "3", |
| 343 | "hidden": false |
| 344 | } |
| 345 | ])); |
| 346 | } |
| 347 | |
| 348 | }); |