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';
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';
17 describe('RbdSnapshotFormModalComponent', () => {
18 let component: RbdSnapshotFormModalComponent;
19 let fixture: ComponentFixture<RbdSnapshotFormModalComponent>;
20 let rbdMirrorService: RbdMirroringService;
27 HttpClientTestingModule,
28 ToastrModule.forRoot(),
31 declarations: [RbdSnapshotFormModalComponent],
32 providers: [NgbActiveModal, AuthStorageService]
36 fixture = TestBed.createComponent(RbdSnapshotFormModalComponent);
37 component = fixture.componentInstance;
38 rbdMirrorService = TestBed.inject(RbdMirroringService);
41 it('should create', () => {
42 expect(component).toBeTruthy();
45 it('should show "Create" text', () => {
46 fixture.detectChanges();
48 const header = fixture.debugElement.nativeElement.querySelector('h4');
49 expect(header.textContent).toBe('Create RBD Snapshot');
51 const button = fixture.debugElement.nativeElement.querySelector('cd-submit-button');
52 expect(button.textContent).toBe('Create RBD Snapshot');
55 it('should show "Rename" text', () => {
56 component.setEditing();
58 fixture.detectChanges();
60 const header = fixture.debugElement.nativeElement.querySelector('h4');
61 expect(header.textContent).toBe('Rename RBD Snapshot');
63 const button = fixture.debugElement.nativeElement.querySelector('cd-submit-button');
64 expect(button.textContent).toBe('Rename RBD Snapshot');
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';
71 fixture.detectChanges();
72 const radio = fixture.debugElement.nativeElement.querySelector('#mirrorImageSnapshot');
73 expect(radio.disabled).toBe(false);
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';
80 fixture.detectChanges();
81 const radio = fixture.debugElement.nativeElement.querySelector('#mirrorImageSnapshot');
82 expect(radio.disabled).toBe(true);