import { ComponentFixture , TestBed } from "@angular/core/testing" ; import { ZonesImportExportDialogComponent } from "./zones-import-export-dialog.component" ; import { MAT_DIALOG_DATA , MatDialogRef } from "@angular/material" ; import { SharedModule } from "../../shared/shared.module" ; import { CoreModule } from "../../core/core.module" ; import { ZoneImportExportDataModel } from "./zone-import-export-data.model" ; import { ZoneDefinitionModel } from "../../shared/models/zone-definition.model" ; import { Mode } from "./mode.enum" ; import { UserZonesModel } from "@elevate/shared/models" ; import { userSettingsData } from "@elevate/shared/data" ; describe ( "ZonesImportExportDialogComponent" , ( ) => { const zoneSpeedDefinition = { name : "Cycling Speed" , value : "speed" , units : "KPH" , step : 0.1 , min : 0 , max : 9999 , customDisplay : null } ; let component ; let fixture ; let zoneImportExportDataModel_As_Export ; beforeEach ( ( done ) => { zoneImportExportDataModel_As_Export = new ZoneImportExportDataModel ( zoneSpeedDefinition , UserZonesModel . deserialize ( userSettingsData . zones . speed ) , Mode . EXPORT ) ; TestBed . configureTestingModule ( { imports : [ CoreModule , SharedModule , ] , declarations : [ ] , providers : [ { provide : MAT_DIALOG_DATA , useValue : zoneImportExportDataModel_As_Export , } , { provide : MatDialogRef , useValue : { } , } , ] } ) . compileComponents ( ) ; done ( ) ; } ) ; beforeEach ( ( done ) => { fixture = TestBed . createComponent ( ZonesImportExportDialogComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; done ( ) ; } ) ; it ( "should create" , ( done ) => { expect ( component ) . toBeTruthy ( ) ; done ( ) ; } ) ; it ( "should render the 'Export' zones dialog" , ( done ) => { const fixture = TestBed . createComponent ( ZonesImportExportDialogComponent ) ; const compiled = fixture . debugElement . nativeElement ; const expected = JSON . stringify ( UserZonesModel . deserialize ( userSettingsData . zones . speed ) ) ; fixture . detectChanges ( ) ; expect ( component . zonesJsonData ) . toEqual ( expected ) ; expect ( compiled . querySelector ( "h2" ) . textContent ) . toContain ( "Export <Cycling Speed> zones" ) ; done ( ) ; } ) ; } ) ;