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