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';
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 = {
28 gw_group: mockGroupName,
29 subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
32 beforeEach(async () => {
33 spyOn(Date, 'now').and.returnValue(mockTimestamp);
34 await TestBed.configureTestingModule({
36 NvmeofSubsystemsFormComponent,
37 NvmeofSubsystemsStepOneComponent,
38 NvmeofSubsystemsStepThreeComponent
40 providers: [NgbActiveModal],
42 HttpClientTestingModule,
51 ToastrModule.forRoot()
53 }).compileComponents();
55 fixture = TestBed.createComponent(NvmeofSubsystemsFormComponent);
56 component = fixture.componentInstance;
58 fixture.detectChanges();
59 component.group = mockGroupName;
62 it('should create', () => {
63 expect(component).toBeTruthy();
66 describe('should test form', () => {
68 nvmeofService = TestBed.inject(NvmeofService);
69 spyOn(nvmeofService, 'createSubsystem').and.stub();
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({
78 gw_group: mockGroupName,
80 dhchap_key: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='