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 { CdFormGroup } from '~/app/shared/forms/cd-form-group';
11 import { SharedModule } from '~/app/shared/shared.module';
12 import { NvmeofSubsystemsFormComponent } from './nvmeof-subsystems-form.component';
13 import { FormHelper } from '~/testing/unit-test-helper';
14 import { MAX_NAMESPACE, NvmeofService } from '~/app/shared/api/nvmeof.service';
16 describe('NvmeofSubsystemsFormComponent', () => {
17 let component: NvmeofSubsystemsFormComponent;
18 let fixture: ComponentFixture<NvmeofSubsystemsFormComponent>;
19 let nvmeofService: NvmeofService;
20 let form: CdFormGroup;
21 let formHelper: FormHelper;
22 const mockTimestamp = 1720693470789;
23 const mockGroupName = 'default';
25 beforeEach(async () => {
26 spyOn(Date, 'now').and.returnValue(mockTimestamp);
27 await TestBed.configureTestingModule({
28 declarations: [NvmeofSubsystemsFormComponent],
29 providers: [NgbActiveModal],
31 HttpClientTestingModule,
36 ToastrModule.forRoot()
38 }).compileComponents();
40 fixture = TestBed.createComponent(NvmeofSubsystemsFormComponent);
41 component = fixture.componentInstance;
43 form = component.subsystemForm;
44 formHelper = new FormHelper(form);
45 fixture.detectChanges();
46 component.group = mockGroupName;
49 it('should create', () => {
50 expect(component).toBeTruthy();
53 describe('should test form', () => {
55 nvmeofService = TestBed.inject(NvmeofService);
56 spyOn(nvmeofService, 'createSubsystem').and.stub();
59 it('should be creating request correctly', () => {
60 const expectedNqn = 'nqn.2001-07.com.ceph:' + mockTimestamp;
62 expect(nvmeofService.createSubsystem).toHaveBeenCalledWith({
64 max_namespaces: MAX_NAMESPACE,
66 gw_group: mockGroupName
70 it('should give error on invalid nqn', () => {
71 formHelper.setValue('nqn', 'nqn:2001-07.com.ceph:');
73 formHelper.expectError('nqn', 'pattern');
76 it('should give error on invalid max_namespaces', () => {
77 formHelper.setValue('max_namespaces', -56);
79 formHelper.expectError('max_namespaces', 'pattern');
82 it(`should give error on max_namespaces greater than ${MAX_NAMESPACE}`, () => {
83 formHelper.setValue('max_namespaces', 2000);
85 formHelper.expectError('max_namespaces', 'max');
88 it('should give error on max_namespaces lesser than 1', () => {
89 formHelper.setValue('max_namespaces', 0);
91 formHelper.expectError('max_namespaces', 'min');