ecce68daf6cd929001d95de051047fbaecd325ef
[vid.git] / vid-webpack-master / src / app / shared / components / auditInfoModal / auditInfoModal.component.spec.ts
1 import {ComponentFixture, TestBed} from '@angular/core/testing';
2 import {ContextMenuModule, ContextMenuService} from 'ngx-contextmenu';
3 import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
4 import {AuditInfoModalComponent} from "./auditInfoModal.component";
5 import {NgRedux} from "@angular-redux/store";
6 import {FeatureFlagsService} from "../../services/featureFlag/feature-flags.service";
7 import {AaiService} from "../../services/aaiService/aai.service";
8 import {HttpClientTestingModule} from "@angular/common/http/testing";
9 import {ScrollToModule} from "@nicky-lenaers/ngx-scroll-to";
10 import {RouterTestingModule} from "@angular/router/testing";
11 import {ModalModule} from "ngx-bootstrap";
12 import {CapitalizeAndFormatPipe} from "../../pipes/capitalize/capitalize-and-format.pipe";
13 import {ServiceInfoService} from "../../server/serviceInfo/serviceInfo.service";
14 import {IframeService} from "../../utils/iframe.service";
15 import {AuditInfoModalComponentService} from "./auditInfoModal.component.service";
16 import {ServiceInfoModel} from "../../server/serviceInfo/serviceInfo.model";
17 import {HttpClient} from '@angular/common/http';
18 import {getTestBed} from "@angular/core/testing";
19 import {of} from 'rxjs';
20
21 class MockAppStore<T> {
22   getState() {
23     return {
24       global: {
25         flags: {
26           'FLAG_1902_NEW_VIEW_EDIT': true
27         }
28       },
29       service: {
30         serviceInstance: {}
31       }
32     }
33   }
34
35   dispatch() {
36
37   }
38 }
39
40
41 describe('Audit Info Modal Component_serviceInfoService', () => {
42   let component: AuditInfoModalComponent;
43   let fixture: ComponentFixture<AuditInfoModalComponent>;
44   let _serviceInfoService: ServiceInfoService;
45   let injector;
46   beforeAll(done => (async () => {
47
48     TestBed.configureTestingModule({
49       imports: [
50         HttpClientTestingModule,
51         ContextMenuModule,
52         ScrollToModule.forRoot(),
53         RouterTestingModule,
54         ModalModule.forRoot()
55       ],
56       providers: [
57         ServiceInfoService,
58         AaiService,
59         IframeService,
60         AuditInfoModalComponentService,
61         ContextMenuService,
62         FeatureFlagsService,
63         {provide: NgRedux, useClass: MockAppStore}
64       ],
65       declarations: [AuditInfoModalComponent, CapitalizeAndFormatPipe],
66       schemas: [CUSTOM_ELEMENTS_SCHEMA]
67     });
68     await TestBed.compileComponents();
69
70     injector = getTestBed();
71     _serviceInfoService = injector.get(ServiceInfoService);
72     fixture = TestBed.createComponent(AuditInfoModalComponent);
73     component = fixture.componentInstance;
74     fixture.detectChanges();
75   })().then(done).catch(done.fail));
76
77
78   test('component should be defined', () => {
79     expect(component).toBeDefined();
80   });
81
82   test('setModalTitles should set modal title according to type', () => {
83     component.setModalTitles('VNF');
84     expect(component.type).toEqual('VNF');
85     expect(component.title).toEqual('VNF Instantiation Information');
86   });
87
88   test('initializeProperties should init some component properties', () => {
89     component.initializeProperties();
90     expect(component.modelInfoItems).toBeNull();
91     expect(component.vidInfoData).toEqual([]);
92     expect(component.msoInfoData).toEqual([]);
93     expect(component.isLoading).toEqual(true);
94   });
95
96   test('openAuditInfoModal', () => {
97     const jobData: ServiceInfoModel = new ServiceInfoModel();
98     spyOn(AuditInfoModalComponentService, 'createModelInformationItemsJob');
99     spyOn(component, 'initAuditInfoData');
100     spyOn(component.auditInfoModal, 'show');
101     component.openAuditInfoModal(jobData);
102
103     expect(AuditInfoModalComponentService.createModelInformationItemsJob).toHaveBeenCalledWith(jobData);
104     expect(component.initAuditInfoData).toHaveBeenCalledWith(jobData);
105     expect(component.auditInfoModal.show).toHaveBeenCalled();
106   });
107
108   test('onCancelClick', () => {
109     spyOn(component, 'initializeProperties');
110     spyOn(component.auditInfoModal, 'hide');
111     component.onCancelClick();
112
113     expect(component.initializeProperties).toHaveBeenCalledWith();
114     expect(component.auditInfoModal.hide).toHaveBeenCalled();
115   });
116
117   test('openInstanceAuditInfoModal calls to getAuditStatusForRetry function', () => {
118     spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
119     spyOn(component, 'initializeProperties');
120     spyOn(component, 'setModalTitles');
121     spyOn(component.auditInfoModal, 'show');
122     spyOn(_serviceInfoService, 'getAuditStatusForRetry');
123     jest.spyOn(_serviceInfoService, 'getAuditStatusForRetry').mockReturnValue(of([]))
124
125     spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
126     const instanceId: string = "instanceID";
127     const type: string = 'VNF';
128     const model = {};
129     const instance = {};
130     const isInstanceFailed: boolean = true;
131     const trackById = "trackById";
132
133     AuditInfoModalComponent.openInstanceAuditInfoModal.next({
134       instanceId: instanceId,
135       type: type,
136       model: model,
137       instance: instance,
138       isInstanceFailed: isInstanceFailed,
139       trackById: trackById
140     });
141
142     expect(component.showVidStatus).toEqual(false);
143     expect(component.initializeProperties).toHaveBeenCalled();
144     expect(component.setModalTitles).toHaveBeenCalled();
145     expect(_serviceInfoService.getAuditStatusForRetry).toHaveBeenCalledWith(trackById);
146     expect(component.auditInfoModal.show).toHaveBeenCalled();
147     expect(AuditInfoModalComponentService.getInstanceModelName).toHaveBeenCalledWith(model);
148   });
149
150   test('openInstanceAuditInfoModal calls to getInstanceAuditStatus function', () => {
151     spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
152     spyOn(component, 'initializeProperties');
153     spyOn(component, 'setModalTitles');
154     spyOn(component.auditInfoModal, 'show');
155     spyOn(_serviceInfoService, 'getAuditStatusForRetry');
156     jest.spyOn(_serviceInfoService, 'getInstanceAuditStatus').mockReturnValue(of([]))
157
158     spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
159     const instanceId: string = "instanceID";
160     const type: string = 'VNF';
161     const model = {};
162     const instance = {};
163     const isInstanceFailed: boolean = false;
164     const trackById = "trackById";
165
166     AuditInfoModalComponent.openInstanceAuditInfoModal.next({
167       instanceId: instanceId,
168       type: type,
169       model: model,
170       instance: instance,
171       isInstanceFailed: isInstanceFailed,
172       trackById: trackById
173     });
174
175     expect(component.showVidStatus).toEqual(false);
176     expect(component.initializeProperties).toHaveBeenCalled();
177     expect(component.setModalTitles).toHaveBeenCalled();
178     expect(_serviceInfoService.getInstanceAuditStatus).toHaveBeenCalledWith(instanceId, type);
179     expect(component.auditInfoModal.show).toHaveBeenCalled();
180     expect(AuditInfoModalComponentService.getInstanceModelName).toHaveBeenCalledWith(model);
181   });
182
183   test('openInstanceAuditInfoModal : openModal : with job data', () => {
184     spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
185     spyOn(component, 'initializeProperties');
186     spyOn(component.auditInfoModal, 'show');
187     spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
188     const jobData: ServiceInfoModel = new ServiceInfoModel();
189     jobData.aLaCarte = true;
190     AuditInfoModalComponent.openModal.next(jobData);
191
192     expect(component.showVidStatus).toEqual(true);
193     expect(component.initializeProperties).toHaveBeenCalled();
194     expect(component.auditInfoModal.show).toHaveBeenCalled();
195   });
196
197   test('openInstanceAuditInfoModal : openModal : without job data', () => {
198     spyOn(component.auditInfoModal, 'hide');
199     const jobData: ServiceInfoModel = null;
200     AuditInfoModalComponent.openModal.next(jobData);
201     expect(component.auditInfoModal.hide).toHaveBeenCalled();
202   });
203 });