import { TestBed } from "@angular/core/testing" ; import { ChromeEventsService } from "./chrome-events.service" ; import { CoreMessages } from "../../../../../../modules/shared/models" ; describe ( "ChromeEventsService" , ( ) => { const pluginId = "c061d18abea0" ; let service ; beforeEach ( ( done ) => { spyOn ( ChromeEventsService , "getBrowserExternalMessages" ) . and . returnValue ( { addListener : ( request , sender ) => { } } ) ; spyOn ( ChromeEventsService , "getBrowserPluginId" ) . and . returnValue ( pluginId ) ; TestBed . configureTestingModule ( { providers : [ ChromeEventsService ] } ) ; service = TestBed . get ( ChromeEventsService ) ; done ( ) ; } ) ; it ( "should be created" , ( done ) => { expect ( service ) . toBeTruthy ( ) ; expect ( service . onSyncDone ) . not . toBeNull ( ) ; done ( ) ; } ) ; it ( "should handle a sync done from external messages" , ( done ) => { const expectedCallCount = 1 ; const spy = spyOn ( service . onSyncDone , "next" ) ; const message = { message : CoreMessages . ON_EXTERNAL_SYNC_DONE , results : { } } ; const senderId = pluginId ; service . onBrowserRequestReceived ( message , senderId ) ; expect ( spy ) . toHaveBeenCalledTimes ( expectedCallCount ) ; done ( ) ; } ) ; it ( "should bypass handle external messages receive if sender is not the plugin it self" , ( done ) => { const spy = spyOn ( service . onSyncDone , "next" ) ; const message = { message : CoreMessages . ON_EXTERNAL_SYNC_DONE , results : { } } ; const senderId = "fakeId" ; service . onBrowserRequestReceived ( message , senderId ) ; expect ( spy ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; } ) ;