]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
23fab84ccc0f7e85de33486e0dc9b1c328b63943
[ceph.git] /
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';
6
7 import { ToastrModule } from 'ngx-toastr';
8
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';
13
14 describe('ConfigurationFormComponent', () => {
15   let component: ConfigurationFormComponent;
16   let fixture: ComponentFixture<ConfigurationFormComponent>;
17
18   configureTestBed({
19     imports: [
20       HttpClientTestingModule,
21       ReactiveFormsModule,
22       RouterTestingModule,
23       ToastrModule.forRoot(),
24       SharedModule
25     ],
26     declarations: [ConfigurationFormComponent],
27     providers: [
28       {
29         provide: ActivatedRoute
30       }
31     ]
32   });
33
34   beforeEach(() => {
35     fixture = TestBed.createComponent(ConfigurationFormComponent);
36     component = fixture.componentInstance;
37   });
38
39   it('should create', () => {
40     expect(component).toBeTruthy();
41   });
42
43   describe('getValidators', () => {
44     it('should return a validator for types float, addr and uuid', () => {
45       const types = ['float', 'addr', 'uuid'];
46
47       types.forEach((valType) => {
48         const configOption = new ConfigFormModel();
49         configOption.type = valType;
50
51         const ret = component.getValidators(configOption);
52         expect(ret).toBeTruthy();
53         expect(ret.length).toBe(1);
54       });
55     });
56
57     it('should not return a validator for types str and bool', () => {
58       const types = ['str', 'bool'];
59
60       types.forEach((valType) => {
61         const configOption = new ConfigFormModel();
62         configOption.type = valType;
63
64         const ret = component.getValidators(configOption);
65         expect(ret).toBeUndefined();
66       });
67     });
68
69     it('should return a pattern and a min validator', () => {
70       const configOption = new ConfigFormModel();
71       configOption.type = 'int';
72       configOption.min = 2;
73
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();
79     });
80
81     it('should return a pattern and a max validator', () => {
82       const configOption = new ConfigFormModel();
83       configOption.type = 'int';
84       configOption.max = 5;
85
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);
91     });
92
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;
98
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);
104     });
105   });
106 });