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 } 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;
20 beforeEach(async () => {
21 await TestBed.configureTestingModule({
22 declarations: [CephfsSubvolumeFormComponent],
23 providers: [NgbActiveModal],
26 ToastrModule.forRoot(),
28 HttpClientTestingModule,
31 }).compileComponents();
35 fixture = TestBed.createComponent(CephfsSubvolumeFormComponent);
36 component = fixture.componentInstance;
37 component.fsName = 'test_volume';
40 formHelper = new FormHelper(component.subvolumeForm);
41 createSubVolumeSpy = spyOn(TestBed.inject(CephfsSubvolumeService), 'create').and.stub();
42 editSubVolumeSpy = spyOn(TestBed.inject(CephfsSubvolumeService), 'update').and.stub();
43 fixture.detectChanges();
46 it('should create', () => {
47 expect(component).toBeTruthy();
50 it('should have a form open in modal', () => {
51 const nativeEl = fixture.debugElement.nativeElement;
52 expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
55 it('should have the volume name prefilled', () => {
57 expect(component.subvolumeForm.get('volumeName').value).toBe('test_volume');
60 it('should submit the form', () => {
61 formHelper.setValue('subvolumeName', 'test_subvolume');
62 formHelper.setValue('size', 10);
65 expect(createSubVolumeSpy).toHaveBeenCalled();
66 expect(editSubVolumeSpy).not.toHaveBeenCalled();
69 it('should edit the subvolume', () => {
70 component.isEdit = true;
72 formHelper.setValue('subvolumeName', 'test_subvolume');
73 formHelper.setValue('size', 10);
76 expect(editSubVolumeSpy).toHaveBeenCalled();
77 expect(createSubVolumeSpy).not.toHaveBeenCalled();