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 { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8 import { of } from 'rxjs';
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';
16 describe('PoolEditModeModalComponent', () => {
17 let component: PoolEditModeModalComponent;
18 let fixture: ComponentFixture<PoolEditModeModalComponent>;
19 let notificationService: NotificationService;
20 let rbdMirroringService: RbdMirroringService;
21 let formHelper: FormHelper;
24 declarations: [PoolEditModeModalComponent],
26 HttpClientTestingModule,
30 ToastrModule.forRoot()
32 providers: [NgbActiveModal]
36 fixture = TestBed.createComponent(PoolEditModeModalComponent);
37 component = fixture.componentInstance;
38 component.poolName = 'somePool';
40 notificationService = TestBed.inject(NotificationService);
41 spyOn(notificationService, 'show').and.stub();
43 rbdMirroringService = TestBed.inject(RbdMirroringService);
45 formHelper = new FormHelper(component.editModeForm);
46 fixture.detectChanges();
49 it('should create', () => {
50 expect(component).toBeTruthy();
53 describe('update pool mode', () => {
55 spyOn(component.activeModal, 'close').and.callThrough();
59 expect(component.activeModal.close).toHaveBeenCalledTimes(1);
62 it('should call updatePool', () => {
63 spyOn(rbdMirroringService, 'updatePool').and.callFake(() => of(''));
65 component.editModeForm.patchValue({ mirrorMode: 'disabled' });
67 expect(rbdMirroringService.updatePool).toHaveBeenCalledWith('somePool', {
68 mirror_mode: 'disabled'
73 describe('form validation', () => {
74 it('should prevent disabling mirroring if peers exist', () => {
75 component.peerExists = true;
76 formHelper.expectErrorChange('mirrorMode', 'disabled', 'cannotDisable');