]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-image-settings-modal/iscsi-target-image-settings-modal.component.spec.ts
import ceph 14.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / iscsi-target-image-settings-modal / iscsi-target-image-settings-modal.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormControl, ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { BsModalRef } from 'ngx-bootstrap/modal';
7
8 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../shared/shared.module';
10 import { IscsiSettingComponent } from '../iscsi-setting/iscsi-setting.component';
11 import { IscsiTargetImageSettingsModalComponent } from './iscsi-target-image-settings-modal.component';
12
13 describe('IscsiTargetImageSettingsModalComponent', () => {
14 let component: IscsiTargetImageSettingsModalComponent;
15 let fixture: ComponentFixture<IscsiTargetImageSettingsModalComponent>;
16
17 configureTestBed({
18 declarations: [IscsiTargetImageSettingsModalComponent, IscsiSettingComponent],
19 imports: [SharedModule, ReactiveFormsModule, HttpClientTestingModule, RouterTestingModule],
20 providers: [BsModalRef, i18nProviders]
21 });
22
23 beforeEach(() => {
24 fixture = TestBed.createComponent(IscsiTargetImageSettingsModalComponent);
25 component = fixture.componentInstance;
26
27 component.imagesSettings = { 'rbd/disk_1': { backstore: 'backstore:1', 'backstore:1': {} } };
28 component.image = 'rbd/disk_1';
29 component.disk_default_controls = {
30 'backstore:1': {
31 foo: 1,
32 bar: 2
33 },
34 'backstore:2': {
35 baz: 3
36 }
37 };
38 component.disk_controls_limits = {
39 'backstore:1': {
40 foo: {
41 min: 1,
42 max: 512,
43 type: 'int'
44 },
45 bar: {
46 min: 1,
47 max: 512,
48 type: 'int'
49 }
50 },
51 'backstore:2': {
52 baz: {
53 min: 1,
54 max: 512,
55 type: 'int'
56 }
57 }
58 };
59 component.backstores = ['backstore:1', 'backstore:2'];
60 component.control = new FormControl();
61
62 component.ngOnInit();
63 fixture.detectChanges();
64 });
65
66 it('should create', () => {
67 expect(component).toBeTruthy();
68 });
69
70 it('should fill the form', () => {
71 expect(component.settingsForm.value).toEqual({
72 lun: null,
73 wwn: null,
74 backstore: 'backstore:1',
75 foo: null,
76 bar: null,
77 baz: null
78 });
79 });
80
81 it('should save changes to imagesSettings', () => {
82 component.settingsForm.controls['foo'].setValue(1234);
83 expect(component.imagesSettings).toEqual({
84 'rbd/disk_1': { backstore: 'backstore:1', 'backstore:1': {} }
85 });
86 component.save();
87 expect(component.imagesSettings).toEqual({
88 'rbd/disk_1': {
89 lun: null,
90 wwn: null,
91 backstore: 'backstore:1',
92 'backstore:1': {
93 foo: 1234
94 }
95 }
96 });
97 });
98 });