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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ToastrModule } from 'ngx-toastr';
import { ConfigFormModel } from '~/app/shared/components/config-option/config-option.model';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { ConfigurationFormComponent } from './configuration-form.component';
describe('ConfigurationFormComponent', () => {
let component: ConfigurationFormComponent;
let fixture: ComponentFixture<ConfigurationFormComponent>;
configureTestBed({
imports: [
HttpClientTestingModule,
ReactiveFormsModule,
RouterTestingModule,
ToastrModule.forRoot(),
SharedModule
],
declarations: [ConfigurationFormComponent],
providers: [
{
provide: ActivatedRoute
}
]
});
beforeEach(() => {
fixture = TestBed.createComponent(ConfigurationFormComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('getValidators', () => {
it('should return a validator for types float, addr and uuid', () => {
const types = ['float', 'addr', 'uuid'];
types.forEach((valType) => {
const configOption = new ConfigFormModel();
configOption.type = valType;
const ret = component.getValidators(configOption);
expect(ret).toBeTruthy();
expect(ret.length).toBe(1);
});
});
it('should not return a validator for types str and bool', () => {
const types = ['str', 'bool'];
types.forEach((valType) => {
const configOption = new ConfigFormModel();
configOption.type = valType;
const ret = component.getValidators(configOption);
expect(ret).toBeUndefined();
});
});
it('should return a pattern and a min validator', () => {
const configOption = new ConfigFormModel();
configOption.type = 'int';
configOption.min = 2;
const ret = component.getValidators(configOption);
expect(ret).toBeTruthy();
expect(ret.length).toBe(2);
expect(component.minValue).toBe(2);
expect(component.maxValue).toBeUndefined();
});
it('should return a pattern and a max validator', () => {
const configOption = new ConfigFormModel();
configOption.type = 'int';
configOption.max = 5;
const ret = component.getValidators(configOption);
expect(ret).toBeTruthy();
expect(ret.length).toBe(2);
expect(component.minValue).toBeUndefined();
expect(component.maxValue).toBe(5);
});
it('should return multiple validators', () => {
const configOption = new ConfigFormModel();
configOption.type = 'float';
configOption.max = 5.2;
configOption.min = 1.5;
const ret = component.getValidators(configOption);
expect(ret).toBeTruthy();
expect(ret.length).toBe(3);
expect(component.minValue).toBe(1.5);
expect(component.maxValue).toBe(5.2);
});
});
});
|