Extend Modern UI for pnf usecase
[vid.git] / vid-webpack-master / src / app / shared / components / genericForm / formControlsServices / pnfGenerator / pnf.control.generator.spec.ts
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";
15
16 class MockFeatureFlagsService {
17 }
18
19 class MockAppStore<T> {
20   getState() {
21     return {
22       global: {
23         flags: {
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
30         }
31       },
32       service: {
33         serviceHierarchy: {
34           'serviceId': {
35             'pnfs': {
36               'pnfName': {}
37             }
38           }
39         },
40         serviceInstance: {
41           'serviceId': {
42             'pnfs': {
43               'pnfName': {}
44             }
45           }
46         }
47       }
48     }
49   }
50 }
51
52 describe('PNF Control Generator', () => {
53   let injector;
54   let service: PnfControlGenerator;
55   let httpMock: HttpTestingController;
56
57   beforeAll(done => (async () => {
58     TestBed.configureTestingModule({
59       imports: [HttpClientTestingModule],
60       providers: [
61         MockNgRedux,
62         PnfControlGenerator,
63         GenericFormService,
64         ControlGeneratorUtil,
65         SharedControllersService,
66         AaiService,
67         FormBuilder,
68         LogService,
69         {provide: FeatureFlagsService, useClass: MockFeatureFlagsService},
70         {provide: NgRedux, useClass: MockAppStore}]
71     });
72     await TestBed.compileComponents();
73
74     injector = getTestBed();
75     service = injector.get(PnfControlGenerator);
76     httpMock = injector.get(HttpTestingController);
77
78   })().then(done).catch(done.fail));
79
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
87     ];
88
89     const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
90
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();
94     }
95   });
96
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;
101
102     const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
103
104     expect(controls).toEqual([]);
105   });
106
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,
113       'platformName',
114       'lineOfBusiness',
115       'rollbackOnFailure'
116     ];
117
118     const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
119
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();
123     }
124   });
125
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;
130
131     const result: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
132
133     expect(result).toEqual([]);
134   });
135
136
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, []);
142
143     const controlsOrderNames = [
144       FormControlNames.INSTANCE_NAME,
145       FormControlNames.PRODUCT_FAMILY_ID,
146       'platformName',
147       'lineOfBusiness'];
148
149     expect(controls.length).toEqual(4);
150     for (let i = 0; i < controls.length; i++) {
151       expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
152     }
153   });
154
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, []);
160
161     const controlsOrderNames = [
162       FormControlNames.INSTANCE_NAME,
163       FormControlNames.PRODUCT_FAMILY_ID,
164       'platformName',
165       'lineOfBusiness',
166       'rollbackOnFailure'
167     ];
168
169     expect(controls.length).toEqual(5);
170     for (let i = 0; i < controls.length; i++) {
171       expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
172     }
173   });
174 });
175