]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
93d19341c9a83ebed767bf32868012bcb4133f24
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4
5 import { BsModalRef } from 'ngx-bootstrap/modal';
6 import { of } from 'rxjs';
7
8 import { configureTestBed } from '../../../../../testing/unit-test-helper';
9 import { OsdService } from '../../../../shared/api/osd.service';
10 import { ModalComponent } from '../../../../shared/components/modal/modal.component';
11 import { SubmitButtonComponent } from '../../../../shared/components/submit-button/submit-button.component';
12 import { CdFormBuilder } from '../../../../shared/forms/cd-form-builder';
13 import { OsdReweightModalComponent } from './osd-reweight-modal.component';
14
15 describe('OsdReweightModalComponent', () => {
16   let component: OsdReweightModalComponent;
17   let fixture: ComponentFixture<OsdReweightModalComponent>;
18
19   configureTestBed({
20     imports: [ReactiveFormsModule, HttpClientTestingModule],
21     declarations: [OsdReweightModalComponent, ModalComponent, SubmitButtonComponent],
22     providers: [OsdService, BsModalRef, CdFormBuilder]
23   });
24
25   beforeEach(() => {
26     fixture = TestBed.createComponent(OsdReweightModalComponent);
27     component = fixture.componentInstance;
28     fixture.detectChanges();
29   });
30
31   it('should create', () => {
32     expect(component).toBeTruthy();
33   });
34
35   it('should call OsdService::reweight() on submit', () => {
36     component.osdId = 1;
37     component.reweightForm.get('weight').setValue(0.5);
38
39     const osdServiceSpy = spyOn(TestBed.get(OsdService), 'reweight').and.callFake(() => of(true));
40     component.reweight();
41
42     expect(osdServiceSpy.calls.count()).toBe(1);
43     expect(osdServiceSpy.calls.first().args).toEqual([1, 0.5]);
44   });
45 });