Fixed the test cases,added sonar config
[portal.git] / portal-FE-common / src / app / pages / scheduler / scheduler.component.spec.ts
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
39
40 import { SchedulerComponent } from './scheduler.component';
41 import { FormsModule } from '@angular/forms';
42 import { NgMaterialModule } from 'src/app/ng-material-module';
43 import { HttpClientTestingModule } from '@angular/common/http/testing';
44 import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
45 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
46 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
47 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
48 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
49
50 describe('SchedulerComponent', () => {
51   let component: SchedulerComponent;
52   let fixture: ComponentFixture<SchedulerComponent>;
53   const payload: any = {"widgetData":"widgetTestData"};
54   const policy = ["test1","test2","test3"];
55
56   beforeEach(async(() => {
57     TestBed.configureTestingModule({
58       declarations: [ SchedulerComponent,InformationModalComponent,ConfirmationModalComponent ],
59       imports:[FormsModule,NgMaterialModule,HttpClientTestingModule,BrowserAnimationsModule,NgbModule.forRoot()],
60       providers:[NgbActiveModal]
61     }).overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [InformationModalComponent,ConfirmationModalComponent] } })
62     .compileComponents();
63   }));
64
65   beforeEach(() => {
66     fixture = TestBed.createComponent(SchedulerComponent);
67     component = fixture.componentInstance;
68     component.payload =payload;
69     component.policys = policy;
70     component.schedulerObjConst.WorkflowName = "workFlowName";
71     component.schedulerObj.domainData=[{"WorkflowName":"test"}];
72    // component.schedulerObj.schedulingInfo.normalDurationInSeconds= 20;
73    component.vnfObject = {
74     workflow: null,
75     vnfNames:'test1'
76   };
77     component.schedulerObj.schedulingInfo = {
78       normalDurationInSeconds: '',
79       additionalDurationInSeconds: '',
80       concurrencyLimit: '',
81       policyId: '',
82       vnfDetails: [
83         {
84           groupId: "",
85           node: [],
86           changeWindow: [{
87             startTime: '',
88             endTime: ''
89           }]
90         }]
91       };
92     
93     // component.schedulerObj.schedulingInfo.additionalDurationInSeconds= null;
94     // component.schedulerObj.schedulingInfo.concurrencyLimit=null;
95     // component.schedulerObj.schedulingInfo['vnfDetails'][0].groupId=null;
96     // component.schedulerObj.schedulingInfo['vnfDetails'][0].node=null;
97     fixture.detectChanges();
98   });
99
100   it('should create', () => {
101     expect(component).toBeTruthy();
102   });
103
104   it('radioSelections should return stubbed value', () => {
105     spyOn(component, 'radioSelections').and.callThrough();
106     component.schedulerForm.checkboxSelection = "true";
107     component.radioSelections();
108     expect(component.radioSelections).toHaveBeenCalledWith();
109   });
110
111   it('onChangeUpdatePolicyName should return stubbed value', () => {
112     spyOn(component, 'onChangeUpdatePolicyName').and.callThrough();
113     component.onChangeUpdatePolicyName("test1","test1");
114     expect(component.onChangeUpdatePolicyName).toHaveBeenCalledWith("test1","test1");
115   });
116
117   it('onChangeUpdateTimeUnit should return stubbed value', () => {
118     spyOn(component, 'onChangeUpdateTimeUnit').and.callThrough();
119     component.onChangeUpdateTimeUnit("HOURS","HOURS");
120     expect(component.onChangeUpdateTimeUnit).toHaveBeenCalledWith("HOURS","HOURS");
121   });
122   it('isDateValid should return stubbed value', () => {
123     spyOn(component, 'isDateValid').and.callThrough();
124     component.isDateValid("10/24/2020");
125     expect(component.isDateValid).toHaveBeenCalledWith("10/24/2020");
126   });
127   it('isStartDateValidFromToday should return stubbed value', () => {
128     spyOn(component, 'isStartDateValidFromToday').and.callThrough();
129     component.isStartDateValidFromToday("10/24/2020");
130     expect(component.isStartDateValidFromToday).toHaveBeenCalledWith("10/24/2020");
131     component.isStartDateValidFromToday("10/24/2021");
132     expect(component.isStartDateValidFromToday).toHaveBeenCalledWith("10/24/2021");
133   });
134
135   it('isToDateGreaterFromDate should return stubbed value', () => {
136     spyOn(component, 'isToDateGreaterFromDate').and.callThrough();
137     component.isToDateGreaterFromDate('10/24/2020','10/24/2021');
138     expect(component.isToDateGreaterFromDate).toHaveBeenCalledWith('10/24/2020','10/24/2021');
139     component.isToDateGreaterFromDate('10/24/2021','10/24/2020');
140     expect(component.isToDateGreaterFromDate).toHaveBeenCalledWith('10/24/2021','10/24/2020');
141   });
142
143   it('submit should return stubbed value', () => {
144     spyOn(component, 'submit').and.callThrough();
145     component.timeSlots = [{"startTime":"10/24/2021"}];
146     component.submit();
147     expect(component.submit).toHaveBeenCalledWith();
148   });
149
150   it('reject should return stubbed value', () => {
151     spyOn(component, 'reject').and.callThrough();
152     component.timeSlots = [{"startTime":"10/24/2021"}];
153     component.reject();
154     expect(component.reject).toHaveBeenCalledWith();
155   });
156
157   // it('sendSchedulerReq should return stubbed value', () => {
158   //   spyOn(component, 'sendSchedulerReq').and.callThrough();
159   //   component.timeSlots = [{"startTime":"10/24/2021"}];
160   //   component.sendSchedulerReq();
161   //   expect(component.sendSchedulerReq).toHaveBeenCalledWith();
162   // });
163   it('seviceCallToGetTimeSlots should return stubbed value', () => {
164     spyOn(component, 'seviceCallToGetTimeSlots').and.callThrough();
165     component.seviceCallToGetTimeSlots();
166     expect(component.seviceCallToGetTimeSlots).toHaveBeenCalledWith();
167   });
168
169   it('getPolicy should return stubbed value', () => {
170     spyOn(component, 'getPolicy').and.callThrough();
171     component.getPolicy();
172     expect(component.getPolicy).toHaveBeenCalledWith();
173   });
174
175   it('parseErrorMsg should return stubbed value', () => {
176     const response ={"entity":{"requestError":{"text":"EmptyTest"}}};
177     spyOn(component, 'parseErrorMsg').and.callThrough();
178     component.parseErrorMsg(response,"TestMethod");
179     expect(component.parseErrorMsg).toHaveBeenCalledWith(response,"TestMethod");
180   });
181
182   it('extractChangeManagementCallbackDataStr should return stubbed value', () => {
183     let response ={"workflow":"Update","vnfNames":[
184       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]},
185       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]}]};
186     spyOn(component, 'extractChangeManagementCallbackDataStr').and.callThrough();
187
188     component.extractChangeManagementCallbackDataStr(response);
189     expect(component.extractChangeManagementCallbackDataStr).toHaveBeenCalledWith(response);
190        response ={"workflow":"Replace","vnfNames":[
191       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]},
192       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]}]};
193     component.extractChangeManagementCallbackDataStr(response);
194     expect(component.extractChangeManagementCallbackDataStr).toHaveBeenCalledWith(response);
195     response ={"workflow":"VNF In Place Software Update","vnfNames":[
196       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]},
197       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]}]};
198     component.extractChangeManagementCallbackDataStr(response);
199     expect(component.extractChangeManagementCallbackDataStr).toHaveBeenCalledWith(response);
200     response ={"workflow":"VNF Config Update","vnfNames":[
201       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]},
202       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]}]};
203     component.extractChangeManagementCallbackDataStr(response);
204     expect(component.extractChangeManagementCallbackDataStr).toHaveBeenCalledWith(response);
205
206     response ={"workflow":"VNF In Place Software Update","vnfNames":[
207       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]},
208       {"availableVersions":[{"requestInfo":{"source":"URL","suppressRollback":"suppressRollback","requestorId":"requestorId"},"requestParameters":{"usePreload":2}}]}]};
209     component.extractChangeManagementCallbackDataStr(response);
210     expect(component.extractChangeManagementCallbackDataStr).toHaveBeenCalledWith(response);
211   });
212   it('formValidation should return stubbed value', () => {
213     spyOn(component, 'formValidation').and.callThrough();
214     component.formValidation();
215     expect(component.formValidation).toHaveBeenCalledWith();
216   });
217
218   it('convertToSecs should return stubbed value', () => {
219     spyOn(component, 'convertToSecs').and.callThrough();
220     component.convertToSecs(200);
221     expect(component.convertToSecs).toHaveBeenCalledWith(200);
222   });
223
224   it('stopPoll should return stubbed value', () => {
225     spyOn(component, 'stopPoll').and.callThrough();
226     component.stopPoll();
227     expect(component.stopPoll).toHaveBeenCalledWith();
228   });
229
230   it('getVnfData should return stubbed value', () => {
231     spyOn(component, 'getVnfData').and.callThrough();
232     component.getVnfData([{"name":"testName"}]);
233     expect(component.getVnfData).toHaveBeenCalledWith([{"name":"testName"}]);
234   });
235
236   it('openConfirmationModal should return stubbed value', () => {
237     spyOn(component, 'openConfirmationModal').and.callThrough();
238     component.openConfirmationModal("Test1","Test1");
239     expect(component.openConfirmationModal).toHaveBeenCalledWith("Test1","Test1");
240   });
241
242   it('openInformationModal should return stubbed value', () => {
243     spyOn(component, 'openInformationModal').and.callThrough();
244     component.openInformationModal("Test1","Test1");
245     expect(component.openInformationModal).toHaveBeenCalledWith("Test1","Test1");
246   });
247
248   
249
250   
251   
252
253   
254   
255   
256   
257 });