]> 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
update sources to ceph Nautilus 14.2.1
[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
7import { ToastModule } from 'ng2-toastr';
8
9import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
10import { SharedModule } from '../../../../shared/shared.module';
11import { ConfigurationFormComponent } from './configuration-form.component';
12import { ConfigFormModel } from './configuration-form.model';
13
14describe('ConfigurationFormComponent', () => {
15 let component: ConfigurationFormComponent;
16 let fixture: ComponentFixture<ConfigurationFormComponent>;
17
18 configureTestBed({
19 imports: [
20 HttpClientTestingModule,
21 ReactiveFormsModule,
22 RouterTestingModule,
23 ToastModule.forRoot(),
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 });
107
108 describe('getStep', () => {
109 it('should return the correct step for type uint and value 0', () => {
110 const ret = component.getStep('uint', 0);
111 expect(ret).toBe(1);
112 });
113
114 it('should return the correct step for type int and value 1', () => {
115 const ret = component.getStep('int', 1);
116 expect(ret).toBe(1);
117 });
118
119 it('should return the correct step for type int and value null', () => {
120 const ret = component.getStep('int', null);
121 expect(ret).toBe(1);
122 });
123
124 it('should return the correct step for type size and value 2', () => {
125 const ret = component.getStep('size', 2);
126 expect(ret).toBe(1);
127 });
128
129 it('should return the correct step for type secs and value 3', () => {
130 const ret = component.getStep('secs', 3);
131 expect(ret).toBe(1);
132 });
133
134 it('should return the correct step for type float and value 1', () => {
135 const ret = component.getStep('float', 1);
136 expect(ret).toBe(0.1);
137 });
138
139 it('should return the correct step for type float and value 0.1', () => {
140 const ret = component.getStep('float', 0.1);
141 expect(ret).toBe(0.1);
142 });
143
144 it('should return the correct step for type float and value 0.02', () => {
145 const ret = component.getStep('float', 0.02);
146 expect(ret).toBe(0.01);
147 });
148
149 it('should return the correct step for type float and value 0.003', () => {
150 const ret = component.getStep('float', 0.003);
151 expect(ret).toBe(0.001);
152 });
153
154 it('should return the correct step for type float and value null', () => {
155 const ret = component.getStep('float', null);
156 expect(ret).toBe(0.1);
157 });
158
159 it('should return undefined for unknown type', () => {
160 const ret = component.getStep('unknown', 1);
161 expect(ret).toBeUndefined();
162 });
163 });
164});