]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
f6da04f5ec071297efa68cea61ba125ac89a47ed
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ReactiveFormsModule } from '@angular/forms';
3 import { RouterTestingModule } from '@angular/router/testing';
4 import { ComponentFixture, TestBed } from '@angular/core/testing';
5
6 import { ToastrModule } from 'ngx-toastr';
7
8 import { NgbActiveModal, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
9
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
12
13 import { NvmeofInitiatorsFormComponent } from './nvmeof-initiators-form.component';
14
15 describe('NvmeofInitiatorsFormComponent', () => {
16   let component: NvmeofInitiatorsFormComponent;
17   let fixture: ComponentFixture<NvmeofInitiatorsFormComponent>;
18   let nvmeofService: NvmeofService;
19   const mockTimestamp = 1720693470789;
20
21   beforeEach(async () => {
22     spyOn(Date, 'now').and.returnValue(mockTimestamp);
23     await TestBed.configureTestingModule({
24       declarations: [NvmeofInitiatorsFormComponent],
25       providers: [NgbActiveModal],
26       imports: [
27         HttpClientTestingModule,
28         NgbTypeaheadModule,
29         ReactiveFormsModule,
30         RouterTestingModule,
31         SharedModule,
32         ToastrModule.forRoot()
33       ]
34     }).compileComponents();
35
36     fixture = TestBed.createComponent(NvmeofInitiatorsFormComponent);
37     component = fixture.componentInstance;
38     component.ngOnInit();
39     fixture.detectChanges();
40   });
41
42   it('should create', () => {
43     expect(component).toBeTruthy();
44   });
45
46   describe('should test form', () => {
47     beforeEach(() => {
48       nvmeofService = TestBed.inject(NvmeofService);
49       spyOn(nvmeofService, 'addInitiators').and.stub();
50     });
51
52     it('should be creating request correctly', () => {
53       const subsystemNQN = 'nqn.2001-07.com.ceph:' + mockTimestamp;
54       component.subsystemNQN = subsystemNQN;
55       component.onSubmit();
56       expect(nvmeofService.addInitiators).toHaveBeenCalledWith(subsystemNQN, {
57         host_nqn: ''
58       });
59     });
60   });
61 });