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