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