1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {NgRedux} from '@angular-redux/store';
4 import {FormControlNames} from "../service.control.generator";
5 import {ControlGeneratorUtil} from "../control.generator.util.service";
6 import {AaiService} from "../../../../services/aaiService/aai.service";
7 import {GenericFormService} from "../../generic-form.service";
8 import {FormBuilder} from "@angular/forms";
9 import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
10 import {LogService} from "../../../../utils/log/log.service";
11 import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
12 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
13 import {PnfControlGenerator} from "./pnf.control.generator";
14 import {MockNgRedux} from "@angular-redux/store/testing";
16 class MockFeatureFlagsService {
19 class MockAppStore<T> {
24 "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
25 "FLAG_SHOW_ASSIGNMENTS": true,
26 "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
27 "FLAG_SHOW_VERIFY_SERVICE": false,
28 "FLAG_SERVICE_MODEL_CACHE": true,
29 "FLAG_ADD_MSO_TESTAPI_FIELD": true
52 describe('PNF Control Generator', () => {
54 let service: PnfControlGenerator;
55 let httpMock: HttpTestingController;
57 beforeAll(done => (async () => {
58 TestBed.configureTestingModule({
59 imports: [HttpClientTestingModule],
65 SharedControllersService,
69 {provide: FeatureFlagsService, useClass: MockFeatureFlagsService},
70 {provide: NgRedux, useClass: MockAppStore}]
72 await TestBed.compileComponents();
74 injector = getTestBed();
75 service = injector.get(PnfControlGenerator);
76 httpMock = injector.get(HttpTestingController);
78 })().then(done).catch(done.fail));
80 test('getMacroFormControls check for mandatory controls', () => {
81 const serviceId = "serviceId";
82 const pnfName = "pnfName";
83 const pnfStoreKey = "pnfStoreKey";
84 const mandatoryControls: string[] = [
85 FormControlNames.INSTANCE_NAME,
86 FormControlNames.PRODUCT_FAMILY_ID
89 const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
91 for (let i = 0; i < mandatoryControls.length; i++) {
92 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
93 expect(requiredExist).toBeDefined();
97 test('should provide empty array on getMacroFormControls when serviceId, pnfName and pnfStoreKey equals to null', () => {
98 let pnfStoreKey = null;
99 const serviceId = null;
100 const pnfName: string = null;
102 const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
104 expect(controls).toEqual([]);
107 test('getAlacartFormControls check for mandatory controls', () => {
108 const serviceId = "serviceId";
109 const pnfName = "pnfName";
110 const pnfStoreKey = "pnfStoreKey";
111 const mandatoryControls: string[] = [
112 FormControlNames.INSTANCE_NAME,
118 const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
120 for (let i = 0; i < mandatoryControls.length; i++) {
121 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
122 expect(requiredExist).toBeDefined();
126 test('should provide empty array on getAlaCarteFormControls when serviceId, pnfName and pnfStoreKey equals to null', () => {
127 let pnfStoreKey = null;
128 const serviceId = null;
129 const pnfName: string = null;
131 const result: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
133 expect(result).toEqual([]);
137 test('getMacroFormControls should return the correct order of controls', () => {
138 const serviceId = "serviceId";
139 const pnfName = "pnfName";
140 const pnfStoreKey = "pnfStoreKey";
141 const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
143 const controlsOrderNames = [
144 FormControlNames.INSTANCE_NAME,
145 FormControlNames.PRODUCT_FAMILY_ID,
149 expect(controls.length).toEqual(4);
150 for (let i = 0; i < controls.length; i++) {
151 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
155 test('getAlacarteFormControls should return the correct order of controls', () => {
156 const serviceId = "serviceId";
157 const pnfName = "pnfName";
158 const pnfStoreKey = "pnfStoreKey";
159 const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
161 const controlsOrderNames = [
162 FormControlNames.INSTANCE_NAME,
163 FormControlNames.PRODUCT_FAMILY_ID,
169 expect(controls.length).toEqual(5);
170 for (let i = 0; i < controls.length; i++) {
171 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);