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"; |
| 20 | import { TooltipModule } from 'ngx-tooltip'; |
| 21 | |
| 22 | class MockAppStore<T> { |
| 23 | |
| 24 | getState() { |
| 25 | return { |
| 26 | global: { |
| 27 | flags: { |
| 28 | 'FLAG_1902_NEW_VIEW_EDIT': true |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | dispatch() { |
| 35 | |
| 36 | } |
| 37 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 38 | |
| 39 | describe('Instantiation Status Component', () => { |
| 40 | let component: InstantiationStatusComponent; |
| 41 | let fixture: ComponentFixture<InstantiationStatusComponent>; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 42 | let item = new ServiceInfoModel(); |
| 43 | beforeAll(done => (async () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 44 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 45 | TestBed.configureTestingModule({ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 46 | imports: [ |
| 47 | HttpClientTestingModule, |
| 48 | ContextMenuModule, |
| 49 | ScrollToModule.forRoot(), |
| 50 | RouterTestingModule, |
| 51 | TooltipModule |
| 52 | ], |
| 53 | providers: [ |
| 54 | ServiceInfoService, |
| 55 | InstantiationStatusComponentService, |
| 56 | AaiService, |
| 57 | MsoService, |
| 58 | ContextMenuService, |
| 59 | FeatureFlagsService, |
| 60 | ConfigurationService, |
| 61 | LogService, |
| 62 | {provide: NgRedux, useClass: MockAppStore} |
| 63 | ], |
| 64 | declarations: [InstantiationStatusComponent, CapitalizeAndFormatPipe], |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 65 | schemas: [ CUSTOM_ELEMENTS_SCHEMA ] |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 66 | }); |
| 67 | await TestBed.compileComponents(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 68 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 69 | fixture = TestBed.createComponent(InstantiationStatusComponent); |
| 70 | component = fixture.componentInstance; |
| 71 | fixture.detectChanges(); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 72 | })().then(done).catch(done.fail)); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 73 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 74 | |
| 75 | test('component should initialize basic parameters', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 76 | component.TIMER_TIME_IN_SECONDS = 2; |
| 77 | expect(component.TIMER_TIME_IN_SECONDS).toEqual(2); |
| 78 | expect(component.dataIsReady).toBeFalsy(); |
| 79 | expect(component.lastUpdatedDate).toBeNull(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 80 | }); |
| 81 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 82 | test('component constructor should call activateInterval and ngOnInit', () => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 83 | component.refreshData(); |
| 84 | expect(component.dataIsReady).toBeFalsy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 85 | }); |
| 86 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 87 | const enableDeleteItemsDataProvider = [ |
| 88 | ['INSTANTIATE action PENDING job status',JobStatus.PENDING , ServiceAction.INSTANTIATE], |
| 89 | ['DELETE action PENDING job status',JobStatus.PENDING , ServiceAction.DELETE], |
| 90 | ['UPDATE action PENDING job status',JobStatus.PENDING , ServiceAction.UPDATE], |
| 91 | ['INSTANTIATE action STOPPED job status',JobStatus.STOPPED , ServiceAction.INSTANTIATE]]; |
| 92 | each(enableDeleteItemsDataProvider).test('delete item should enable for %s', (desc, jobStatus, action ) => { |
| 93 | item.action=action; |
| 94 | item.jobStatus=jobStatus; |
| 95 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 96 | expect(isDeleteEnabled).toBeTruthy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 97 | }); |
| 98 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 99 | const disableDeleteItemsDataProvider = [ |
| 100 | [ 'INSTANTIATE action COMPLETED job status', JobStatus.COMPLETED , ServiceAction.INSTANTIATE], |
| 101 | [ 'INSTANTIATE action FAILED job status', JobStatus.FAILED , ServiceAction.INSTANTIATE], |
| 102 | [ 'INSTANTIATE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.INSTANTIATE], |
| 103 | [ 'INSTANTIATE action COMPLETED_WITH_ERRORS job status', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE], |
| 104 | [ 'DELETE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.DELETE], |
| 105 | [ 'DELETE action COMPLETED_WITH_ERRORS job status',JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE], |
| 106 | [ 'UPDATE action IN_PROGRESS job status', JobStatus.IN_PROGRESS, ServiceAction.UPDATE], |
| 107 | [ 'UPDATE action COMPLETED_WITH_ERRORS job status', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE], |
| 108 | [ 'INSTANTIATE action UNKNOWN job status', "UNKNOWN", ServiceAction.INSTANTIATE]]; |
| 109 | each(disableDeleteItemsDataProvider).test('delete item should disable for %s', (desc,jobStatus, action ) => { |
| 110 | item.action=action; |
| 111 | item.jobStatus=jobStatus; |
| 112 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 113 | expect(isDeleteEnabled).toBeFalsy(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 114 | }); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 115 | |
| 116 | const enableHideItemsDataProvider = [ |
| 117 | ['instantiate action job status COMPLETED',JobStatus.COMPLETED, ServiceAction.INSTANTIATE ], |
| 118 | ['instantiate action job status FAILED',JobStatus.FAILED, ServiceAction.INSTANTIATE ], |
| 119 | ['instantiate action job status STOPPED', JobStatus.STOPPED, ServiceAction.INSTANTIATE ], |
| 120 | ['instantiate action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE ], |
| 121 | ['delete action job status COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE ], |
| 122 | ['delete action job status FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 123 | ['delete action job status STOPPED',JobStatus.STOPPED, ServiceAction.DELETE ], |
| 124 | ['delete action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 125 | ['update action job status COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 126 | ['update action job status FAILED',JobStatus.FAILED, ServiceAction.UPDATE ], |
| 127 | ['update action job status STOPPED', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 128 | ['update action job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 129 | each(enableHideItemsDataProvider).test('hide item should be enabled for %s', (desc, jobStatus, action ) => { |
| 130 | item.action=action; |
| 131 | item.jobStatus=jobStatus; |
| 132 | let isHideEnabled: boolean = component.isHideEnabled(item); |
| 133 | expect(isHideEnabled).toBeTruthy(); |
| 134 | }); |
| 135 | |
| 136 | const disableHideItemsDataProvider = [ |
| 137 | ['action instantiate job status IN_PROGRESS',JobStatus.IN_PROGRESS , ServiceAction.INSTANTIATE], |
| 138 | ['action instantiate job status PAUSE',JobStatus.PAUSE, ServiceAction.INSTANTIATE], |
| 139 | ['action instantiate job status PENDING', JobStatus.PENDING, ServiceAction.INSTANTIATE ], |
| 140 | ['action instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.INSTANTIATE], |
| 141 | ['update instantiate job status IN_PROGRESS', JobStatus.IN_PROGRESS , ServiceAction.UPDATE], |
| 142 | ['update instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE], |
| 143 | ['update instantiate job status PENDING', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 144 | ['update instantiate job status UNKNOWN',"UNKNOWN", ServiceAction.UPDATE], |
| 145 | ['delete instantiate job status IN_PROGRESS',JobStatus.IN_PROGRESS , ServiceAction.DELETE], |
| 146 | ['delete instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.DELETE], |
| 147 | ['delete instantiate job status PENDING', JobStatus.PENDING, ServiceAction.DELETE ], |
| 148 | ['delete instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.DELETE]]; |
| 149 | each(disableHideItemsDataProvider).test('hide item should disable for %s', (desc, jobStatus, action ) => { |
| 150 | item.action=action; |
| 151 | item.jobStatus=jobStatus; |
| 152 | let isHideEnabled: boolean = component.isHideEnabled(item); |
| 153 | expect(isHideEnabled).toBeFalsy(); |
| 154 | }); |
| 155 | |
| 156 | const enableAuditItemsDataProvider = [ |
| 157 | ['instantiate action UNKNOWN job status', "UNKNOWN", ServiceAction.INSTANTIATE ], |
| 158 | ['delete action JobStatus IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.DELETE ], |
| 159 | ['delete action JobStatus PAUSE', JobStatus.PAUSE, ServiceAction.DELETE ], |
| 160 | ['delete action JobStatus FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 161 | ['delete action JobStatus COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE ], |
| 162 | ['delete action JobStatus COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 163 | ['update action JobStatus IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.UPDATE ], |
| 164 | ['update action JobStatus PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE ], |
| 165 | ['update action JobStatus COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 166 | ['update action JobStatus FAILED', JobStatus.FAILED, ServiceAction.UPDATE ], |
| 167 | ['update action JobStatus COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 168 | |
| 169 | each(enableAuditItemsDataProvider).test('audit item should be enabled for %s', (desc, jobStatus, action ) => { |
| 170 | item.action=action; |
| 171 | item.jobStatus=jobStatus; |
| 172 | const isAuditEnabled: boolean = component.isAuditInfoEnabled(item); |
| 173 | expect(isAuditEnabled).toBeTruthy(); |
| 174 | }); |
| 175 | |
| 176 | const disableAuditItemsDataProvider = [ |
| 177 | ['Job status STOPPED action update', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 178 | ['Job status PENDING action update', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 179 | ['Job status UNKNOWN action update', "UNKNOWN", ServiceAction.UPDATE], |
| 180 | ['Job status STOPPED action delete',JobStatus.STOPPED, ServiceAction.DELETE], |
| 181 | ['Job status PENDING action delete', JobStatus.PENDING, ServiceAction.DELETE ], |
| 182 | ['Job status UNKNOWN action delete', "UNKNOWN", ServiceAction.DELETE]]; |
| 183 | each(disableAuditItemsDataProvider).test('audit item should be disabled for %s', (desc, jobStatus, action ) => { |
| 184 | item.action=action; |
| 185 | item.jobStatus=jobStatus; |
| 186 | let isAuditEnabled: boolean = component.isAuditInfoEnabled(item); |
| 187 | expect(isAuditEnabled).toBeFalsy(); |
| 188 | }); |
| 189 | |
| 190 | const enableOpenItemsDataProvider = [ |
| 191 | ['action instantiate job status PAUSE', JobStatus.PAUSE, ServiceAction.INSTANTIATE ], |
| 192 | ['action instantiate job status COMPLETED', JobStatus.COMPLETED, ServiceAction.INSTANTIATE ], |
| 193 | ['action instantiate job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.INSTANTIATE ], |
| 194 | ['action delete job status PENDING', JobStatus.PENDING, ServiceAction.DELETE ], |
| 195 | ['action delete job status FAILED', JobStatus.FAILED, ServiceAction.DELETE ], |
| 196 | ['action delete job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.DELETE ], |
| 197 | ['action update job status PENDING', JobStatus.PENDING, ServiceAction.UPDATE ], |
| 198 | ['action update job status PAUSE', JobStatus.PAUSE, ServiceAction.UPDATE ], |
| 199 | ['action update job status COMPLETED', JobStatus.COMPLETED, ServiceAction.UPDATE ], |
| 200 | ['action update job status FAILED', JobStatus.FAILED, ServiceAction.UPDATE ], |
| 201 | ['action update job status COMPLETED_WITH_ERRORS', JobStatus.COMPLETED_WITH_ERRORS, ServiceAction.UPDATE ]]; |
| 202 | each(enableOpenItemsDataProvider).test('open item should be enabled for %s', (desc, jobStatus, action ) => { |
| 203 | item.action=action; |
| 204 | item.jobStatus=jobStatus; |
| 205 | let isOpenEnabled: boolean = component.isOpenEnabled(item); |
| 206 | expect(isOpenEnabled).toBeTruthy(); |
| 207 | }); |
| 208 | |
| 209 | const disableOpenItemsDataProvider = [ |
| 210 | ['action instantiate job status STOPPED', JobStatus.STOPPED, ServiceAction.INSTANTIATE], |
| 211 | ['action instantiate job status FAILED', JobStatus.FAILED, ServiceAction.INSTANTIATE], |
| 212 | ['action instantiate job status UNKNOWN', "UNKNOWN", ServiceAction.INSTANTIATE], |
| 213 | ['action update job status STOPPED', JobStatus.STOPPED, ServiceAction.UPDATE ], |
| 214 | ['action update job status IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.UPDATE ], |
| 215 | ['action update job status UNKNOWN', "UNKNOWN", ServiceAction.UPDATE], |
| 216 | ['action delete job status COMPLETED', JobStatus.COMPLETED, ServiceAction.DELETE], |
| 217 | ['action delete job status PAUSE', JobStatus.PAUSE, ServiceAction.DELETE], |
| 218 | ['action delete job status IN_PROGRESS', JobStatus.IN_PROGRESS, ServiceAction.DELETE ], |
| 219 | ['action delete job status UNKNOWN',"UNKNOWN", ServiceAction.DELETE]]; |
| 220 | each(disableOpenItemsDataProvider).test('open item should be disabled for %s', (desc, jobStatus, action ) => { |
| 221 | item.action=action; |
| 222 | item.jobStatus=jobStatus; |
| 223 | let isOpenEnabled: boolean = component.isOpenEnabled(item); |
| 224 | expect(isOpenEnabled).toBeFalsy(); |
| 225 | }); |
| 226 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 227 | }); |