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 { ToastModule } from 'ng2-toastr';
7 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
8 import { of } from 'rxjs';
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';
20 describe('PoolEditModeModalComponent', () => {
21 let component: PoolEditModeModalComponent;
22 let fixture: ComponentFixture<PoolEditModeModalComponent>;
23 let notificationService: NotificationService;
24 let rbdMirroringService: RbdMirroringService;
25 let formHelper: FormHelper;
28 declarations: [PoolEditModeModalComponent],
30 HttpClientTestingModule,
36 providers: [BsModalRef, BsModalService, i18nProviders]
40 fixture = TestBed.createComponent(PoolEditModeModalComponent);
41 component = fixture.componentInstance;
42 component.poolName = 'somePool';
44 notificationService = TestBed.get(NotificationService);
45 spyOn(notificationService, 'show').and.stub();
47 rbdMirroringService = TestBed.get(RbdMirroringService);
49 formHelper = new FormHelper(component.editModeForm);
50 fixture.detectChanges();
53 it('should create', () => {
54 expect(component).toBeTruthy();
57 describe('update pool mode', () => {
59 spyOn(component.modalRef, 'hide').and.callThrough();
63 expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
66 it('should call updatePool', () => {
67 spyOn(rbdMirroringService, 'updatePool').and.callFake(() => of(''));
69 component.editModeForm.patchValue({ mirrorMode: 'disabled' });
71 expect(rbdMirroringService.updatePool).toHaveBeenCalledWith('somePool', {
72 mirror_mode: 'disabled'
77 describe('form validation', () => {
78 it('should prevent disabling mirroring if peers exist', () => {
79 component.peerExists = true;
80 formHelper.expectErrorChange('mirrorMode', 'disabled', 'cannotDisable');