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';
21 class MockAppStore<T> {
26 'FLAG_1902_NEW_VIEW_EDIT': true
41 describe('Audit Info Modal Component_serviceInfoService', () => {
42 let component: AuditInfoModalComponent;
43 let fixture: ComponentFixture<AuditInfoModalComponent>;
44 let _serviceInfoService: ServiceInfoService;
46 beforeAll(done => (async () => {
48 TestBed.configureTestingModule({
50 HttpClientTestingModule,
52 ScrollToModule.forRoot(),
60 AuditInfoModalComponentService,
63 {provide: NgRedux, useClass: MockAppStore}
65 declarations: [AuditInfoModalComponent, CapitalizeAndFormatPipe],
66 schemas: [CUSTOM_ELEMENTS_SCHEMA]
68 await TestBed.compileComponents();
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));
78 test('component should be defined', () => {
79 expect(component).toBeDefined();
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');
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);
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);
103 expect(AuditInfoModalComponentService.createModelInformationItemsJob).toHaveBeenCalledWith(jobData);
104 expect(component.initAuditInfoData).toHaveBeenCalledWith(jobData);
105 expect(component.auditInfoModal.show).toHaveBeenCalled();
108 test('onCancelClick', () => {
109 spyOn(component, 'initializeProperties');
110 spyOn(component.auditInfoModal, 'hide');
111 component.onCancelClick();
113 expect(component.initializeProperties).toHaveBeenCalledWith();
114 expect(component.auditInfoModal.hide).toHaveBeenCalled();
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([]))
125 spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
126 const instanceId: string = "instanceID";
127 const type: string = 'VNF';
130 const isInstanceFailed: boolean = true;
131 const trackById = "trackById";
133 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
134 instanceId: instanceId,
138 isInstanceFailed: isInstanceFailed,
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);
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([]))
158 spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
159 const instanceId: string = "instanceID";
160 const type: string = 'VNF';
163 const isInstanceFailed: boolean = false;
164 const trackById = "trackById";
166 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
167 instanceId: instanceId,
171 isInstanceFailed: isInstanceFailed,
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);
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);
192 expect(component.showVidStatus).toEqual(true);
193 expect(component.initializeProperties).toHaveBeenCalled();
194 expect(component.auditInfoModal.show).toHaveBeenCalled();
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();