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 { ConfigFormModel } from '~/app/shared/components/config-option/config-option.model';
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { configureTestBed } from '~/testing/unit-test-helper';
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
35 fixture = TestBed.createComponent(ConfigurationFormComponent);
36 component = fixture.componentInstance;
39 it('should create', () => {
40 expect(component).toBeTruthy();
43 describe('getValidators', () => {
44 it('should return a validator for types float, addr and uuid', () => {
45 const types = ['float', 'addr', 'uuid'];
47 types.forEach((valType) => {
48 const configOption = new ConfigFormModel();
49 configOption.type = valType;
51 const ret = component.getValidators(configOption);
52 expect(ret).toBeTruthy();
53 expect(ret.length).toBe(1);
57 it('should not return a validator for types str and bool', () => {
58 const types = ['str', 'bool'];
60 types.forEach((valType) => {
61 const configOption = new ConfigFormModel();
62 configOption.type = valType;
64 const ret = component.getValidators(configOption);
65 expect(ret).toBeUndefined();
69 it('should return a pattern and a min validator', () => {
70 const configOption = new ConfigFormModel();
71 configOption.type = 'int';
74 const ret = component.getValidators(configOption);
75 expect(ret).toBeTruthy();
76 expect(ret.length).toBe(2);
77 expect(component.minValue).toBe(2);
78 expect(component.maxValue).toBeUndefined();
81 it('should return a pattern and a max validator', () => {
82 const configOption = new ConfigFormModel();
83 configOption.type = 'int';
86 const ret = component.getValidators(configOption);
87 expect(ret).toBeTruthy();
88 expect(ret.length).toBe(2);
89 expect(component.minValue).toBeUndefined();
90 expect(component.maxValue).toBe(5);
93 it('should return multiple validators', () => {
94 const configOption = new ConfigFormModel();
95 configOption.type = 'float';
96 configOption.max = 5.2;
97 configOption.min = 1.5;
99 const ret = component.getValidators(configOption);
100 expect(ret).toBeTruthy();
101 expect(ret.length).toBe(3);
102 expect(component.minValue).toBe(1.5);
103 expect(component.maxValue).toBe(5.2);