blob: e6ccdda8e613ce3378ae4f654c041a62d488fac7 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {ComponentFixture, TestBed} from '@angular/core/testing';
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03002import {InstantiationStatusComponent} from './instantiationStatus.component';
3import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service';
4import {InstantiationStatusComponentService} from './instantiationStatus.component.service';
Ittay Stern6f900cc2018-08-29 17:01:32 +03005import {ContextMenuModule, ContextMenuService} from 'ngx-contextmenu';
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03006import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
Ittay Stern6f900cc2018-08-29 17:01:32 +03007import {HttpClientTestingModule} from '@angular/common/http/testing';
8import {ScrollToModule} from '@nicky-lenaers/ngx-scroll-to';
9import {ConfigurationService} from '../shared/services/configuration.service';
10import {LogService} from '../shared/utils/log/log.service';
11import {NgRedux} from '@angular-redux/store';
12import {RouterTestingModule} from '@angular/router/testing';
13import {CapitalizeAndFormatPipe} from "../shared/pipes/capitalize/capitalize-and-format.pipe";
14import {AaiService} from "../shared/services/aaiService/aai.service";
15import {MsoService} from "../shared/services/msoService/mso.service";
16import {FeatureFlagsService} from "../shared/services/featureFlag/feature-flags.service";
17import {JobStatus, ServiceAction} from "../shared/models/serviceInstanceActions";
18import each from 'jest-each';
19import {ServiceInfoModel} from "../shared/server/serviceInfo/serviceInfo.model";
Eylon Malind00cf802019-12-03 12:12:38 +020020import {TooltipModule} from 'ngx-tooltip';
21import {SearchFilterPipe} from "../shared/pipes/searchFilter/search-filter.pipe";
22import {ActivatedRoute} from "@angular/router";
23import {FormsModule} from "@angular/forms";
Ittay Stern6f900cc2018-08-29 17:01:32 +030024
25class 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)ff76b5e2018-07-10 15:57:37 +030041
Eylon Malind00cf802019-12-03 12:12:38 +020042class ActivatedRouteMock<T>{
43 queryParams() {
44 return {}
45 };
46
47 snapshot = {
48 queryParams : {}
49 }
50}
51
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030052describe('Instantiation Status Component', () => {
53 let component: InstantiationStatusComponent;
54 let fixture: ComponentFixture<InstantiationStatusComponent>;
Eylon Malind00cf802019-12-03 12:12:38 +020055 let item = new ServiceInfoModel();
56
Ittay Stern6f900cc2018-08-29 17:01:32 +030057 beforeAll(done => (async () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030058
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030059 TestBed.configureTestingModule({
Ittay Stern6f900cc2018-08-29 17:01:32 +030060 imports: [
61 HttpClientTestingModule,
62 ContextMenuModule,
63 ScrollToModule.forRoot(),
64 RouterTestingModule,
Eylon Malind00cf802019-12-03 12:12:38 +020065 TooltipModule,
66 FormsModule,
Ittay Stern6f900cc2018-08-29 17:01:32 +030067 ],
68 providers: [
69 ServiceInfoService,
70 InstantiationStatusComponentService,
71 AaiService,
72 MsoService,
73 ContextMenuService,
74 FeatureFlagsService,
75 ConfigurationService,
76 LogService,
Eylon Malind00cf802019-12-03 12:12:38 +020077 {provide: ActivatedRoute, useClass: ActivatedRouteMock},
Ittay Stern6f900cc2018-08-29 17:01:32 +030078 {provide: NgRedux, useClass: MockAppStore}
79 ],
Eylon Malind00cf802019-12-03 12:12:38 +020080 declarations: [InstantiationStatusComponent, CapitalizeAndFormatPipe, SearchFilterPipe],
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030081 schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
Ittay Stern6f900cc2018-08-29 17:01:32 +030082 });
83 await TestBed.compileComponents();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030084
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030085 fixture = TestBed.createComponent(InstantiationStatusComponent);
86 component = fixture.componentInstance;
87 fixture.detectChanges();
Ittay Stern6f900cc2018-08-29 17:01:32 +030088 })().then(done).catch(done.fail));
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030089
Ittay Stern6f900cc2018-08-29 17:01:32 +030090
91 test('component should initialize basic parameters', () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030092 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)ff76b5e2018-07-10 15:57:37 +030096 });
97
Ittay Stern6f900cc2018-08-29 17:01:32 +030098 test('component constructor should call activateInterval and ngOnInit', () => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030099 component.refreshData();
100 expect(component.dataIsReady).toBeFalsy();
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300101 });
102
Ittay Stern6f900cc2018-08-29 17:01:32 +0300103 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)ff76b5e2018-07-10 15:57:37 +0300113 });
114
Ittay Stern6f900cc2018-08-29 17:01:32 +0300115 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)ff76b5e2018-07-10 15:57:37 +0300130 });
Ittay Stern6f900cc2018-08-29 17:01:32 +0300131
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)ff76b5e2018-07-10 15:57:37 +0300243});