]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
dedbd3bafc1ae2f0c22fffe503251ad4e3266190
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import {
3   ComponentFixture,
4   TestBed,
5   discardPeriodicTasks,
6   fakeAsync,
7   tick
8 } from '@angular/core/testing';
9
10 import { CephfsSnapshotscheduleFormComponent } from './cephfs-snapshotschedule-form.component';
11 import {
12   NgbActiveModal,
13   NgbDatepickerModule,
14   NgbTimepickerModule
15 } from '@ng-bootstrap/ng-bootstrap';
16 import { ToastrModule } from 'ngx-toastr';
17 import { SharedModule } from '~/app/shared/shared.module';
18 import { RouterTestingModule } from '@angular/router/testing';
19 import { ReactiveFormsModule } from '@angular/forms';
20 import { FormHelper, configureTestBed } from '~/testing/unit-test-helper';
21 import { CephfsSnapshotScheduleService } from '~/app/shared/api/cephfs-snapshot-schedule.service';
22 import { of } from 'rxjs';
23
24 describe('CephfsSnapshotscheduleFormComponent', () => {
25   let component: CephfsSnapshotscheduleFormComponent;
26   let fixture: ComponentFixture<CephfsSnapshotscheduleFormComponent>;
27   let formHelper: FormHelper;
28
29   configureTestBed({
30     declarations: [CephfsSnapshotscheduleFormComponent],
31     providers: [NgbActiveModal],
32     imports: [
33       SharedModule,
34       ToastrModule.forRoot(),
35       ReactiveFormsModule,
36       HttpClientTestingModule,
37       RouterTestingModule,
38       NgbDatepickerModule,
39       NgbTimepickerModule
40     ]
41   });
42
43   beforeEach(() => {
44     fixture = TestBed.createComponent(CephfsSnapshotscheduleFormComponent);
45     component = fixture.componentInstance;
46     component.fsName = 'test_fs';
47     component.ngOnInit();
48     formHelper = new FormHelper(component.snapScheduleForm);
49     fixture.detectChanges();
50   });
51
52   it('should create', () => {
53     expect(component).toBeTruthy();
54   });
55
56   it('should have a form open in modal', () => {
57     const nativeEl = fixture.debugElement.nativeElement;
58     expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
59   });
60
61   it('should submit the form', fakeAsync(() => {
62     const createSpy = spyOn(TestBed.inject(CephfsSnapshotScheduleService), 'create').and.stub();
63     const checkScheduleExistsSpy = spyOn(
64       TestBed.inject(CephfsSnapshotScheduleService),
65       'checkScheduleExists'
66     ).and.returnValue(of(false));
67     const input = {
68       directory: '/test',
69       startDate: {
70         year: 2023,
71         month: 11,
72         day: 14
73       },
74       startTime: {
75         hour: 0,
76         minute: 6,
77         second: 22
78       },
79       repeatInterval: 4,
80       repeatFrequency: 'h'
81     };
82
83     formHelper.setMultipleValues(input);
84     component.snapScheduleForm.get('directory').setValue('/test');
85     component.submit();
86     tick(400);
87
88     expect(checkScheduleExistsSpy).toHaveBeenCalled();
89     expect(createSpy).toHaveBeenCalled();
90     discardPeriodicTasks();
91   }));
92 });