import {getTestBed, TestBed} from '@angular/core/testing';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {NgRedux} from '@angular-redux/store';
-import {BasicControlGenerator, SDN_C_PRE_LOAD} from "../basic.control.generator";
+import {ControlGeneratorUtil, SDN_C_PRE_LOAD} from "../control.generator.util.service";
import {AaiService} from "../../../../services/aaiService/aai.service";
import {GenericFormService} from "../../generic-form.service";
import {FormBuilder} from "@angular/forms";
ValidatorOptions
} from "../../../../models/formControlModels/formControl.model";
import {FormControlNames, VfModuleControlGenerator} from "./vfModule.control.generator";
-import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
+import {FeatureFlagsService, Features} from "../../../../services/featureFlag/feature-flags.service";
import {VfModuleInstance} from "../../../../models/vfModuleInstance";
import {VfModule} from "../../../../models/vfModule";
+import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
+import {AppState} from "../../../../store/reducers";
+import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service";
+import {instance, mock, when} from "ts-mockito";
+import each from "jest-each";
class MockAppStore<T> {
getState() {
"FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
"FLAG_SHOW_VERIFY_SERVICE": false,
"FLAG_SERVICE_MODEL_CACHE": true,
- "FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD": false,
"FLAG_ADD_MSO_TESTAPI_FIELD": true
},
"type": "[FLAGS] Update"
let injector;
let service: VfModuleControlGenerator;
let httpMock: HttpTestingController;
+ let store : NgRedux<AppState>;
+ let mockFeatureFlagsService: FeatureFlagsService = mock(FeatureFlagsService);
+
beforeAll(done => (async () => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [VfModuleControlGenerator,
GenericFormService,
- BasicControlGenerator,
+ SharedControllersService,
+ ControlGeneratorUtil,
AaiService,
FormBuilder,
LogService,
- {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
+ SharedTreeService,
+ {provide: FeatureFlagsService, useValue: instance(mockFeatureFlagsService)},
{provide: NgRedux, useClass: MockAppStore}]
});
await TestBed.compileComponents();
injector = getTestBed();
service = injector.get(VfModuleControlGenerator);
httpMock = injector.get(HttpTestingController);
+ store = injector.get(NgRedux);
jest.spyOn(console, 'error');
})().then(done).catch(done.fail));
+ let formControlsWithoutLcpRegionTenantLegacy : string[] =
+ [FormControlNames.INSTANCE_NAME,
+ FormControlNames.VOLUME_GROUP_NAME,
+ FormControlNames.ROLLBACK_ON_FAILURE,
+ SDN_C_PRE_LOAD,];
+
+ let formControlsWithLcpRegionTenantLegacy : string[] =
+ [FormControlNames.INSTANCE_NAME,
+ FormControlNames.VOLUME_GROUP_NAME,
+ FormControlNames.LCPCLOUD_REGION_ID,
+ FormControlNames.LEGACY_REGION,
+ FormControlNames.TENANT_ID,
+ FormControlNames.ROLLBACK_ON_FAILURE,
+ SDN_C_PRE_LOAD,];
+
+
+
test(' getMacroFormControls gets vnfStoreKey === null', () => {
const serviceId: string = "6e59c5de-f052-46fa-aa7e-2fca9d674c44";
const vnfStoreKey: string = null;
expect(console.error).toHaveBeenCalled();
});
- test('getAlaCarteFormControls should return the correct order of controls', () => {
+ each([
+ [true, 5, formControlsWithoutLcpRegionTenantLegacy],
+ [false, 8,formControlsWithLcpRegionTenantLegacy]
+ ]).
+ test('getAlaCarteFormControls should return the correct order of controls', (flag: boolean, controlAmount: number, orderedControls: string[]) => {
+ when(mockFeatureFlagsService.getFlagState(Features.FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF)).thenReturn(flag);
const controls:FormControlModel[] = getAlaCarteFormControls();
- const orderedControls : string[] = [
- FormControlNames.INSTANCE_NAME,
- FormControlNames.VOLUME_GROUP_NAME,
- FormControlNames.LCPCLOUD_REGION_ID,
- FormControlNames.LEGACY_REGION,
- FormControlNames.TENANT_ID,
- FormControlNames.ROLLBACK_ON_FAILURE,
- SDN_C_PRE_LOAD,
- ];
-
- expect(controls.length).toEqual(7);
+ expect(controls.length).toEqual(controlAmount);
for(let i = 0 ; i < orderedControls.length ; i++) {
expect(controls[i].controlName).toEqual(orderedControls[i]);
}
return controls;
}
- test('getAlaCarteFormControls responce with wrong order of controls', () => {
- const controls:FormControlModel[] = getAlaCarteFormControls();
-
- const orderedControls : string[] = [
- FormControlNames.INSTANCE_NAME,
- FormControlNames.VOLUME_GROUP_NAME,
- FormControlNames.LCPCLOUD_REGION_ID,
- FormControlNames.TENANT_ID, // TENANT_ID must be after LEGACY_REGION
- FormControlNames.LEGACY_REGION,
- FormControlNames.ROLLBACK_ON_FAILURE,
- SDN_C_PRE_LOAD,
- ];
-
- for(let i = 0 ; i < orderedControls.length ; i++) {
- if (controls[i].controlName === 'legacyRegion') {
- expect(orderedControls[i]).toEqual('tenantId');
- }
- }
- });
-
test('getMacroFormControls should return the correct order of controls', () => {
const serviceId: string = "6e59c5de-f052-46fa-aa7e-2fca9d674c44";
const vnfStoreKey: string = 'VF_vGeraldine 0';
expect(instanceNameValidator.validatorArg).toEqual(/^[a-zA-Z0-9._-]*$/);
});
- test(' getAlaCarteFormControls gets null service', () => {
- const controls:FormControlModel[] = getAlaCarteFormControls();
- expect(controls.length).toEqual(7);
- const orderedControls : string[] = [
- FormControlNames.INSTANCE_NAME,
- FormControlNames.VOLUME_GROUP_NAME,
- FormControlNames.LCPCLOUD_REGION_ID,
- FormControlNames.LEGACY_REGION,
- FormControlNames.TENANT_ID,
- FormControlNames.ROLLBACK_ON_FAILURE,
- SDN_C_PRE_LOAD,
- ];
+ test('when flag is active - response should contains upload file', ()=>{
+ spyOn(store, 'getState').and.returnValue( {
+ "global": {
+ "flags": {
+ "FLAG_2006_VFM_SDNC_PRELOAD_FILES" : true
+ }
+ }
+ });
+
+ const extraContent = service.getSdncExtraContents();
+ console.log("extraContent", extraContent);
+ const uploadFileData = <any>extraContent[0];
+
+ expect(uploadFileData.type).toEqual('UPLOAD_FILE');
+ expect(uploadFileData.dataTestId).toEqual('sdnc_pereload_upload_link');
+ expect(uploadFileData.uploadMethod).toBeDefined();
+ expect(uploadFileData.isDisabled).toBeDefined();
+ expect(uploadFileData.onSuccess).toBeDefined();
+ expect(uploadFileData.onFailed).toBeDefined();
+
+ })
- for(let i = 0 ; i < orderedControls.length ; i++) {
- expect(controls[i].controlName).toEqual(orderedControls[i]);
- }
- });
});