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';
6 import { ToastrModule } from 'ngx-toastr';
8 import { NgbActiveModal, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
10 import { SharedModule } from '~/app/shared/shared.module';
12 NvmeofSubsystemsFormComponent,
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 import { HOST_TYPE } from '~/app/shared/models/nvmeof';
20 import { NvmeofSubsystemsStepTwoComponent } from './nvmeof-subsystem-step-2/nvmeof-subsystem-step-2.component';
21 import { of } from 'rxjs';
23 describe('NvmeofSubsystemsFormComponent', () => {
24 let component: NvmeofSubsystemsFormComponent;
25 let fixture: ComponentFixture<NvmeofSubsystemsFormComponent>;
26 let nvmeofService: NvmeofService;
27 const mockTimestamp = 1720693470789;
28 const mockGroupName = 'default';
29 const mockPayload: SubsystemPayload = {
31 gw_group: mockGroupName,
32 subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY=',
34 hostType: HOST_TYPE.ALL
37 beforeEach(async () => {
38 spyOn(Date, 'now').and.returnValue(mockTimestamp);
39 await TestBed.configureTestingModule({
41 NvmeofSubsystemsFormComponent,
42 NvmeofSubsystemsStepOneComponent,
43 NvmeofSubsystemsStepThreeComponent,
44 NvmeofSubsystemsStepTwoComponent
46 providers: [NgbActiveModal],
48 HttpClientTestingModule,
57 ToastrModule.forRoot()
59 }).compileComponents();
61 fixture = TestBed.createComponent(NvmeofSubsystemsFormComponent);
62 component = fixture.componentInstance;
64 fixture.detectChanges();
65 component.group = mockGroupName;
68 it('should create', () => {
69 expect(component).toBeTruthy();
72 describe('should test form', () => {
74 nvmeofService = TestBed.inject(NvmeofService);
75 spyOn(nvmeofService, 'createSubsystem').and.returnValue(of({}));
76 spyOn(nvmeofService, 'addInitiators').and.returnValue(of({}));
79 it('should be creating request correctly', () => {
80 const expectedNqn = 'nqn.2001-07.com.ceph:' + mockTimestamp;
81 mockPayload['nqn'] = expectedNqn;
82 component.onSubmit(mockPayload);
83 expect(nvmeofService.createSubsystem).toHaveBeenCalledWith({
85 gw_group: mockGroupName,
87 dhchap_key: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
91 it('should add initiators with wildcard when hostType is ALL', () => {
92 const payload: SubsystemPayload = {
94 gw_group: mockGroupName,
96 hostType: HOST_TYPE.ALL,
97 subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
100 component.group = mockGroupName;
101 component.onSubmit(payload);
103 expect(nvmeofService.addInitiators).toHaveBeenCalledWith('test-nqn.default', {
105 gw_group: mockGroupName