]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/mgr-modules/mgr-module-form/mgr-module-form.component.spec.ts
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / mgr-modules / mgr-module-form / mgr-module-form.component.spec.ts
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 { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../../shared/shared.module';
10 import { MgrModuleFormComponent } from './mgr-module-form.component';
11
12 describe('MgrModuleFormComponent', () => {
13 let component: MgrModuleFormComponent;
14 let fixture: ComponentFixture<MgrModuleFormComponent>;
15
16 configureTestBed({
17 declarations: [MgrModuleFormComponent],
18 imports: [
19 HttpClientTestingModule,
20 ReactiveFormsModule,
21 RouterTestingModule,
22 SharedModule,
23 ToastrModule.forRoot()
24 ],
25 providers: i18nProviders
26 });
27
28 beforeEach(() => {
29 fixture = TestBed.createComponent(MgrModuleFormComponent);
30 component = fixture.componentInstance;
31 fixture.detectChanges();
32 });
33
34 it('should create', () => {
35 expect(component).toBeTruthy();
36 });
37
38 describe('getValidators', () => {
39 it('should return ip validator for type addr', () => {
40 const result = component.getValidators({ type: 'addr' });
41 expect(result.length).toBe(1);
42 });
43
44 it('should return number, required validators for types uint, int, size, secs', () => {
45 const types = ['uint', 'int', 'size', 'secs'];
46 types.forEach((type) => {
47 const result = component.getValidators({ type: type });
48 expect(result.length).toBe(2);
49 });
50 });
51
52 it('should return number, required, min validators for types uint, int, size, secs', () => {
53 const types = ['uint', 'int', 'size', 'secs'];
54 types.forEach((type) => {
55 const result = component.getValidators({ type: type, min: 2 });
56 expect(result.length).toBe(3);
57 });
58 });
59
60 it('should return number, required, min, max validators for types uint, int, size, secs', () => {
61 const types = ['uint', 'int', 'size', 'secs'];
62 types.forEach((type) => {
63 const result = component.getValidators({ type: type, min: 2, max: 5 });
64 expect(result.length).toBe(4);
65 });
66 });
67
68 it('should return required, decimalNumber validators for type float', () => {
69 const result = component.getValidators({ type: 'float' });
70 expect(result.length).toBe(2);
71 });
72
73 it('should return uuid validator for type uuid', () => {
74 const result = component.getValidators({ type: 'uuid' });
75 expect(result.length).toBe(1);
76 });
77
78 it('should return no validator for type str', () => {
79 const result = component.getValidators({ type: 'str' });
80 expect(result.length).toBe(0);
81 });
82
83 it('should return min validator for type str', () => {
84 const result = component.getValidators({ type: 'str', min: 1 });
85 expect(result.length).toBe(1);
86 });
87
88 it('should return min, max validators for type str', () => {
89 const result = component.getValidators({ type: 'str', min: 1, max: 127 });
90 expect(result.length).toBe(2);
91 });
92 });
93 });