import { ComponentFixture , TestBed } from "@angular/core/testing" ; import { ZoneComponent } from "./zone.component" ; import { ZonesService } from "../shared/zones.service" ; import { ZoneChangeWhisperModel } from "../shared/zone-change-whisper.model" ; import { ZoneChangeTypeModel } from "./zone-change-type.model" ; import { SharedModule } from "../../shared/shared.module" ; import { CoreModule } from "../../core/core.module" ; describe ( "ZoneComponent" , ( ) => { let component ; let fixture ; let zonesService ; beforeEach ( ( done ) => { TestBed . configureTestingModule ( { imports : [ CoreModule , SharedModule ] } ) . compileComponents ( ) ; zonesService = TestBed . get ( ZonesService ) ; done ( ) ; } ) ; beforeEach ( ( done ) => { fixture = TestBed . createComponent ( ZoneComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; done ( ) ; } ) ; it ( "should create" , ( done ) => { expect ( component ) . toBeTruthy ( ) ; done ( ) ; } ) ; it ( "should notify properly a \"from\" zone change" , ( done ) => { const sourceId = 5 ; const zoneFrom = 50 ; const zoneTo = 75 ; const changeType = { from : true , to : false } ; const expectedChange = { sourceId : sourceId , from : true , to : false , value : zoneFrom } ; spyOn ( zonesService , "whisperZoneChange" ) . and . stub ( ) ; component . zoneId = sourceId ; component . zone = { from : zoneFrom , to : zoneTo } ; component . whisperZoneChange ( changeType ) ; expect ( zonesService . whisperZoneChange ) . toHaveBeenCalledTimes ( 1 ) ; expect ( zonesService . whisperZoneChange ) . toHaveBeenCalledWith ( expectedChange ) ; done ( ) ; } ) ; it ( "should notify properly a \"to\" zone change" , ( done ) => { const sourceId = 5 ; const zoneFrom = 50 ; const zoneTo = 75 ; const changeType = { from : false , to : true } ; const expectedChange = { sourceId : sourceId , from : false , to : true , value : zoneTo } ; spyOn ( zonesService , "whisperZoneChange" ) . and . stub ( ) ; component . zoneId = sourceId ; component . zone = { from : zoneFrom , to : zoneTo } ; component . whisperZoneChange ( changeType ) ; expect ( zonesService . whisperZoneChange ) . toHaveBeenCalledTimes ( 1 ) ; expect ( zonesService . whisperZoneChange ) . toHaveBeenCalledWith ( expectedChange ) ; done ( ) ; } ) ; it ( "should skip notify is from + to changes (On first display)" , ( done ) => { const changeType = { from : true , to : true } ; spyOn ( zonesService , "whisperZoneChange" ) . and . stub ( ) ; component . whisperZoneChange ( changeType ) ; expect ( zonesService . whisperZoneChange ) . toHaveBeenCalledTimes ( 0 ) ; done ( ) ; } ) ; } ) ;