]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
21005c80c524a8d4763b4cd93adb0f7dc132aa88
[ceph.git] /
1 import {
2   HttpClientTestingModule,
3   HttpTestingController,
4   TestRequest
5 } from '@angular/common/http/testing';
6 import { ComponentFixture, TestBed } from '@angular/core/testing';
7 import { ReactiveFormsModule } from '@angular/forms';
8 import { RouterTestingModule } from '@angular/router/testing';
9
10 import { ToastModule } from 'ng2-toastr';
11 import { BsModalRef } from 'ngx-bootstrap/modal';
12
13 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { IscsiTargetDiscoveryModalComponent } from './iscsi-target-discovery-modal.component';
16
17 describe('IscsiTargetDiscoveryModalComponent', () => {
18   let component: IscsiTargetDiscoveryModalComponent;
19   let fixture: ComponentFixture<IscsiTargetDiscoveryModalComponent>;
20   let httpTesting: HttpTestingController;
21   let req: TestRequest;
22
23   configureTestBed({
24     declarations: [IscsiTargetDiscoveryModalComponent],
25     imports: [
26       HttpClientTestingModule,
27       ReactiveFormsModule,
28       SharedModule,
29       ToastModule.forRoot(),
30       RouterTestingModule
31     ],
32     providers: [i18nProviders, BsModalRef]
33   });
34
35   beforeEach(() => {
36     fixture = TestBed.createComponent(IscsiTargetDiscoveryModalComponent);
37     component = fixture.componentInstance;
38     httpTesting = TestBed.get(HttpTestingController);
39     fixture.detectChanges();
40     req = httpTesting.expectOne('api/iscsi/discoveryauth');
41   });
42
43   it('should create', () => {
44     expect(component).toBeTruthy();
45   });
46
47   it('should create form', () => {
48     expect(component.discoveryForm.value).toEqual({
49       user: '',
50       password: '',
51       mutual_user: '',
52       mutual_password: ''
53     });
54   });
55
56   it('should patch form', () => {
57     req.flush({
58       user: 'foo',
59       password: 'bar',
60       mutual_user: 'mutual_foo',
61       mutual_password: 'mutual_bar'
62     });
63     expect(component.discoveryForm.value).toEqual({
64       user: 'foo',
65       password: 'bar',
66       mutual_user: 'mutual_foo',
67       mutual_password: 'mutual_bar'
68     });
69   });
70
71   it('should submit new values', () => {
72     component.discoveryForm.patchValue({
73       user: 'new_user',
74       password: 'new_pass',
75       mutual_user: 'mutual_new_user',
76       mutual_password: 'mutual_new_pass'
77     });
78     component.submitAction();
79
80     const submit_req = httpTesting.expectOne('api/iscsi/discoveryauth');
81     expect(submit_req.request.method).toBe('PUT');
82     expect(submit_req.request.body).toEqual({
83       user: 'new_user',
84       password: 'new_pass',
85       mutual_user: 'mutual_new_user',
86       mutual_password: 'mutual_new_pass'
87     });
88   });
89 });