@@ -34,6 +34,7 @@ jest.mock('../../../../src/stores/OwnBeaconStore', () => {
34
34
public getBeaconById = jest . fn ( ) ;
35
35
public getLiveBeaconIds = jest . fn ( ) . mockReturnValue ( [ ] ) ;
36
36
public readonly beaconUpdateErrors = new Map < BeaconIdentifier , Error > ( ) ;
37
+ public readonly beacons = new Map < BeaconIdentifier , Beacon > ( ) ;
37
38
}
38
39
return {
39
40
// @ts -ignore
@@ -103,6 +104,10 @@ describe('<LeftPanelLiveShareWarning />', () => {
103
104
mocked ( OwnBeaconStore . instance ) . getLiveBeaconIds . mockReturnValue ( [ beacon2 . identifier , beacon1 . identifier ] ) ;
104
105
} ) ;
105
106
107
+ afterAll ( ( ) => {
108
+ jest . spyOn ( document , 'addEventListener' ) . mockRestore ( ) ;
109
+ } ) ;
110
+
106
111
it ( 'renders correctly when not minimized' , ( ) => {
107
112
const component = getComponent ( ) ;
108
113
expect ( component ) . toMatchSnapshot ( ) ;
@@ -195,6 +200,24 @@ describe('<LeftPanelLiveShareWarning />', () => {
195
200
expect ( component . html ( ) ) . toBe ( null ) ;
196
201
} ) ;
197
202
203
+ it ( 'refreshes beacon liveness monitors when pagevisibilty changes to visible' , ( ) => {
204
+ OwnBeaconStore . instance . beacons . set ( beacon1 . identifier , beacon1 ) ;
205
+ OwnBeaconStore . instance . beacons . set ( beacon2 . identifier , beacon2 ) ;
206
+ const beacon1MonitorSpy = jest . spyOn ( beacon1 , 'monitorLiveness' ) ;
207
+ const beacon2MonitorSpy = jest . spyOn ( beacon1 , 'monitorLiveness' ) ;
208
+
209
+ jest . spyOn ( document , 'addEventListener' ) . mockImplementation (
210
+ ( _e , listener ) => ( listener as EventListener ) ( new Event ( '' ) ) ,
211
+ ) ;
212
+
213
+ expect ( beacon1MonitorSpy ) . not . toHaveBeenCalled ( ) ;
214
+
215
+ getComponent ( ) ;
216
+
217
+ expect ( beacon1MonitorSpy ) . toHaveBeenCalled ( ) ;
218
+ expect ( beacon2MonitorSpy ) . toHaveBeenCalled ( ) ;
219
+ } ) ;
220
+
198
221
describe ( 'stopping errors' , ( ) => {
199
222
it ( 'renders stopping error' , ( ) => {
200
223
OwnBeaconStore . instance . beaconUpdateErrors . set ( beacon2 . identifier , new Error ( 'error' ) ) ;
0 commit comments