]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
5e7b04b9f25af244604c280ff83b2537fcf5fb25
[ceph-ci.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 { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8
9 import { ComponentsModule } from '~/app/shared/components/components.module';
10 import { PipesModule } from '~/app/shared/pipes/pipes.module';
11 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
12 import { configureTestBed } from '~/testing/unit-test-helper';
13 import { RbdSnapshotFormModalComponent } from './rbd-snapshot-form-modal.component';
14 import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
15 import { of } from 'rxjs';
16
17 describe('RbdSnapshotFormModalComponent', () => {
18   let component: RbdSnapshotFormModalComponent;
19   let fixture: ComponentFixture<RbdSnapshotFormModalComponent>;
20   let rbdMirrorService: RbdMirroringService;
21
22   configureTestBed({
23     imports: [
24       ReactiveFormsModule,
25       ComponentsModule,
26       PipesModule,
27       HttpClientTestingModule,
28       ToastrModule.forRoot(),
29       RouterTestingModule
30     ],
31     declarations: [RbdSnapshotFormModalComponent],
32     providers: [NgbActiveModal, AuthStorageService]
33   });
34
35   beforeEach(() => {
36     fixture = TestBed.createComponent(RbdSnapshotFormModalComponent);
37     component = fixture.componentInstance;
38     rbdMirrorService = TestBed.inject(RbdMirroringService);
39   });
40
41   it('should create', () => {
42     expect(component).toBeTruthy();
43   });
44
45   it('should show "Create" text', () => {
46     fixture.detectChanges();
47
48     const header = fixture.debugElement.nativeElement.querySelector('h4');
49     expect(header.textContent).toBe('Create RBD Snapshot');
50
51     const button = fixture.debugElement.nativeElement.querySelector('cd-submit-button');
52     expect(button.textContent).toBe('Create RBD Snapshot');
53   });
54
55   it('should show "Rename" text', () => {
56     component.setEditing();
57
58     fixture.detectChanges();
59
60     const header = fixture.debugElement.nativeElement.querySelector('h4');
61     expect(header.textContent).toBe('Rename RBD Snapshot');
62
63     const button = fixture.debugElement.nativeElement.querySelector('cd-submit-button');
64     expect(button.textContent).toBe('Rename RBD Snapshot');
65   });
66
67   it('should enable the mirror image snapshot creation when peer is configured', () => {
68     spyOn(rbdMirrorService, 'getPeerForPool').and.returnValue(of(['test_peer']));
69     component.mirroring = 'snapshot';
70     component.ngOnInit();
71     fixture.detectChanges();
72     const radio = fixture.debugElement.nativeElement.querySelector('#mirrorImageSnapshot');
73     expect(radio.disabled).toBe(false);
74   });
75
76   it('should disable the mirror image snapshot creation when peer is not configured', () => {
77     spyOn(rbdMirrorService, 'getPeerForPool').and.returnValue(of([]));
78     component.mirroring = 'snapshot';
79     component.ngOnInit();
80     fixture.detectChanges();
81     const radio = fixture.debugElement.nativeElement.querySelector('#mirrorImageSnapshot');
82     expect(radio.disabled).toBe(true);
83   });
84 });