@@ -15,23 +15,66 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from 'react' ;
18
+ import { mocked } from 'jest-mock' ;
18
19
import { mount } from 'enzyme' ;
19
20
20
21
import '../../../skinned-sdk' ;
21
22
import 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
+ ) ;
22
41
23
42
describe ( '<LeftPanelLiveShareWarning />' , ( ) => {
24
43
const defaultProps = { } ;
25
44
const getComponent = ( props = { } ) =>
26
45
mount ( < LeftPanelLiveShareWarning { ...defaultProps } { ...props } /> ) ;
27
46
28
- it ( 'renders correctly when not minimized ' , ( ) => {
47
+ it ( 'renders nothing when user has no live beacons ' , ( ) => {
29
48
const component = getComponent ( ) ;
30
- expect ( component ) . toMatchSnapshot ( ) ;
49
+ expect ( component . html ( ) ) . toBe ( null ) ;
31
50
} ) ;
32
51
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
+ } ) ;
36
79
} ) ;
37
80
} ) ;
0 commit comments