2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
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';
50 describe('SchedulerComponent', () => {
51 let component: SchedulerComponent;
52 let fixture: ComponentFixture<SchedulerComponent>;
53 const payload: any = {"widgetData":"widgetTestData"};
54 const policy = ["test1","test2","test3"];
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] } })
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 = {
77 component.schedulerObj.schedulingInfo = {
78 normalDurationInSeconds: '',
79 additionalDurationInSeconds: '',
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();
100 it('should create', () => {
101 expect(component).toBeTruthy();
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();
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");
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");
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");
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");
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');
143 it('submit should return stubbed value', () => {
144 spyOn(component, 'submit').and.callThrough();
145 component.timeSlots = [{"startTime":"10/24/2021"}];
147 expect(component.submit).toHaveBeenCalledWith();
150 it('reject should return stubbed value', () => {
151 spyOn(component, 'reject').and.callThrough();
152 component.timeSlots = [{"startTime":"10/24/2021"}];
154 expect(component.reject).toHaveBeenCalledWith();
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();
163 it('seviceCallToGetTimeSlots should return stubbed value', () => {
164 spyOn(component, 'seviceCallToGetTimeSlots').and.callThrough();
165 component.seviceCallToGetTimeSlots();
166 expect(component.seviceCallToGetTimeSlots).toHaveBeenCalledWith();
169 it('getPolicy should return stubbed value', () => {
170 spyOn(component, 'getPolicy').and.callThrough();
171 component.getPolicy();
172 expect(component.getPolicy).toHaveBeenCalledWith();
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");
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();
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);
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);
212 it('formValidation should return stubbed value', () => {
213 spyOn(component, 'formValidation').and.callThrough();
214 component.formValidation();
215 expect(component.formValidation).toHaveBeenCalledWith();
218 it('convertToSecs should return stubbed value', () => {
219 spyOn(component, 'convertToSecs').and.callThrough();
220 component.convertToSecs(200);
221 expect(component.convertToSecs).toHaveBeenCalledWith(200);
224 it('stopPoll should return stubbed value', () => {
225 spyOn(component, 'stopPoll').and.callThrough();
226 component.stopPoll();
227 expect(component.stopPoll).toHaveBeenCalledWith();
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"}]);
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");
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");