]> git.proxmox.com Git - ceph.git/blob - 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
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { ActivatedRoute } from '@angular/router';
5 import { RouterTestingModule } from '@angular/router/testing';
6
7 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
8 import { ToastrModule } from 'ngx-toastr';
9 import { of } from 'rxjs';
10
11 import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
12 import { NotificationService } from '~/app/shared/services/notification.service';
13 import { SharedModule } from '~/app/shared/shared.module';
14 import { ActivatedRouteStub } from '~/testing/activated-route-stub';
15 import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
16 import { PoolEditModeModalComponent } from './pool-edit-mode-modal.component';
17
18 describe('PoolEditModeModalComponent', () => {
19 let component: PoolEditModeModalComponent;
20 let fixture: ComponentFixture<PoolEditModeModalComponent>;
21 let notificationService: NotificationService;
22 let rbdMirroringService: RbdMirroringService;
23 let formHelper: FormHelper;
24 let activatedRoute: ActivatedRouteStub;
25
26 configureTestBed({
27 declarations: [PoolEditModeModalComponent],
28 imports: [
29 HttpClientTestingModule,
30 ReactiveFormsModule,
31 RouterTestingModule,
32 SharedModule,
33 ToastrModule.forRoot()
34 ],
35 providers: [
36 NgbActiveModal,
37 {
38 provide: ActivatedRoute,
39 useValue: new ActivatedRouteStub({ pool_name: 'somePool' })
40 }
41 ]
42 });
43
44 beforeEach(() => {
45 fixture = TestBed.createComponent(PoolEditModeModalComponent);
46 component = fixture.componentInstance;
47 component.poolName = 'somePool';
48
49 notificationService = TestBed.inject(NotificationService);
50 spyOn(notificationService, 'show').and.stub();
51
52 rbdMirroringService = TestBed.inject(RbdMirroringService);
53 activatedRoute = <ActivatedRouteStub>TestBed.inject(ActivatedRoute);
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(() => {
65 spyOn(component.activeModal, 'close').and.callThrough();
66 });
67
68 it('should call updatePool', () => {
69 activatedRoute.setParams({ pool_name: 'somePool' });
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 });