1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { ActivatedRoute } from '@angular/router';
5 import { RouterTestingModule } from '@angular/router/testing';
7 import { ToastrModule } from 'ngx-toastr';
9 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
10 import { ConfigFormModel } from '../../../../shared/components/config-option/config-option.model';
11 import { SharedModule } from '../../../../shared/shared.module';
12 import { ConfigurationFormComponent } from './configuration-form.component';
14 describe('ConfigurationFormComponent', () => {
15 let component: ConfigurationFormComponent;
16 let fixture: ComponentFixture<ConfigurationFormComponent>;
20 HttpClientTestingModule,
23 ToastrModule.forRoot(),
26 declarations: [ConfigurationFormComponent],
29 provide: ActivatedRoute
36 fixture = TestBed.createComponent(ConfigurationFormComponent);
37 component = fixture.componentInstance;
40 it('should create', () => {
41 expect(component).toBeTruthy();
44 describe('getValidators', () => {
45 it('should return a validator for types float, addr and uuid', () => {
46 const types = ['float', 'addr', 'uuid'];
48 types.forEach((valType) => {
49 const configOption = new ConfigFormModel();
50 configOption.type = valType;
52 const ret = component.getValidators(configOption);
53 expect(ret).toBeTruthy();
54 expect(ret.length).toBe(1);
58 it('should not return a validator for types str and bool', () => {
59 const types = ['str', 'bool'];
61 types.forEach((valType) => {
62 const configOption = new ConfigFormModel();
63 configOption.type = valType;
65 const ret = component.getValidators(configOption);
66 expect(ret).toBeUndefined();
70 it('should return a pattern and a min validator', () => {
71 const configOption = new ConfigFormModel();
72 configOption.type = 'int';
75 const ret = component.getValidators(configOption);
76 expect(ret).toBeTruthy();
77 expect(ret.length).toBe(2);
78 expect(component.minValue).toBe(2);
79 expect(component.maxValue).toBeUndefined();
82 it('should return a pattern and a max validator', () => {
83 const configOption = new ConfigFormModel();
84 configOption.type = 'int';
87 const ret = component.getValidators(configOption);
88 expect(ret).toBeTruthy();
89 expect(ret.length).toBe(2);
90 expect(component.minValue).toBeUndefined();
91 expect(component.maxValue).toBe(5);
94 it('should return multiple validators', () => {
95 const configOption = new ConfigFormModel();
96 configOption.type = 'float';
97 configOption.max = 5.2;
98 configOption.min = 1.5;
100 const ret = component.getValidators(configOption);
101 expect(ret).toBeTruthy();
102 expect(ret.length).toBe(3);
103 expect(component.minValue).toBe(1.5);
104 expect(component.maxValue).toBe(5.2);