]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.spec.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / hosts / host-form / host-form.component.spec.ts
CommitLineData
f67539c2 1import { HttpClientTestingModule } from '@angular/common/http/testing';
b3b6e05e 2import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
9f95a23c 3import { ReactiveFormsModule } from '@angular/forms';
f67539c2 4import { RouterTestingModule } from '@angular/router/testing';
9f95a23c 5
a4b75251 6import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
9f95a23c
TL
7import { ToastrModule } from 'ngx-toastr';
8
f67539c2
TL
9import { LoadingPanelComponent } from '~/app/shared/components/loading-panel/loading-panel.component';
10import { SharedModule } from '~/app/shared/shared.module';
b3b6e05e 11import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
9f95a23c
TL
12import { HostFormComponent } from './host-form.component';
13
14describe('HostFormComponent', () => {
15 let component: HostFormComponent;
16 let fixture: ComponentFixture<HostFormComponent>;
b3b6e05e 17 let formHelper: FormHelper;
9f95a23c 18
f67539c2
TL
19 configureTestBed(
20 {
21 imports: [
22 SharedModule,
23 HttpClientTestingModule,
24 RouterTestingModule,
25 ReactiveFormsModule,
26 ToastrModule.forRoot()
27 ],
a4b75251
TL
28 declarations: [HostFormComponent],
29 providers: [NgbActiveModal]
f67539c2
TL
30 },
31 [LoadingPanelComponent]
32 );
9f95a23c
TL
33
34 beforeEach(() => {
35 fixture = TestBed.createComponent(HostFormComponent);
36 component = fixture.componentInstance;
a4b75251 37 component.ngOnInit();
b3b6e05e 38 formHelper = new FormHelper(component.hostForm);
9f95a23c
TL
39 fixture.detectChanges();
40 });
41
42 it('should create', () => {
43 expect(component).toBeTruthy();
44 });
b3b6e05e 45
a4b75251
TL
46 it('should open the form in a modal', () => {
47 const nativeEl = fixture.debugElement.nativeElement;
48 expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
49 });
50
b3b6e05e
TL
51 it('should validate the network address is valid', fakeAsync(() => {
52 formHelper.setValue('addr', '115.42.150.37', true);
53 tick();
54 formHelper.expectValid('addr');
55 }));
56
57 it('should show error if network address is invalid', fakeAsync(() => {
58 formHelper.setValue('addr', '666.10.10.20', true);
59 tick();
60 formHelper.expectError('addr', 'pattern');
61 }));
62
63 it('should submit the network address', () => {
64 component.hostForm.get('addr').setValue('127.0.0.1');
65 fixture.detectChanges();
66 component.submit();
67 expect(component.addr).toBe('127.0.0.1');
68 });
69
70 it('should validate the labels are added', () => {
71 const labels = ['label1', 'label2'];
72 component.hostForm.get('labels').patchValue(labels);
73 fixture.detectChanges();
74 component.submit();
75 expect(component.allLabels).toBe(labels);
76 });
77
78 it('should select maintenance mode', () => {
79 component.hostForm.get('maintenance').setValue(true);
80 fixture.detectChanges();
81 component.submit();
82 expect(component.status).toBe('maintenance');
83 });
a4b75251
TL
84
85 it('should expand the hostname correctly', () => {
86 component.hostForm.get('hostname').setValue('ceph-node-00.cephlab.com');
87 fixture.detectChanges();
88 component.submit();
89 expect(component.hostnameArray).toStrictEqual(['ceph-node-00.cephlab.com']);
90
91 component.hostnameArray = [];
92
93 component.hostForm.get('hostname').setValue('ceph-node-[00-10].cephlab.com');
94 fixture.detectChanges();
95 component.submit();
96 expect(component.hostnameArray).toStrictEqual([
97 'ceph-node-00.cephlab.com',
98 'ceph-node-01.cephlab.com',
99 'ceph-node-02.cephlab.com',
100 'ceph-node-03.cephlab.com',
101 'ceph-node-04.cephlab.com',
102 'ceph-node-05.cephlab.com',
103 'ceph-node-06.cephlab.com',
104 'ceph-node-07.cephlab.com',
105 'ceph-node-08.cephlab.com',
106 'ceph-node-09.cephlab.com',
107 'ceph-node-10.cephlab.com'
108 ]);
109
110 component.hostnameArray = [];
111
112 component.hostForm.get('hostname').setValue('ceph-node-00.cephlab.com,ceph-node-1.cephlab.com');
113 fixture.detectChanges();
114 component.submit();
115 expect(component.hostnameArray).toStrictEqual([
116 'ceph-node-00.cephlab.com',
117 'ceph-node-1.cephlab.com'
118 ]);
119
120 component.hostnameArray = [];
121
122 component.hostForm
123 .get('hostname')
124 .setValue('ceph-mon-[01-05].lab.com,ceph-osd-[1-4].lab.com,ceph-rgw-[001-006].lab.com');
125 fixture.detectChanges();
126 component.submit();
127 expect(component.hostnameArray).toStrictEqual([
128 'ceph-mon-01.lab.com',
129 'ceph-mon-02.lab.com',
130 'ceph-mon-03.lab.com',
131 'ceph-mon-04.lab.com',
132 'ceph-mon-05.lab.com',
133 'ceph-osd-1.lab.com',
134 'ceph-osd-2.lab.com',
135 'ceph-osd-3.lab.com',
136 'ceph-osd-4.lab.com',
137 'ceph-rgw-001.lab.com',
138 'ceph-rgw-002.lab.com',
139 'ceph-rgw-003.lab.com',
140 'ceph-rgw-004.lab.com',
141 'ceph-rgw-005.lab.com',
142 'ceph-rgw-006.lab.com'
143 ]);
144
145 component.hostnameArray = [];
146
147 component.hostForm
148 .get('hostname')
149 .setValue('ceph-(mon-[00-04],osd-[001-005],rgw-[1-3]).lab.com');
150 fixture.detectChanges();
151 component.submit();
152 expect(component.hostnameArray).toStrictEqual([
153 'ceph-mon-00.lab.com',
154 'ceph-mon-01.lab.com',
155 'ceph-mon-02.lab.com',
156 'ceph-mon-03.lab.com',
157 'ceph-mon-04.lab.com',
158 'ceph-osd-001.lab.com',
159 'ceph-osd-002.lab.com',
160 'ceph-osd-003.lab.com',
161 'ceph-osd-004.lab.com',
162 'ceph-osd-005.lab.com',
163 'ceph-rgw-1.lab.com',
164 'ceph-rgw-2.lab.com',
165 'ceph-rgw-3.lab.com'
166 ]);
167 });
9f95a23c 168});