1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
6 import { ToastrModule } from 'ngx-toastr';
8 import { ConfigFormModel } from '~/app/shared/components/config-option/config-option.model';
9 import { SharedModule } from '~/app/shared/shared.module';
10 import { configureTestBed } from '~/testing/unit-test-helper';
11 import { ConfigurationFormComponent } from './configuration-form.component';
13 describe('ConfigurationFormComponent', () => {
14 let component: ConfigurationFormComponent;
15 let fixture: ComponentFixture<ConfigurationFormComponent>;
19 HttpClientTestingModule,
22 ToastrModule.forRoot(),
25 declarations: [ConfigurationFormComponent]
29 fixture = TestBed.createComponent(ConfigurationFormComponent);
30 component = fixture.componentInstance;
33 it('should create', () => {
34 expect(component).toBeTruthy();
37 describe('getValidators', () => {
38 it('should return a validator for types float, addr and uuid', () => {
39 const types = ['float', 'addr', 'uuid'];
41 types.forEach((valType) => {
42 const configOption = new ConfigFormModel();
43 configOption.type = valType;
45 const ret = component.getValidators(configOption);
46 expect(ret).toBeTruthy();
47 expect(ret.length).toBe(1);
51 it('should not return a validator for types str and bool', () => {
52 const types = ['str', 'bool'];
54 types.forEach((valType) => {
55 const configOption = new ConfigFormModel();
56 configOption.type = valType;
58 const ret = component.getValidators(configOption);
59 expect(ret).toBeUndefined();
63 it('should return a pattern and a min validator', () => {
64 const configOption = new ConfigFormModel();
65 configOption.type = 'int';
68 const ret = component.getValidators(configOption);
69 expect(ret).toBeTruthy();
70 expect(ret.length).toBe(2);
71 expect(component.minValue).toBe(2);
72 expect(component.maxValue).toBeUndefined();
75 it('should return a pattern and a max validator', () => {
76 const configOption = new ConfigFormModel();
77 configOption.type = 'int';
80 const ret = component.getValidators(configOption);
81 expect(ret).toBeTruthy();
82 expect(ret.length).toBe(2);
83 expect(component.minValue).toBeUndefined();
84 expect(component.maxValue).toBe(5);
87 it('should return multiple validators', () => {
88 const configOption = new ConfigFormModel();
89 configOption.type = 'float';
90 configOption.max = 5.2;
91 configOption.min = 1.5;
93 const ret = component.getValidators(configOption);
94 expect(ret).toBeTruthy();
95 expect(ret.length).toBe(3);
96 expect(component.minValue).toBe(1.5);
97 expect(component.maxValue).toBe(5.2);