]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
392e5c54ac757490a66ed6b8fd934683898d68a6
[ceph-ci.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
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';
12
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;
19
20   beforeEach(async () => {
21     await TestBed.configureTestingModule({
22       declarations: [CephfsSubvolumeFormComponent],
23       providers: [NgbActiveModal],
24       imports: [
25         SharedModule,
26         ToastrModule.forRoot(),
27         ReactiveFormsModule,
28         HttpClientTestingModule,
29         RouterTestingModule
30       ]
31     }).compileComponents();
32   });
33
34   beforeEach(() => {
35     fixture = TestBed.createComponent(CephfsSubvolumeFormComponent);
36     component = fixture.componentInstance;
37     component.fsName = 'test_volume';
38     component.pools = [];
39     component.ngOnInit();
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();
44   });
45
46   it('should create', () => {
47     expect(component).toBeTruthy();
48   });
49
50   it('should have a form open in modal', () => {
51     const nativeEl = fixture.debugElement.nativeElement;
52     expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
53   });
54
55   it('should have the volume name prefilled', () => {
56     component.ngOnInit();
57     expect(component.subvolumeForm.get('volumeName').value).toBe('test_volume');
58   });
59
60   it('should submit the form', () => {
61     formHelper.setValue('subvolumeName', 'test_subvolume');
62     formHelper.setValue('size', 10);
63     component.submit();
64
65     expect(createSubVolumeSpy).toHaveBeenCalled();
66     expect(editSubVolumeSpy).not.toHaveBeenCalled();
67   });
68
69   it('should edit the subvolume', () => {
70     component.isEdit = true;
71     component.ngOnInit();
72     formHelper.setValue('subvolumeName', 'test_subvolume');
73     formHelper.setValue('size', 10);
74     component.submit();
75
76     expect(editSubVolumeSpy).toHaveBeenCalled();
77     expect(createSubVolumeSpy).not.toHaveBeenCalled();
78   });
79 });