]>
Commit | Line | Data |
---|---|---|
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'; | |
5 | ||
6 | import { ToastrModule } from 'ngx-toastr'; | |
7 | ||
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'; | |
12 | ||
13 | describe('ConfigurationFormComponent', () => { | |
14 | let component: ConfigurationFormComponent; | |
15 | let fixture: ComponentFixture<ConfigurationFormComponent>; | |
16 | ||
17 | configureTestBed({ | |
18 | imports: [ | |
19 | HttpClientTestingModule, | |
20 | ReactiveFormsModule, | |
21 | RouterTestingModule, | |
22 | ToastrModule.forRoot(), | |
23 | SharedModule | |
24 | ], | |
25 | declarations: [ConfigurationFormComponent] | |
26 | }); | |
27 | ||
28 | beforeEach(() => { | |
29 | fixture = TestBed.createComponent(ConfigurationFormComponent); | |
30 | component = fixture.componentInstance; | |
31 | }); | |
32 | ||
33 | it('should create', () => { | |
34 | expect(component).toBeTruthy(); | |
35 | }); | |
36 | ||
37 | describe('getValidators', () => { | |
38 | it('should return a validator for types float, addr and uuid', () => { | |
39 | const types = ['float', 'addr', 'uuid']; | |
40 | ||
41 | types.forEach((valType) => { | |
42 | const configOption = new ConfigFormModel(); | |
43 | configOption.type = valType; | |
44 | ||
45 | const ret = component.getValidators(configOption); | |
46 | expect(ret).toBeTruthy(); | |
47 | expect(ret.length).toBe(1); | |
48 | }); | |
49 | }); | |
50 | ||
51 | it('should not return a validator for types str and bool', () => { | |
52 | const types = ['str', 'bool']; | |
53 | ||
54 | types.forEach((valType) => { | |
55 | const configOption = new ConfigFormModel(); | |
56 | configOption.type = valType; | |
57 | ||
58 | const ret = component.getValidators(configOption); | |
59 | expect(ret).toBeUndefined(); | |
60 | }); | |
61 | }); | |
62 | ||
63 | it('should return a pattern and a min validator', () => { | |
64 | const configOption = new ConfigFormModel(); | |
65 | configOption.type = 'int'; | |
66 | configOption.min = 2; | |
67 | ||
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(); | |
73 | }); | |
74 | ||
75 | it('should return a pattern and a max validator', () => { | |
76 | const configOption = new ConfigFormModel(); | |
77 | configOption.type = 'int'; | |
78 | configOption.max = 5; | |
79 | ||
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); | |
85 | }); | |
86 | ||
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; | |
92 | ||
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); | |
98 | }); | |
99 | }); | |
100 | }); |