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';
6 import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
7 import _ from 'lodash';
8 import { ToastrModule } from 'ngx-toastr';
10 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
11 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
12 import { SharedModule } from '~/app/shared/shared.module';
13 import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
14 import { ServiceFormComponent } from './service-form.component';
16 describe('ServiceFormComponent', () => {
17 let component: ServiceFormComponent;
18 let fixture: ComponentFixture<ServiceFormComponent>;
19 let cephServiceService: CephServiceService;
20 let form: CdFormGroup;
21 let formHelper: FormHelper;
24 declarations: [ServiceFormComponent],
26 HttpClientTestingModule,
31 ToastrModule.forRoot()
36 fixture = TestBed.createComponent(ServiceFormComponent);
37 component = fixture.componentInstance;
38 form = component.serviceForm;
39 formHelper = new FormHelper(form);
40 fixture.detectChanges();
43 it('should create', () => {
44 expect(component).toBeTruthy();
47 describe('should test form', () => {
49 cephServiceService = TestBed.inject(CephServiceService);
50 spyOn(cephServiceService, 'create').and.stub();
53 it('should test placement (host)', () => {
54 formHelper.setValue('service_type', 'crash');
55 formHelper.setValue('placement', 'hosts');
56 formHelper.setValue('hosts', ['mgr0', 'mon0', 'osd0']);
57 formHelper.setValue('count', 2);
59 expect(cephServiceService.create).toHaveBeenCalledWith({
60 service_type: 'crash',
62 hosts: ['mgr0', 'mon0', 'osd0'],
69 it('should test placement (label)', () => {
70 formHelper.setValue('service_type', 'mgr');
71 formHelper.setValue('placement', 'label');
72 formHelper.setValue('label', 'foo');
74 expect(cephServiceService.create).toHaveBeenCalledWith({
83 it('should submit valid count', () => {
84 formHelper.setValue('count', 1);
86 formHelper.expectValid('count');
89 it('should submit invalid count (1)', () => {
90 formHelper.setValue('count', 0);
92 formHelper.expectError('count', 'min');
95 it('should submit invalid count (2)', () => {
96 formHelper.setValue('count', 'abc');
98 formHelper.expectError('count', 'pattern');
101 it('should test unmanaged', () => {
102 formHelper.setValue('service_type', 'rgw');
103 formHelper.setValue('placement', 'label');
104 formHelper.setValue('label', 'bar');
105 formHelper.setValue('rgw_frontend_port', 4567);
106 formHelper.setValue('unmanaged', true);
107 component.onSubmit();
108 expect(cephServiceService.create).toHaveBeenCalledWith({
115 it('should test various services', () => {
129 formHelper.setValue('service_type', serviceType);
130 component.onSubmit();
131 expect(cephServiceService.create).toHaveBeenCalledWith({
132 service_type: serviceType,
140 describe('should test service nfs', () => {
142 formHelper.setValue('service_type', 'nfs');
143 formHelper.setValue('pool', 'foo');
146 it('should submit nfs with namespace', () => {
147 formHelper.setValue('namespace', 'bar');
148 component.onSubmit();
149 expect(cephServiceService.create).toHaveBeenCalledWith({
158 it('should submit nfs w/o namespace', () => {
159 component.onSubmit();
160 expect(cephServiceService.create).toHaveBeenCalledWith({
169 describe('should test service rgw', () => {
171 formHelper.setValue('service_type', 'rgw');
174 it('should test rgw valid service id', () => {
175 formHelper.setValue('service_id', 'foo.bar');
176 formHelper.expectValid('service_id');
177 formHelper.setValue('service_id', 'foo.bar.bas');
178 formHelper.expectValid('service_id');
181 it('should test rgw invalid service id', () => {
182 formHelper.setValue('service_id', 'foo');
183 formHelper.expectError('service_id', 'rgwPattern');
184 formHelper.setValue('service_id', 'foo.');
185 formHelper.expectError('service_id', 'rgwPattern');
186 formHelper.setValue('service_id', 'foo.bar.');
187 formHelper.expectError('service_id', 'rgwPattern');
188 formHelper.setValue('service_id', 'foo.bar.bas.');
189 formHelper.expectError('service_id', 'rgwPattern');
192 it('should submit rgw with port', () => {
193 formHelper.setValue('rgw_frontend_port', 1234);
194 formHelper.setValue('ssl', true);
195 component.onSubmit();
196 expect(cephServiceService.create).toHaveBeenCalledWith({
200 rgw_frontend_port: 1234,
201 rgw_frontend_ssl_certificate: '',
202 rgw_frontend_ssl_key: '',
207 it('should submit valid rgw port (1)', () => {
208 formHelper.setValue('rgw_frontend_port', 1);
209 component.onSubmit();
210 formHelper.expectValid('rgw_frontend_port');
213 it('should submit valid rgw port (2)', () => {
214 formHelper.setValue('rgw_frontend_port', 65535);
215 component.onSubmit();
216 formHelper.expectValid('rgw_frontend_port');
219 it('should submit invalid rgw port (1)', () => {
220 formHelper.setValue('rgw_frontend_port', 0);
221 component.onSubmit();
222 formHelper.expectError('rgw_frontend_port', 'min');
225 it('should submit invalid rgw port (2)', () => {
226 formHelper.setValue('rgw_frontend_port', 65536);
227 component.onSubmit();
228 formHelper.expectError('rgw_frontend_port', 'max');
231 it('should submit invalid rgw port (3)', () => {
232 formHelper.setValue('rgw_frontend_port', 'abc');
233 component.onSubmit();
234 formHelper.expectError('rgw_frontend_port', 'pattern');
237 it('should submit rgw w/o port', () => {
238 formHelper.setValue('ssl', false);
239 component.onSubmit();
240 expect(cephServiceService.create).toHaveBeenCalledWith({
249 describe('should test service iscsi', () => {
251 formHelper.setValue('service_type', 'iscsi');
252 formHelper.setValue('pool', 'xyz');
253 formHelper.setValue('api_user', 'user');
254 formHelper.setValue('api_password', 'password');
255 formHelper.setValue('ssl', false);
258 it('should submit iscsi', () => {
259 component.onSubmit();
260 expect(cephServiceService.create).toHaveBeenCalledWith({
261 service_type: 'iscsi',
266 api_password: 'password',
271 it('should submit iscsi with trusted ips', () => {
272 formHelper.setValue('ssl', true);
273 formHelper.setValue('trusted_ip_list', ' 172.16.0.5, 192.1.1.10 ');
274 component.onSubmit();
275 expect(cephServiceService.create).toHaveBeenCalledWith({
276 service_type: 'iscsi',
281 api_password: 'password',
285 trusted_ip_list: '172.16.0.5, 192.1.1.10'
289 it('should submit iscsi with port', () => {
290 formHelper.setValue('api_port', 456);
291 component.onSubmit();
292 expect(cephServiceService.create).toHaveBeenCalledWith({
293 service_type: 'iscsi',
298 api_password: 'password',
304 it('should submit valid iscsi port (1)', () => {
305 formHelper.setValue('api_port', 1);
306 component.onSubmit();
307 formHelper.expectValid('api_port');
310 it('should submit valid iscsi port (2)', () => {
311 formHelper.setValue('api_port', 65535);
312 component.onSubmit();
313 formHelper.expectValid('api_port');
316 it('should submit invalid iscsi port (1)', () => {
317 formHelper.setValue('api_port', 0);
318 component.onSubmit();
319 formHelper.expectError('api_port', 'min');
322 it('should submit invalid iscsi port (2)', () => {
323 formHelper.setValue('api_port', 65536);
324 component.onSubmit();
325 formHelper.expectError('api_port', 'max');
328 it('should submit invalid iscsi port (3)', () => {
329 formHelper.setValue('api_port', 'abc');
330 component.onSubmit();
331 formHelper.expectError('api_port', 'pattern');