@@ -15,23 +15,66 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18+ import { mocked } from 'jest-mock' ;
1819import { mount } from 'enzyme' ;
1920
2021import '../../../skinned-sdk' ;
2122import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning' ;
23+ import { OwnBeaconStore , OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore' ;
24+ import { flushPromises } from '../../../test-utils' ;
25+
26+ jest . mock ( '../../../../src/stores/OwnBeaconStore' , ( ) => {
27+ // eslint-disable-next-line @typescript-eslint/no-var-requires
28+ const EventEmitter = require ( "events" ) ;
29+ class MockOwnBeaconStore extends EventEmitter {
30+ public hasLiveBeacons = jest . fn ( ) . mockReturnValue ( false ) ;
31+ }
32+ return {
33+ // @ts -ignore
34+ ...jest . requireActual ( '../../../../src/stores/OwnBeaconStore' ) ,
35+ OwnBeaconStore : {
36+ instance : new MockOwnBeaconStore ( ) as unknown as OwnBeaconStore ,
37+ } ,
38+ } ;
39+ } ,
40+ ) ;
2241
2342describe ( '<LeftPanelLiveShareWarning />' , ( ) => {
2443 const defaultProps = { } ;
2544 const getComponent = ( props = { } ) =>
2645 mount ( < LeftPanelLiveShareWarning { ...defaultProps } { ...props } /> ) ;
2746
28- it ( 'renders correctly when not minimized ' , ( ) => {
47+ it ( 'renders nothing when user has no live beacons ' , ( ) => {
2948 const component = getComponent ( ) ;
30- expect ( component ) . toMatchSnapshot ( ) ;
49+ expect ( component . html ( ) ) . toBe ( null ) ;
3150 } ) ;
3251
33- it ( 'renders correctly when minimized' , ( ) => {
34- const component = getComponent ( { isMinimized : true } ) ;
35- expect ( component ) . toMatchSnapshot ( ) ;
52+ describe ( 'when user has live beacons' , ( ) => {
53+ beforeEach ( ( ) => {
54+ mocked ( OwnBeaconStore . instance ) . hasLiveBeacons . mockReturnValue ( true ) ;
55+ } ) ;
56+ it ( 'renders correctly when not minimized' , ( ) => {
57+ const component = getComponent ( ) ;
58+ expect ( component ) . toMatchSnapshot ( ) ;
59+ } ) ;
60+
61+ it ( 'renders correctly when minimized' , ( ) => {
62+ const component = getComponent ( { isMinimized : true } ) ;
63+ expect ( component ) . toMatchSnapshot ( ) ;
64+ } ) ;
65+
66+ it ( 'removes itself when user stops having live beacons' , async ( ) => {
67+ const component = getComponent ( { isMinimized : true } ) ;
68+ // started out rendered
69+ expect ( component . html ( ) ) . toBeTruthy ( ) ;
70+
71+ mocked ( OwnBeaconStore . instance ) . hasLiveBeacons . mockReturnValue ( false ) ;
72+ OwnBeaconStore . instance . emit ( OwnBeaconStoreEvent . LivenessChange , false ) ;
73+
74+ await flushPromises ( ) ;
75+ component . setProps ( { } ) ;
76+
77+ expect ( component . html ( ) ) . toBe ( null ) ;
78+ } ) ;
3679 } ) ;
3780} ) ;
0 commit comments