]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
a22a60d5e736c0fb631ce975d4d0226c53d08bcc
[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 { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8 import { of } from 'rxjs';
9
10 import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
11 import { NotificationService } from '~/app/shared/services/notification.service';
12 import { SharedModule } from '~/app/shared/shared.module';
13 import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
14 import { PoolEditModeModalComponent } from './pool-edit-mode-modal.component';
15
16 describe('PoolEditModeModalComponent', () => {
17   let component: PoolEditModeModalComponent;
18   let fixture: ComponentFixture<PoolEditModeModalComponent>;
19   let notificationService: NotificationService;
20   let rbdMirroringService: RbdMirroringService;
21   let formHelper: FormHelper;
22
23   configureTestBed({
24     declarations: [PoolEditModeModalComponent],
25     imports: [
26       HttpClientTestingModule,
27       ReactiveFormsModule,
28       RouterTestingModule,
29       SharedModule,
30       ToastrModule.forRoot()
31     ],
32     providers: [NgbActiveModal]
33   });
34
35   beforeEach(() => {
36     fixture = TestBed.createComponent(PoolEditModeModalComponent);
37     component = fixture.componentInstance;
38     component.poolName = 'somePool';
39
40     notificationService = TestBed.inject(NotificationService);
41     spyOn(notificationService, 'show').and.stub();
42
43     rbdMirroringService = TestBed.inject(RbdMirroringService);
44
45     formHelper = new FormHelper(component.editModeForm);
46     fixture.detectChanges();
47   });
48
49   it('should create', () => {
50     expect(component).toBeTruthy();
51   });
52
53   describe('update pool mode', () => {
54     beforeEach(() => {
55       spyOn(component.activeModal, 'close').and.callThrough();
56     });
57
58     afterEach(() => {
59       expect(component.activeModal.close).toHaveBeenCalledTimes(1);
60     });
61
62     it('should call updatePool', () => {
63       spyOn(rbdMirroringService, 'updatePool').and.callFake(() => of(''));
64
65       component.editModeForm.patchValue({ mirrorMode: 'disabled' });
66       component.update();
67       expect(rbdMirroringService.updatePool).toHaveBeenCalledWith('somePool', {
68         mirror_mode: 'disabled'
69       });
70     });
71   });
72
73   describe('form validation', () => {
74     it('should prevent disabling mirroring if peers exist', () => {
75       component.peerExists = true;
76       formHelper.expectErrorChange('mirrorMode', 'disabled', 'cannotDisable');
77     });
78   });
79 });