]> 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 ceph quincy 17.2.6
[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';
11fdf7f2
TL
4import { RouterTestingModule } from '@angular/router/testing';
5
494da23a 6import { ToastrModule } from 'ngx-toastr';
11fdf7f2 7
f67539c2
TL
8import { ConfigFormModel } from '~/app/shared/components/config-option/config-option.model';
9import { SharedModule } from '~/app/shared/shared.module';
10import { configureTestBed } from '~/testing/unit-test-helper';
11fdf7f2 11import { ConfigurationFormComponent } from './configuration-form.component';
11fdf7f2
TL
12
13describe('ConfigurationFormComponent', () => {
14 let component: ConfigurationFormComponent;
15 let fixture: ComponentFixture<ConfigurationFormComponent>;
16
17 configureTestBed({
18 imports: [
19 HttpClientTestingModule,
20 ReactiveFormsModule,
21 RouterTestingModule,
494da23a 22 ToastrModule.forRoot(),
11fdf7f2
TL
23 SharedModule
24 ],
39ae355f 25 declarations: [ConfigurationFormComponent]
11fdf7f2
TL
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 });
11fdf7f2 100});