]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/pool-edit-mode-modal/pool-edit-mode-modal.component.spec.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / pool-edit-mode-modal / pool-edit-mode-modal.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
2a845540 4import { ActivatedRoute } from '@angular/router';
11fdf7f2
TL
5import { RouterTestingModule } from '@angular/router/testing';
6
f67539c2 7import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
494da23a 8import { ToastrModule } from 'ngx-toastr';
11fdf7f2
TL
9import { of } from 'rxjs';
10
f67539c2
TL
11import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
12import { NotificationService } from '~/app/shared/services/notification.service';
13import { SharedModule } from '~/app/shared/shared.module';
2a845540 14import { ActivatedRouteStub } from '~/testing/activated-route-stub';
f67539c2 15import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
11fdf7f2
TL
16import { PoolEditModeModalComponent } from './pool-edit-mode-modal.component';
17
18describe('PoolEditModeModalComponent', () => {
19 let component: PoolEditModeModalComponent;
20 let fixture: ComponentFixture<PoolEditModeModalComponent>;
21 let notificationService: NotificationService;
22 let rbdMirroringService: RbdMirroringService;
23 let formHelper: FormHelper;
2a845540 24 let activatedRoute: ActivatedRouteStub;
11fdf7f2
TL
25
26 configureTestBed({
27 declarations: [PoolEditModeModalComponent],
28 imports: [
29 HttpClientTestingModule,
30 ReactiveFormsModule,
31 RouterTestingModule,
32 SharedModule,
494da23a 33 ToastrModule.forRoot()
11fdf7f2 34 ],
2a845540
TL
35 providers: [
36 NgbActiveModal,
37 {
38 provide: ActivatedRoute,
39 useValue: new ActivatedRouteStub({ pool_name: 'somePool' })
40 }
41 ]
11fdf7f2
TL
42 });
43
44 beforeEach(() => {
45 fixture = TestBed.createComponent(PoolEditModeModalComponent);
46 component = fixture.componentInstance;
47 component.poolName = 'somePool';
48
f67539c2 49 notificationService = TestBed.inject(NotificationService);
11fdf7f2
TL
50 spyOn(notificationService, 'show').and.stub();
51
f67539c2 52 rbdMirroringService = TestBed.inject(RbdMirroringService);
2a845540 53 activatedRoute = <ActivatedRouteStub>TestBed.inject(ActivatedRoute);
11fdf7f2
TL
54
55 formHelper = new FormHelper(component.editModeForm);
56 fixture.detectChanges();
57 });
58
59 it('should create', () => {
60 expect(component).toBeTruthy();
61 });
62
63 describe('update pool mode', () => {
64 beforeEach(() => {
f67539c2 65 spyOn(component.activeModal, 'close').and.callThrough();
11fdf7f2
TL
66 });
67
11fdf7f2 68 it('should call updatePool', () => {
2a845540 69 activatedRoute.setParams({ pool_name: 'somePool' });
11fdf7f2
TL
70 spyOn(rbdMirroringService, 'updatePool').and.callFake(() => of(''));
71
72 component.editModeForm.patchValue({ mirrorMode: 'disabled' });
73 component.update();
74 expect(rbdMirroringService.updatePool).toHaveBeenCalledWith('somePool', {
75 mirror_mode: 'disabled'
76 });
77 });
78 });
79
80 describe('form validation', () => {
81 it('should prevent disabling mirroring if peers exist', () => {
82 component.peerExists = true;
83 formHelper.expectErrorChange('mirrorMode', 'disabled', 'cannotDisable');
84 });
85 });
86});