@@ -17,6 +17,7 @@ limitations under the License.
17
17
import { Room , Beacon , BeaconEvent } from "matrix-js-sdk/src/matrix" ;
18
18
19
19
import { OwnBeaconStore , OwnBeaconStoreEvent } from "../../src/stores/OwnBeaconStore" ;
20
+ import { resetAsyncStoreWithClient , setupAsyncStoreWithClient } from "../test-utils" ;
20
21
import { makeBeaconInfoEvent } from "../test-utils/beacon" ;
21
22
import { getMockClientWithEventEmitter } from "../test-utils/client" ;
22
23
@@ -69,15 +70,26 @@ describe('OwnBeaconStore', () => {
69
70
} ;
70
71
71
72
const makeOwnBeaconStore = async ( ) => {
72
- const store = new OwnBeaconStore ( ) ;
73
- // @ts -ignore
74
- await store . onReady ( ) ;
73
+ const store = OwnBeaconStore . instance ;
74
+ // await resetAsyncStoreWithClient(store)
75
+
76
+ await setupAsyncStoreWithClient ( store , mockClient ) ;
75
77
return store ;
76
78
} ;
77
79
78
80
beforeEach ( ( ) => {
79
81
mockClient . getVisibleRooms . mockReturnValue ( [ ] ) ;
80
82
jest . spyOn ( global . Date , 'now' ) . mockReturnValue ( now ) ;
83
+ jest . spyOn ( OwnBeaconStore . instance , 'emit' ) . mockRestore ( ) ;
84
+ } ) ;
85
+
86
+ afterEach ( async ( ) => {
87
+ await resetAsyncStoreWithClient ( OwnBeaconStore . instance ) ;
88
+ } ) ;
89
+
90
+ it ( 'works' , async ( ) => {
91
+ const store = await makeOwnBeaconStore ( ) ;
92
+ expect ( store . hasLiveBeacons ( ) ) . toBe ( false ) ;
81
93
} ) ;
82
94
83
95
describe ( 'onReady()' , ( ) => {
@@ -112,6 +124,31 @@ describe('OwnBeaconStore', () => {
112
124
} ) ;
113
125
} ) ;
114
126
127
+ describe ( 'onNotReady()' , ( ) => {
128
+ it ( 'removes listeners' , async ( ) => {
129
+ const store = await makeOwnBeaconStore ( ) ;
130
+ const removeSpy = jest . spyOn ( mockClient , 'removeListener' ) ;
131
+ // @ts -ignore
132
+ store . onNotReady ( ) ;
133
+
134
+ expect ( removeSpy . mock . calls [ 0 ] ) . toEqual ( expect . arrayContaining ( [ BeaconEvent . LivenessChange ] ) ) ;
135
+ expect ( removeSpy . mock . calls [ 1 ] ) . toEqual ( expect . arrayContaining ( [ BeaconEvent . New ] ) ) ;
136
+ } ) ;
137
+
138
+ it ( 'destroys beacons' , async ( ) => {
139
+ const [ room1 ] = makeRoomsWithStateEvents ( [
140
+ alicesRoom1BeaconInfo ,
141
+ ] ) ;
142
+ const store = await makeOwnBeaconStore ( ) ;
143
+ const beacon = room1 . currentState . beacons . get ( alicesRoom1BeaconInfo . getId ( ) ) ;
144
+ const destroySpy = jest . spyOn ( beacon , 'destroy' ) ;
145
+ // @ts -ignore
146
+ store . onNotReady ( ) ;
147
+
148
+ expect ( destroySpy ) . toHaveBeenCalled ( ) ;
149
+ } ) ;
150
+ } ) ;
151
+
115
152
describe ( 'hasLiveBeacons()' , ( ) => {
116
153
beforeEach ( ( ) => {
117
154
makeRoomsWithStateEvents ( [
0 commit comments