]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
bb7abdcbbebc0177d38afbbd2fc870912085d03c
[ceph-ci.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 { Router } from '@angular/router';
5 import { RouterTestingModule } from '@angular/router/testing';
6 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import _ from 'lodash';
8 import { ToastrModule } from 'ngx-toastr';
9 import { of as observableOf } from 'rxjs';
10 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
11 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
12 import { NotificationService } from '~/app/shared/services/notification.service';
13 import { SharedModule } from '~/app/shared/shared.module';
14
15 import { RgwMultisiteZonegroupFormComponent } from './rgw-multisite-zonegroup-form.component';
16
17 describe('RgwMultisiteZonegroupFormComponent', () => {
18   let component: RgwMultisiteZonegroupFormComponent;
19   let fixture: ComponentFixture<RgwMultisiteZonegroupFormComponent>;
20   let rgwZonegroupService: RgwZonegroupService;
21
22   beforeEach(async () => {
23     await TestBed.configureTestingModule({
24       imports: [
25         SharedModule,
26         ReactiveFormsModule,
27         RouterTestingModule,
28         HttpClientTestingModule,
29         ToastrModule.forRoot()
30       ],
31       providers: [NgbActiveModal],
32       declarations: [RgwMultisiteZonegroupFormComponent]
33     }).compileComponents();
34   });
35
36   beforeEach(() => {
37     fixture = TestBed.createComponent(RgwMultisiteZonegroupFormComponent);
38     component = fixture.componentInstance;
39     fixture.detectChanges();
40   });
41
42   it('should create', () => {
43     expect(component).toBeTruthy();
44   });
45
46   describe('submit form', () => {
47     let notificationService: NotificationService;
48
49     beforeEach(() => {
50       spyOn(TestBed.inject(Router), 'navigate').and.stub();
51       notificationService = TestBed.inject(NotificationService);
52       spyOn(notificationService, 'show');
53       rgwZonegroupService = TestBed.inject(RgwZonegroupService);
54     });
55
56     it('should validate name', () => {
57       component.action = 'create';
58       component.createForm();
59       const control = component.multisiteZonegroupForm.get('zonegroupName');
60       expect(_.isFunction(control.validator)).toBeTruthy();
61     });
62
63     it('should not validate name', () => {
64       component.action = 'edit';
65       component.createForm();
66       const control = component.multisiteZonegroupForm.get('zonegroupName');
67       expect(control.asyncValidator).toBeNull();
68     });
69
70     it('tests create success notification', () => {
71       spyOn(rgwZonegroupService, 'create').and.returnValue(observableOf([]));
72       component.action = 'create';
73       component.multisiteZonegroupForm.markAsDirty();
74       component.multisiteZonegroupForm._get('zonegroupName').setValue('zg-1');
75       component.multisiteZonegroupForm
76         ._get('zonegroup_endpoints')
77         .setValue('http://192.1.1.1:8004');
78       component.submit();
79       expect(notificationService.show).toHaveBeenCalledWith(
80         NotificationType.success,
81         "Zonegroup: 'zg-1' created successfully"
82       );
83     });
84
85     it('tests update success notification', () => {
86       spyOn(rgwZonegroupService, 'update').and.returnValue(observableOf([]));
87       component.action = 'edit';
88       component.info = {
89         data: { name: 'zg-1', zones: ['z1'] }
90       };
91       component.multisiteZonegroupForm._get('zonegroupName').setValue('zg-1');
92       component.multisiteZonegroupForm
93         ._get('zonegroup_endpoints')
94         .setValue('http://192.1.1.1:8004,http://192.12.12.12:8004');
95       component.multisiteZonegroupForm.markAsDirty();
96       component.submit();
97       expect(notificationService.show).toHaveBeenCalledWith(
98         NotificationType.success,
99         "Zonegroup: 'zg-1' updated successfully"
100       );
101     });
102   });
103 });