]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
fc66c8689512103a5c68ef4a97cb29dae99ed03b
[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 { RouterTestingModule } from '@angular/router/testing';
5
6 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8 import { of } from 'rxjs';
9
10 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
11 import { RbdMirroringService } from '../../../../shared/api/rbd-mirroring.service';
12 import { NotificationService } from '../../../../shared/services/notification.service';
13 import { SharedModule } from '../../../../shared/shared.module';
14 import { EditSiteNameModalComponent } from './edit-site-name-modal.component';
15
16 describe('EditSiteNameModalComponent', () => {
17   let component: EditSiteNameModalComponent;
18   let fixture: ComponentFixture<EditSiteNameModalComponent>;
19   let notificationService: NotificationService;
20   let rbdMirroringService: RbdMirroringService;
21
22   configureTestBed({
23     declarations: [EditSiteNameModalComponent],
24     imports: [
25       HttpClientTestingModule,
26       ReactiveFormsModule,
27       RouterTestingModule,
28       SharedModule,
29       ToastrModule.forRoot()
30     ],
31     providers: [NgbActiveModal, i18nProviders]
32   });
33
34   beforeEach(() => {
35     fixture = TestBed.createComponent(EditSiteNameModalComponent);
36     component = fixture.componentInstance;
37     component.siteName = 'site-A';
38
39     notificationService = TestBed.inject(NotificationService);
40     spyOn(notificationService, 'show').and.stub();
41
42     rbdMirroringService = TestBed.inject(RbdMirroringService);
43   });
44
45   it('should create', () => {
46     expect(component).toBeTruthy();
47   });
48
49   describe('edit site name', () => {
50     beforeEach(() => {
51       spyOn(rbdMirroringService, 'getSiteName').and.callFake(() => of({ site_name: 'site-A' }));
52       spyOn(rbdMirroringService, 'refresh').and.stub();
53       spyOn(component.activeModal, 'close').and.callThrough();
54       fixture.detectChanges();
55     });
56
57     afterEach(() => {
58       expect(rbdMirroringService.getSiteName).toHaveBeenCalledTimes(1);
59       expect(rbdMirroringService.refresh).toHaveBeenCalledTimes(1);
60       expect(component.activeModal.close).toHaveBeenCalledTimes(1);
61     });
62
63     it('should call setSiteName', () => {
64       spyOn(rbdMirroringService, 'setSiteName').and.callFake(() => of({ site_name: 'new-site-A' }));
65
66       component.editSiteNameForm.patchValue({
67         siteName: 'new-site-A'
68       });
69       component.update();
70       expect(rbdMirroringService.setSiteName).toHaveBeenCalledWith('new-site-A');
71     });
72   });
73 });