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