import { ComponentFixture , TestBed } from "@angular/core/testing" ; import { ZoneToolBarComponent } from "./zone-tool-bar.component" ; import * as _ from "lodash" ; import { userSettingsData } from "@elevate/shared/data" ; import { CoreModule } from "../../core/core.module" ; import { SharedModule } from "../../shared/shared.module" ; import { ZoneDefinitionModel } from "../../shared/models/zone-definition.model" ; import { UserSettingsService } from "../../shared/services/user-settings/user-settings.service" ; describe ( "ZoneToolBarComponent" , ( ) => { let component ; let fixture ; let userSettingsService ; const zoneSpeedDefinition = [ { name : "Cycling Speed" , value : "speed" , units : "KPH" , step : 0.1 , min : 0 , max : 9999 , customDisplay : null } , { name : "Heart Rate" , value : "heartRate" , units : "BPM" , step : 1 , min : 0 , max : 9999 , customDisplay : null } ] ; beforeEach ( ( done ) => { TestBed . configureTestingModule ( { imports : [ CoreModule , SharedModule , ] } ) . compileComponents ( ) ; userSettingsService = TestBed . get ( UserSettingsService ) ; spyOn ( userSettingsService , "fetch" ) . and . returnValue ( Promise . resolve ( _ . cloneDeep ( userSettingsData ) ) ) ; done ( ) ; } ) ; beforeEach ( ( done ) => { fixture = TestBed . createComponent ( ZoneToolBarComponent ) ; component = fixture . componentInstance ; component . zoneDefinitions = _ . clone ( zoneSpeedDefinition ) ; component . zoneDefinitionSelected = _ . first ( _ . clone ( zoneSpeedDefinition ) ) ; component . zonesService . zoneDefinition = _ . first ( _ . clone ( zoneSpeedDefinition ) ) ; fixture . detectChanges ( ) ; done ( ) ; } ) ; it ( "should create" , ( done ) => { expect ( component ) . toBeTruthy ( ) ; done ( ) ; } ) ; it ( "should call zone service on AddLastZone" , ( done ) => { const spy = spyOn ( component . zonesService , "addLastZone" ) . and . returnValue ( Promise . resolve ( null ) ) ; const compiled = fixture . debugElement . nativeElement ; compiled . querySelector ( "#addLastZone" ) . click ( ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; done ( ) ; } ) ; it ( "should call zone service on RemoveLastZone" , ( done ) => { const spy = spyOn ( component . zonesService , "removeLastZone" ) . and . returnValue ( Promise . resolve ( null ) ) ; const compiled = fixture . debugElement . nativeElement ; compiled . querySelector ( "#removeLastZone" ) . click ( ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; done ( ) ; } ) ; it ( "should call zone service on SaveZones" , ( done ) => { const spy = spyOn ( component . zonesService , "saveZones" ) . and . returnValue ( Promise . resolve ( null ) ) ; const compiled = fixture . debugElement . nativeElement ; compiled . querySelector ( "#saveZones" ) . click ( ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; done ( ) ; } ) ; } ) ;