aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts
blob: e97ed9ca33bbbf1e1902d13e0696c343d8f13372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {getTestBed, TestBed} from '@angular/core/testing';
import {AaiService} from "../../../services/aaiService/aai.service";
import {FormControlModel, ValidatorModel, ValidatorOptions} from "../../../models/formControlModels/formControl.model";
import {FeatureFlagsService} from "../../../services/featureFlag/feature-flags.service";
import {BasicControlGenerator} from "./basic.control.generator";
import {NgRedux} from '@angular-redux/store';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {FileFormControl} from "../../../models/formControlModels/fileFormControl.model";

class MockAppStore<T> {}

class MockFeatureFlagsService {}

describe('Basic Control Generator', () => {
  let injector;
  let service: BasicControlGenerator;
  let httpMock: HttpTestingController;


  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [BasicControlGenerator,
        AaiService,
        {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
        {provide: NgRedux, useClass: MockAppStore}]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    service = injector.get(BasicControlGenerator);
    httpMock = injector.get(HttpTestingController);

  })().then(done).catch(done.fail));


  test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
    const instance = {lcpCloudRegionId : 'AAIAIC25'};
    const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
    expect(legacyRegionControl.isVisible).toBeTruthy();
  });

  test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
    const instance = {lcpCloudRegionId : 'olson3'};
    const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
    expect(legacyRegionControl.isVisible).toBeFalsy();
  });

  test('given instance, get supp file from getSupplementaryFile ', () => {
    const instance = {};
    const suppFileForInstance: FileFormControl = service.getSupplementaryFile(instance);
    expect(suppFileForInstance.isVisible).toBeTruthy();
    expect(suppFileForInstance.hiddenFile.length).toBeGreaterThanOrEqual(1);
    expect(suppFileForInstance.hiddenFile[0].validations[0].validatorName).toEqual("isFileTooBig");
  });

  test('concatSupplementaryFile add SupplementaryFile control and hidden file', () => {

    //given
    const instance = {};
    const controls = [service.getLegacyRegion(instance)];
    expect(controls).toHaveLength(1);

    //when
    const result = service.concatSupplementaryFile(controls, instance);

    //then
    expect(controls).toHaveLength(1); //original controls remain the same

    expect(result.map((control) => {return control.controlName})).toEqual([
      "legacyRegion",
      "supplementaryFile",
      "supplementaryFile_hidden",
      "supplementaryFile_hidden_content"
    ]);
  });
});