]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
b82df5cfdee4d669dd4e1236591ef60a22b48d8d
[ceph-ci.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 {
12   NvmeofSubsystemsFormComponent,
13   SubsystemPayload
14 } from './nvmeof-subsystems-form.component';
15 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
16 import { NvmeofSubsystemsStepOneComponent } from './nvmeof-subsystem-step-1/nvmeof-subsystem-step-1.component';
17 import { GridModule, InputModule, RadioModule, TagModule } from 'carbon-components-angular';
18 import { NvmeofSubsystemsStepThreeComponent } from './nvmeof-subsystem-step-3/nvmeof-subsystem-step-3.component';
19
20 describe('NvmeofSubsystemsFormComponent', () => {
21   let component: NvmeofSubsystemsFormComponent;
22   let fixture: ComponentFixture<NvmeofSubsystemsFormComponent>;
23   let nvmeofService: NvmeofService;
24   const mockTimestamp = 1720693470789;
25   const mockGroupName = 'default';
26   const mockPayload: SubsystemPayload = {
27     nqn: '',
28     gw_group: mockGroupName,
29     subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
30   };
31
32   beforeEach(async () => {
33     spyOn(Date, 'now').and.returnValue(mockTimestamp);
34     await TestBed.configureTestingModule({
35       declarations: [
36         NvmeofSubsystemsFormComponent,
37         NvmeofSubsystemsStepOneComponent,
38         NvmeofSubsystemsStepThreeComponent
39       ],
40       providers: [NgbActiveModal],
41       imports: [
42         HttpClientTestingModule,
43         NgbTypeaheadModule,
44         ReactiveFormsModule,
45         RouterTestingModule,
46         SharedModule,
47         InputModule,
48         GridModule,
49         RadioModule,
50         TagModule,
51         ToastrModule.forRoot()
52       ]
53     }).compileComponents();
54
55     fixture = TestBed.createComponent(NvmeofSubsystemsFormComponent);
56     component = fixture.componentInstance;
57     component.ngOnInit();
58     fixture.detectChanges();
59     component.group = mockGroupName;
60   });
61
62   it('should create', () => {
63     expect(component).toBeTruthy();
64   });
65
66   describe('should test form', () => {
67     beforeEach(() => {
68       nvmeofService = TestBed.inject(NvmeofService);
69       spyOn(nvmeofService, 'createSubsystem').and.stub();
70     });
71
72     it('should be creating request correctly', () => {
73       const expectedNqn = 'nqn.2001-07.com.ceph:' + mockTimestamp;
74       mockPayload['nqn'] = expectedNqn;
75       component.onSubmit(mockPayload);
76       expect(nvmeofService.createSubsystem).toHaveBeenCalledWith({
77         nqn: expectedNqn,
78         gw_group: mockGroupName,
79         enable_ha: true,
80         dhchap_key: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
81       });
82     });
83   });
84 });