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