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 import {NodeInstance} from "../../models/nodeInstance";
22 class MockAppStore<T> {
27 'FLAG_1902_NEW_VIEW_EDIT': true
42 describe('Audit Info Modal Component_serviceInfoService', () => {
43 let component: AuditInfoModalComponent;
44 let fixture: ComponentFixture<AuditInfoModalComponent>;
45 let _serviceInfoService: ServiceInfoService;
47 beforeAll(done => (async () => {
49 TestBed.configureTestingModule({
51 HttpClientTestingModule,
53 ScrollToModule.forRoot(),
61 AuditInfoModalComponentService,
64 {provide: NgRedux, useClass: MockAppStore}
66 declarations: [AuditInfoModalComponent, CapitalizeAndFormatPipe],
67 schemas: [CUSTOM_ELEMENTS_SCHEMA]
69 await TestBed.compileComponents();
71 injector = getTestBed();
72 _serviceInfoService = injector.get(ServiceInfoService);
73 fixture = TestBed.createComponent(AuditInfoModalComponent);
74 component = fixture.componentInstance;
75 fixture.detectChanges();
76 })().then(done).catch(done.fail));
79 test('component should be defined', () => {
80 expect(component).toBeDefined();
83 test('setModalTitles should set modal title according to type', () => {
84 component.setModalTitles('VNF');
85 expect(component.type).toEqual('VNF');
86 expect(component.title).toEqual('VNF Instantiation Information');
89 test('initializeProperties should init some component properties', () => {
90 component.initializeProperties();
91 expect(component.modelInfoItems).toBeNull();
92 expect(component.vidInfoData).toEqual([]);
93 expect(component.msoInfoData).toEqual([]);
94 expect(component.isLoading).toEqual(true);
97 test('openAuditInfoModal', () => {
98 const jobData: ServiceInfoModel = new ServiceInfoModel();
99 spyOn(AuditInfoModalComponentService, 'createModelInformationItemsJob');
100 spyOn(component, 'initAuditInfoData');
101 spyOn(component.auditInfoModal, 'show');
102 component.openAuditInfoModal(jobData);
104 expect(AuditInfoModalComponentService.createModelInformationItemsJob).toHaveBeenCalledWith(jobData);
105 expect(component.initAuditInfoData).toHaveBeenCalledWith(jobData);
106 expect(component.auditInfoModal.show).toHaveBeenCalled();
109 test('onCancelClick', () => {
110 spyOn(component, 'initializeProperties');
111 spyOn(component.auditInfoModal, 'hide');
112 component.onCancelClick();
114 expect(component.initializeProperties).toHaveBeenCalledWith();
115 expect(component.auditInfoModal.hide).toHaveBeenCalled();
118 test('openInstanceAuditInfoModal calls to getAuditStatusForRetry function', () => {
119 spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
120 spyOn(component, 'initializeProperties');
121 spyOn(component, 'setModalTitles');
122 spyOn(component.auditInfoModal, 'show');
123 spyOn(_serviceInfoService, 'getAuditStatusForRetry');
124 jest.spyOn(_serviceInfoService, 'getAuditStatusForRetry').mockReturnValue(of([]))
126 spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
127 const instanceId: string = "instanceID";
128 const type: string = 'VNF';
130 const instance: NodeInstance = new NodeInstance();
131 instance.trackById = 'trackById';
132 instance.isFailed= true;
134 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
135 instanceId: instanceId,
141 expect(component.showVidStatus).toEqual(false);
142 expect(component.initializeProperties).toHaveBeenCalled();
143 expect(component.setModalTitles).toHaveBeenCalled();
144 expect(_serviceInfoService.getAuditStatusForRetry).toHaveBeenCalledWith(instance.trackById);
145 expect(component.auditInfoModal.show).toHaveBeenCalled();
146 expect(AuditInfoModalComponentService.getInstanceModelName).toHaveBeenCalledWith(model);
149 test('openInstanceAuditInfoModal calls to getInstanceAuditStatus function', () => {
150 spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
151 spyOn(component, 'initializeProperties');
152 spyOn(component, 'setModalTitles');
153 spyOn(component.auditInfoModal, 'show');
154 spyOn(_serviceInfoService, 'getAuditStatusForRetry');
155 jest.spyOn(_serviceInfoService, 'getInstanceAuditStatus').mockReturnValue(of([]))
157 spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
158 const instanceId: string = "instanceID";
159 const type: string = 'VNF';
163 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
164 instanceId: instanceId,
170 expect(component.showVidStatus).toEqual(false);
171 expect(component.initializeProperties).toHaveBeenCalled();
172 expect(component.setModalTitles).toHaveBeenCalled();
173 expect(_serviceInfoService.getInstanceAuditStatus).toHaveBeenCalledWith(instanceId, type);
174 expect(component.auditInfoModal.show).toHaveBeenCalled();
175 expect(AuditInfoModalComponentService.getInstanceModelName).toHaveBeenCalledWith(model);
178 test('openInstanceAuditInfoModal : openModal : with job data', () => {
179 spyOn(component.auditInfoModalComponentService, 'getModelInfo').and.returnValue([]);
180 spyOn(component, 'initializeProperties');
181 spyOn(component.auditInfoModal, 'show');
182 spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
183 const jobData: ServiceInfoModel = new ServiceInfoModel();
184 jobData.aLaCarte = true;
185 AuditInfoModalComponent.openModal.next(jobData);
187 expect(component.showVidStatus).toEqual(true);
188 expect(component.initializeProperties).toHaveBeenCalled();
189 expect(component.auditInfoModal.show).toHaveBeenCalled();
192 test('openInstanceAuditInfoModal : openModal : without job data', () => {
193 spyOn(component.auditInfoModal, 'hide');
194 const jobData: ServiceInfoModel = null;
195 AuditInfoModalComponent.openModal.next(jobData);
196 expect(component.auditInfoModal.hide).toHaveBeenCalled();