Merge from ecomp 718fd196 - Modern UI
[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 import {NodeInstance} from "../../models/nodeInstance";
21
22 class MockAppStore<T> {
23   getState() {
24     return {
25       global: {
26         flags: {
27           'FLAG_1902_NEW_VIEW_EDIT': true
28         }
29       },
30       service: {
31         serviceInstance: {}
32       }
33     }
34   }
35
36   dispatch() {
37
38   }
39 }
40
41
42 describe('Audit Info Modal Component_serviceInfoService', () => {
43   let component: AuditInfoModalComponent;
44   let fixture: ComponentFixture<AuditInfoModalComponent>;
45   let _serviceInfoService: ServiceInfoService;
46   let injector;
47   beforeAll(done => (async () => {
48
49     TestBed.configureTestingModule({
50       imports: [
51         HttpClientTestingModule,
52         ContextMenuModule,
53         ScrollToModule.forRoot(),
54         RouterTestingModule,
55         ModalModule.forRoot()
56       ],
57       providers: [
58         ServiceInfoService,
59         AaiService,
60         IframeService,
61         AuditInfoModalComponentService,
62         ContextMenuService,
63         FeatureFlagsService,
64         {provide: NgRedux, useClass: MockAppStore}
65       ],
66       declarations: [AuditInfoModalComponent, CapitalizeAndFormatPipe],
67       schemas: [CUSTOM_ELEMENTS_SCHEMA]
68     });
69     await TestBed.compileComponents();
70
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));
77
78
79   test('component should be defined', () => {
80     expect(component).toBeDefined();
81   });
82
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');
87   });
88
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);
95   });
96
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);
103
104     expect(AuditInfoModalComponentService.createModelInformationItemsJob).toHaveBeenCalledWith(jobData);
105     expect(component.initAuditInfoData).toHaveBeenCalledWith(jobData);
106     expect(component.auditInfoModal.show).toHaveBeenCalled();
107   });
108
109   test('onCancelClick', () => {
110     spyOn(component, 'initializeProperties');
111     spyOn(component.auditInfoModal, 'hide');
112     component.onCancelClick();
113
114     expect(component.initializeProperties).toHaveBeenCalledWith();
115     expect(component.auditInfoModal.hide).toHaveBeenCalled();
116   });
117
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([]))
125
126     spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
127     const instanceId: string = "instanceID";
128     const type: string = 'VNF';
129     const model = {};
130     const instance: NodeInstance = new NodeInstance();
131     instance.trackById = 'trackById';
132     instance.isFailed= true;
133
134     AuditInfoModalComponent.openInstanceAuditInfoModal.next({
135       instanceId: instanceId,
136       type: type,
137       model: model,
138       instance: instance
139     });
140
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);
147   });
148
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([]))
156
157     spyOn(AuditInfoModalComponentService, 'getInstanceModelName');
158     const instanceId: string = "instanceID";
159     const type: string = 'VNF';
160     const model = {};
161     const instance = {};
162
163     AuditInfoModalComponent.openInstanceAuditInfoModal.next({
164       instanceId: instanceId,
165       type: type,
166       model: model,
167       instance: instance
168     });
169
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);
176   });
177
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);
186
187     expect(component.showVidStatus).toEqual(true);
188     expect(component.initializeProperties).toHaveBeenCalled();
189     expect(component.auditInfoModal.show).toHaveBeenCalled();
190   });
191
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();
197   });
198 });