Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {ComponentFixture, TestBed} from '@angular/core/testing'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 2 | import {InstantiationStatusComponent} from './instantiationStatus.component'; |
| 3 | import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service'; |
| 4 | import {InstantiationStatusComponentService} from './instantiationStatus.component.service'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 5 | import {ContextMenuModule, ContextMenuService} from 'ngx-contextmenu'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 6 | import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 7 | import {HttpClientTestingModule} from '@angular/common/http/testing'; |
| 8 | import {ScrollToModule} from '@nicky-lenaers/ngx-scroll-to'; |
| 9 | import {ConfigurationService} from '../shared/services/configuration.service'; |
| 10 | import {LogService} from '../shared/utils/log/log.service'; |
| 11 | import {NgRedux} from '@angular-redux/store'; |
| 12 | import {RouterTestingModule} from '@angular/router/testing'; |
| 13 | import {CapitalizeAndFormatPipe} from "../shared/pipes/capitalize/capitalize-and-format.pipe"; |
| 14 | import {AaiService} from "../shared/services/aaiService/aai.service"; |
| 15 | import {MsoService} from "../shared/services/msoService/mso.service"; |
| 16 | import {FeatureFlagsService} from "../shared/services/featureFlag/feature-flags.service"; |
| 17 | import {JobStatus, ServiceAction} from "../shared/models/serviceInstanceActions"; |
| 18 | import each from 'jest-each'; |
| 19 | import {ServiceInfoModel} from "../shared/server/serviceInfo/serviceInfo.model"; |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 20 | import {TooltipModule} from 'ngx-tooltip'; |
| 21 | import {SearchFilterPipe} from "../shared/pipes/searchFilter/search-filter.pipe"; |
| 22 | import {ActivatedRoute} from "@angular/router"; |
| 23 | import {FormsModule} from "@angular/forms"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 24 | |
| 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 | dispatch() { |
| 38 | |
| 39 | } |
| 40 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 41 | |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 42 | class ActivatedRouteMock<T>{ |
| 43 | queryParams() { |
| 44 | return {} |
| 45 | }; |
| 46 | |
| 47 | snapshot = { |
| 48 | queryParams : {} |
| 49 | } |
| 50 | } |
| 51 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 52 | describe('Instantiation Status Component', () => { |
| 53 | let component: InstantiationStatusComponent; |
| 54 | let fixture: ComponentFixture<InstantiationStatusComponent>; |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 55 | let item = new ServiceInfoModel(); |
| 56 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 57 | beforeAll(done => (async () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 58 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 59 | TestBed.configureTestingModule({ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 60 | imports: [ |
| 61 | HttpClientTestingModule, |
| 62 | ContextMenuModule, |
| 63 | ScrollToModule.forRoot(), |
| 64 | RouterTestingModule, |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 65 | TooltipModule, |
| 66 | FormsModule, |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 67 | ], |
| 68 | providers: [ |
| 69 | ServiceInfoService, |
| 70 | InstantiationStatusComponentService, |
| 71 | AaiService, |
| 72 | MsoService, |
| 73 | ContextMenuService, |
| 74 | FeatureFlagsService, |
| 75 | ConfigurationService, |
| 76 | LogService, |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 77 | {provide: ActivatedRoute, useClass: ActivatedRouteMock}, |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 78 | {provide: NgRedux, useClass: MockAppStore} |
| 79 | ], |
Eylon Malin | d00cf80 | 2019-12-03 12:12:38 +0200 | [diff] [blame^] | 80 | declarations: [InstantiationStatusComponent, CapitalizeAndFormatPipe, SearchFilterPipe], |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 81 | schemas: [ CUSTOM_ELEMENTS_SCHEMA ] |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 82 | }); |
| 83 | await TestBed.compileComponents(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 84 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 85 | fixture = TestBed.createComponent(InstantiationStatusComponent); |
| 86 | component = fixture.componentInstance; |
| 87 | fixture.detectChanges(); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 88 | })().then(done).catch(done.fail)); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 89 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 90 | |
| 91 | test('component should initialize basic parameters', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 92 | component.TIMER_TIME_IN_SECONDS = 2; |
| 93 | expect(component.TIMER_TIME_IN_SECONDS).toEqual(2); |
| 94 | expect(component.dataIsReady).toBeFalsy(); |
| 95 | expect(component.lastUpdatedDate).toBeNull(); |
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 | test('component constructor should call activateInterval and ngOnInit', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 99 | component.refreshData(); |
| 100 | expect(component.dataIsReady).toBeFalsy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 101 | }); |
| 102 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 103 | const enableDeleteItemsDataProvider = [ |
| 104 | ['INSTANTIATE action PENDING job status',JobStatus.PENDING , ServiceAction.INSTANTIATE], |
| 105 | ['DELETE action PENDING job status',JobStatus.PENDING , ServiceAction.DELETE], |
| 106 | ['UPDATE action PENDING job status',JobStatus.PENDING , ServiceAction.UPDATE], |
| 107 | ['INSTANTIATE action STOPPED job status',JobStatus.STOPPED , ServiceAction.INSTANTIATE]]; |
| 108 | each(enableDeleteItemsDataProvider).test('delete item should enable for %s', (desc, jobStatus, action ) => { |
| 109 | item.action=action; |
| 110 | item.jobStatus=jobStatus; |
| 111 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 112 | expect(isDeleteEnabled).toBeTruthy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 113 | }); |
| 114 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 115 | const disableDeleteItemsDataProvider = [ |
| 116 | [ 'INSTANTIATE action COMPLETED job status', JobStatus.COMPLETED , ServiceAction.INSTANTIATE], |
| 117 | [ 'INSTANTIATE action FAILED job status', JobStatus.FAILED , ServiceAction.INSTANTIATE], |
| 118 | [ 'INSTANTIATE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.INSTANTIATE], |
| 119 | [ 'INSTANTIATE action COMPLETED_WITH_ERRORS job status', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE], |
| 120 | [ 'DELETE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.DELETE], |
| 121 | [ 'DELETE action COMPLETED_WITH_ERRORS job status',JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE], |
| 122 | [ 'UPDATE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.UPDATE], |
| 123 | [ 'UPDATE action COMPLETED_WITH_ERRORS job status', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE], |
| 124 | [ 'INSTANTIATE action UNKNOWN job status', "UNKNOWN", ServiceAction.INSTANTIATE]]; |
| 125 | each(disableDeleteItemsDataProvider).test('delete item should disable for %s', (desc,jobStatus, action ) => { |
| 126 | item.action=action; |
| 127 | item.jobStatus=jobStatus; |
| 128 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 129 | expect(isDeleteEnabled).toBeFalsy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 130 | }); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 131 | |
| 132 | const enableHideItemsDataProvider = [ |
| 133 | ['instantiate action job status COMPLETED',JobStatus.COMPLETED, ServiceAction.INSTANTIATE ], |
| 134 | ['instantiate action job status FAILED',JobStatus.FAILED, ServiceAction.INSTANTIATE ], |
| 135 | ['instantiate action job status STOPPED', JobStatus.STOPPED, ServiceAction.INSTANTIATE ], |
| 136 | ['instantiate action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE ], |
| 137 | ['delete action job status COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE ], |
| 138 | ['delete action job status FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 139 | ['delete action job status STOPPED',JobStatus.STOPPED, ServiceAction.DELETE ], |
| 140 | ['delete action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 141 | ['update action job status COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 142 | ['update action job status FAILED',JobStatus.FAILED, ServiceAction.UPDATE ], |
| 143 | ['update action job status STOPPED', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 144 | ['update action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 145 | each(enableHideItemsDataProvider).test('hide item should be enabled for %s', (desc, jobStatus, action ) => { |
| 146 | item.action=action; |
| 147 | item.jobStatus=jobStatus; |
| 148 | let isHideEnabled: boolean = component.isHideEnabled(item); |
| 149 | expect(isHideEnabled).toBeTruthy(); |
| 150 | }); |
| 151 | |
| 152 | const disableHideItemsDataProvider = [ |
| 153 | ['action instantiate job status IN_PROGRESS',JobStatus.IN_PROGRESS , ServiceAction.INSTANTIATE], |
| 154 | ['action instantiate job status PAUSE',JobStatus.PAUSE, ServiceAction.INSTANTIATE], |
| 155 | ['action instantiate job status PENDING', JobStatus.PENDING, ServiceAction.INSTANTIATE ], |
| 156 | ['action instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.INSTANTIATE], |
| 157 | ['update instantiate job status IN_PROGRESS', JobStatus.IN_PROGRESS , ServiceAction.UPDATE], |
| 158 | ['update instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE], |
| 159 | ['update instantiate job status PENDING', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 160 | ['update instantiate job status UNKNOWN',"UNKNOWN", ServiceAction.UPDATE], |
| 161 | ['delete instantiate job status IN_PROGRESS',JobStatus.IN_PROGRESS , ServiceAction.DELETE], |
| 162 | ['delete instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.DELETE], |
| 163 | ['delete instantiate job status PENDING', JobStatus.PENDING, ServiceAction.DELETE ], |
| 164 | ['delete instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.DELETE]]; |
| 165 | each(disableHideItemsDataProvider).test('hide item should disable for %s', (desc, jobStatus, action ) => { |
| 166 | item.action=action; |
| 167 | item.jobStatus=jobStatus; |
| 168 | let isHideEnabled: boolean = component.isHideEnabled(item); |
| 169 | expect(isHideEnabled).toBeFalsy(); |
| 170 | }); |
| 171 | |
| 172 | const enableAuditItemsDataProvider = [ |
| 173 | ['instantiate action UNKNOWN job status', "UNKNOWN", ServiceAction.INSTANTIATE ], |
| 174 | ['delete action JobStatus IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.DELETE ], |
| 175 | ['delete action JobStatus PAUSE', JobStatus.PAUSE, ServiceAction.DELETE ], |
| 176 | ['delete action JobStatus FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 177 | ['delete action JobStatus COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE ], |
| 178 | ['delete action JobStatus COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 179 | ['update action JobStatus IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.UPDATE ], |
| 180 | ['update action JobStatus PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE ], |
| 181 | ['update action JobStatus COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 182 | ['update action JobStatus FAILED', JobStatus.FAILED, ServiceAction.UPDATE ], |
| 183 | ['update action JobStatus COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 184 | |
| 185 | each(enableAuditItemsDataProvider).test('audit item should be enabled for %s', (desc, jobStatus, action ) => { |
| 186 | item.action=action; |
| 187 | item.jobStatus=jobStatus; |
| 188 | const isAuditEnabled: boolean = component.isAuditInfoEnabled(item); |
| 189 | expect(isAuditEnabled).toBeTruthy(); |
| 190 | }); |
| 191 | |
| 192 | const disableAuditItemsDataProvider = [ |
| 193 | ['Job status STOPPED action update', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 194 | ['Job status PENDING action update', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 195 | ['Job status UNKNOWN action update', "UNKNOWN", ServiceAction.UPDATE], |
| 196 | ['Job status STOPPED action delete',JobStatus.STOPPED, ServiceAction.DELETE], |
| 197 | ['Job status PENDING action delete', JobStatus.PENDING, ServiceAction.DELETE ], |
| 198 | ['Job status UNKNOWN action delete', "UNKNOWN", ServiceAction.DELETE]]; |
| 199 | each(disableAuditItemsDataProvider).test('audit item should be disabled for %s', (desc, jobStatus, action ) => { |
| 200 | item.action=action; |
| 201 | item.jobStatus=jobStatus; |
| 202 | let isAuditEnabled: boolean = component.isAuditInfoEnabled(item); |
| 203 | expect(isAuditEnabled).toBeFalsy(); |
| 204 | }); |
| 205 | |
| 206 | const enableOpenItemsDataProvider = [ |
| 207 | ['action instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.INSTANTIATE ], |
| 208 | ['action instantiate job status COMPLETED', JobStatus.COMPLETED, ServiceAction.INSTANTIATE ], |
| 209 | ['action instantiate job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE ], |
| 210 | ['action delete job status PENDING', JobStatus.PENDING, ServiceAction.DELETE ], |
| 211 | ['action delete job status FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 212 | ['action delete job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 213 | ['action update job status PENDING', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 214 | ['action update job status PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE ], |
| 215 | ['action update job status COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 216 | ['action update job status FAILED', JobStatus.FAILED, ServiceAction.UPDATE ], |
| 217 | ['action update job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 218 | each(enableOpenItemsDataProvider).test('open item should be enabled for %s', (desc, jobStatus, action ) => { |
| 219 | item.action=action; |
| 220 | item.jobStatus=jobStatus; |
| 221 | let isOpenEnabled: boolean = component.isOpenEnabled(item); |
| 222 | expect(isOpenEnabled).toBeTruthy(); |
| 223 | }); |
| 224 | |
| 225 | const disableOpenItemsDataProvider = [ |
| 226 | ['action instantiate job status STOPPED', JobStatus.STOPPED, ServiceAction.INSTANTIATE], |
| 227 | ['action instantiate job status FAILED', JobStatus.FAILED, ServiceAction.INSTANTIATE], |
| 228 | ['action instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.INSTANTIATE], |
| 229 | ['action update job status STOPPED', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 230 | ['action update job status IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.UPDATE ], |
| 231 | ['action update job status UNKNOWN', "UNKNOWN", ServiceAction.UPDATE], |
| 232 | ['action delete job status COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE], |
| 233 | ['action delete job status PAUSE', JobStatus.PAUSE, ServiceAction.DELETE], |
| 234 | ['action delete job status IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.DELETE ], |
| 235 | ['action delete job status UNKNOWN',"UNKNOWN", ServiceAction.DELETE]]; |
| 236 | each(disableOpenItemsDataProvider).test('open item should be disabled for %s', (desc, jobStatus, action ) => { |
| 237 | item.action=action; |
| 238 | item.jobStatus=jobStatus; |
| 239 | let isOpenEnabled: boolean = component.isOpenEnabled(item); |
| 240 | expect(isOpenEnabled).toBeFalsy(); |
| 241 | }); |
| 242 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 243 | }); |