import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; import {PregnancyComponent} from './pregnancy.component'; import {AppModule} from '../app.module'; import {of} from 'rxjs'; import {delay} from 'rxjs/operators'; import {YesNoEnum} from '@nspop/gm-web-facade-api'; import {AngularMaterialModule} from '../modules/angular-material.module'; import {FormsModule} from '@angular/forms'; import {MatIconTestingModule} from '@angular/material/icon/testing'; import {DataCardService} from '../api/data-card.service'; describe('PregnancyComponent', () => { let component: PregnancyComponent; let fixture: ComponentFixture; let dataCardServiceStub: DataCardService; beforeEach(async () => { dataCardServiceStub = { update: () => of({}).pipe( delay(100) ), refresh: () => {}, isDataCardClosed: of(false), selectedDataCard$: of({ identifier: '1', episodeOfCareIdentifier: '2', recordTarget: { identifier: '1008821234', name: { firstNames: ['Peter'], middleNames: [], lastName: 'Parker' } }, socialHistorySection: { partner: { translationLanguage: 'something', nationality: 'whetever', needsTranslation: YesNoEnum.True } }, screeningsSection: { hepatitisB: {}, hiv: {}, syphilis: {}, chlamydia: {}, gonorrhea: {}, streptococcusGroupB: {}, hemoglobinopathy: {}, vitaminDConsumption: {}, maternalRhDAntibody: {}, fetalRhDAntibody: {}, diabetesWeek18To20: {}, diabetesWeek28To30: {}, diabetesGlycosuria: {}, antiDImmunoglobulinGiven: {}, mrsaSwap: {}, }, expectedDateOfDeliverySection: { expectedDateOfDeliveryFromLastPeriod: {} } }) } as any; await TestBed.configureTestingModule({ declarations: [ PregnancyComponent], imports: [AppModule, AngularMaterialModule, FormsModule, MatIconTestingModule], providers: [ {provide: DataCardService, useValue: dataCardServiceStub} ] }) .compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(PregnancyComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('disables save button while saving', fakeAsync(() => { expect(component.disableSaveButton).toBeFalse(); component.save(); expect(component.disableSaveButton).toBeTrue(); tick(200); expect(component.disableSaveButton).toBeFalse(); })); it('handles that active datacard could be undefined', fakeAsync(() => { component = new PregnancyComponent({selectedDataCard$: of()} as any); component.ngOnInit(); tick(); expect(component.dataCard).toBeUndefined(); })); });