summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-iqn-settings-modal/iscsi-target-iqn-settings-modal.component.spec.ts
blob: dda1be3c1deb85b6b08c718a49fa9e0e185472fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';

import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { IscsiSettingComponent } from '../iscsi-setting/iscsi-setting.component';
import { IscsiTargetIqnSettingsModalComponent } from './iscsi-target-iqn-settings-modal.component';

describe('IscsiTargetIqnSettingsModalComponent', () => {
  let component: IscsiTargetIqnSettingsModalComponent;
  let fixture: ComponentFixture<IscsiTargetIqnSettingsModalComponent>;

  configureTestBed({
    declarations: [IscsiTargetIqnSettingsModalComponent, IscsiSettingComponent],
    imports: [SharedModule, ReactiveFormsModule, HttpClientTestingModule, RouterTestingModule],
    providers: [NgbActiveModal]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(IscsiTargetIqnSettingsModalComponent);
    component = fixture.componentInstance;
    component.target_controls = new FormControl({});
    component.target_default_controls = {
      cmdsn_depth: 1,
      dataout_timeout: 2,
      first_burst_length: true
    };
    component.target_controls_limits = {
      cmdsn_depth: {
        min: 1,
        max: 512,
        type: 'int'
      },
      dataout_timeout: {
        min: 2,
        max: 60,
        type: 'int'
      },
      first_burst_length: {
        max: 16777215,
        min: 512,
        type: 'int'
      }
    };
    component.ngOnInit();
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should fill the settingsForm', () => {
    expect(component.settingsForm.value).toEqual({
      cmdsn_depth: null,
      dataout_timeout: null,
      first_burst_length: null
    });
  });

  it('should save changes to target_controls', () => {
    component.settingsForm.patchValue({ dataout_timeout: 1234 });
    expect(component.target_controls.value).toEqual({});
    component.save();
    expect(component.target_controls.value).toEqual({ dataout_timeout: 1234 });
  });
});