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