1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import { CephfsSubvolumeFormComponent } from './cephfs-subvolume-form.component';
5 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
6 import { ToastrModule } from 'ngx-toastr';
7 import { SharedModule } from '~/app/shared/shared.module';
8 import { RouterTestingModule } from '@angular/router/testing';
9 import { ReactiveFormsModule } from '@angular/forms';
10 import { FormHelper, configureTestBed } from '~/testing/unit-test-helper';
11 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service';
13 describe('CephfsSubvolumeFormComponent', () => {
14 let component: CephfsSubvolumeFormComponent;
15 let fixture: ComponentFixture<CephfsSubvolumeFormComponent>;
16 let formHelper: FormHelper;
17 let createSubVolumeSpy: jasmine.Spy;
18 let editSubVolumeSpy: jasmine.Spy;
21 declarations: [CephfsSubvolumeFormComponent],
22 providers: [NgbActiveModal],
25 ToastrModule.forRoot(),
27 HttpClientTestingModule,
33 fixture = TestBed.createComponent(CephfsSubvolumeFormComponent);
34 component = fixture.componentInstance;
35 component.fsName = 'test_volume';
38 formHelper = new FormHelper(component.subvolumeForm);
39 createSubVolumeSpy = spyOn(TestBed.inject(CephfsSubvolumeService), 'create').and.stub();
40 editSubVolumeSpy = spyOn(TestBed.inject(CephfsSubvolumeService), 'update').and.stub();
41 fixture.detectChanges();
44 it('should create', () => {
45 expect(component).toBeTruthy();
48 it('should have a form open in modal', () => {
49 const nativeEl = fixture.debugElement.nativeElement;
50 expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
53 it('should have the volume name prefilled', () => {
55 expect(component.subvolumeForm.get('volumeName').value).toBe('test_volume');
58 it('should submit the form', () => {
59 formHelper.setValue('subvolumeName', 'test_subvolume');
60 formHelper.setValue('size', 10);
63 expect(createSubVolumeSpy).toHaveBeenCalled();
64 expect(editSubVolumeSpy).not.toHaveBeenCalled();
67 it('should edit the subvolume', () => {
68 component.isEdit = true;
70 formHelper.setValue('subvolumeName', 'test_subvolume');
71 formHelper.setValue('size', 10);
74 expect(editSubVolumeSpy).toHaveBeenCalled();
75 expect(createSubVolumeSpy).not.toHaveBeenCalled();