1 import { HttpClientTestingModule } from '@angular/common/http/testing';
8 } from '@angular/core/testing';
10 import { CephfsSnapshotscheduleFormComponent } from './cephfs-snapshotschedule-form.component';
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';
24 describe('CephfsSnapshotscheduleFormComponent', () => {
25 let component: CephfsSnapshotscheduleFormComponent;
26 let fixture: ComponentFixture<CephfsSnapshotscheduleFormComponent>;
27 let formHelper: FormHelper;
30 declarations: [CephfsSnapshotscheduleFormComponent],
31 providers: [NgbActiveModal],
34 ToastrModule.forRoot(),
36 HttpClientTestingModule,
44 fixture = TestBed.createComponent(CephfsSnapshotscheduleFormComponent);
45 component = fixture.componentInstance;
46 component.fsName = 'test_fs';
48 formHelper = new FormHelper(component.snapScheduleForm);
49 fixture.detectChanges();
52 it('should create', () => {
53 expect(component).toBeTruthy();
56 it('should have a form open in modal', () => {
57 const nativeEl = fixture.debugElement.nativeElement;
58 expect(nativeEl.querySelector('cd-modal')).not.toBe(null);
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),
66 ).and.returnValue(of(false));
83 formHelper.setMultipleValues(input);
84 component.snapScheduleForm.get('directory').setValue('/test');
88 expect(checkScheduleExistsSpy).toHaveBeenCalled();
89 expect(createSpy).toHaveBeenCalled();
90 discardPeriodicTasks();