]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.spec.ts
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / configuration / configuration-form / configuration-form.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
4import { ActivatedRoute } from '@angular/router';
5import { RouterTestingModule } from '@angular/router/testing';
6
494da23a 7import { ToastrModule } from 'ngx-toastr';
11fdf7f2
TL
8
9import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
81eedcae 10import { ConfigFormModel } from '../../../../shared/components/config-option/config-option.model';
11fdf7f2
TL
11import { SharedModule } from '../../../../shared/shared.module';
12import { ConfigurationFormComponent } from './configuration-form.component';
11fdf7f2
TL
13
14describe('ConfigurationFormComponent', () => {
15 let component: ConfigurationFormComponent;
16 let fixture: ComponentFixture<ConfigurationFormComponent>;
17
18 configureTestBed({
19 imports: [
20 HttpClientTestingModule,
21 ReactiveFormsModule,
22 RouterTestingModule,
494da23a 23 ToastrModule.forRoot(),
11fdf7f2
TL
24 SharedModule
25 ],
26 declarations: [ConfigurationFormComponent],
27 providers: [
28 {
29 provide: ActivatedRoute
30 },
31 i18nProviders
32 ]
33 });
34
35 beforeEach(() => {
36 fixture = TestBed.createComponent(ConfigurationFormComponent);
37 component = fixture.componentInstance;
38 });
39
40 it('should create', () => {
41 expect(component).toBeTruthy();
42 });
43
44 describe('getValidators', () => {
45 it('should return a validator for types float, addr and uuid', () => {
46 const types = ['float', 'addr', 'uuid'];
47
48 types.forEach((valType) => {
49 const configOption = new ConfigFormModel();
50 configOption.type = valType;
51
52 const ret = component.getValidators(configOption);
53 expect(ret).toBeTruthy();
54 expect(ret.length).toBe(1);
55 });
56 });
57
58 it('should not return a validator for types str and bool', () => {
59 const types = ['str', 'bool'];
60
61 types.forEach((valType) => {
62 const configOption = new ConfigFormModel();
63 configOption.type = valType;
64
65 const ret = component.getValidators(configOption);
66 expect(ret).toBeUndefined();
67 });
68 });
69
70 it('should return a pattern and a min validator', () => {
71 const configOption = new ConfigFormModel();
72 configOption.type = 'int';
73 configOption.min = 2;
74
75 const ret = component.getValidators(configOption);
76 expect(ret).toBeTruthy();
77 expect(ret.length).toBe(2);
78 expect(component.minValue).toBe(2);
79 expect(component.maxValue).toBeUndefined();
80 });
81
82 it('should return a pattern and a max validator', () => {
83 const configOption = new ConfigFormModel();
84 configOption.type = 'int';
85 configOption.max = 5;
86
87 const ret = component.getValidators(configOption);
88 expect(ret).toBeTruthy();
89 expect(ret.length).toBe(2);
90 expect(component.minValue).toBeUndefined();
91 expect(component.maxValue).toBe(5);
92 });
93
94 it('should return multiple validators', () => {
95 const configOption = new ConfigFormModel();
96 configOption.type = 'float';
97 configOption.max = 5.2;
98 configOption.min = 1.5;
99
100 const ret = component.getValidators(configOption);
101 expect(ret).toBeTruthy();
102 expect(ret.length).toBe(3);
103 expect(component.minValue).toBe(1.5);
104 expect(component.maxValue).toBe(5.2);
105 });
106 });
11fdf7f2 107});