@@ -16,8 +16,7 @@ limitations under the License.
1616
1717import React from 'react' ;
1818import { mocked } from 'jest-mock' ;
19- // eslint-disable-next-line deprecate/import
20- import { mount } from 'enzyme' ;
19+ import { fireEvent , render } from "@testing-library/react" ;
2120import { act } from 'react-dom/test-utils' ;
2221import { Beacon , BeaconIdentifier } from 'matrix-js-sdk/src/matrix' ;
2322
@@ -48,9 +47,7 @@ jest.mock('../../../../src/stores/OwnBeaconStore', () => {
4847) ;
4948
5049describe ( '<LeftPanelLiveShareWarning />' , ( ) => {
51- const defaultProps = { } ;
52- const getComponent = ( props = { } ) =>
53- mount ( < LeftPanelLiveShareWarning { ...defaultProps } { ...props } /> ) ;
50+ const getComponent = ( props = { } ) => render ( < LeftPanelLiveShareWarning { ...props } /> ) ;
5451
5552 const roomId1 = '!room1:server' ;
5653 const roomId2 = '!room2:server' ;
@@ -85,8 +82,8 @@ describe('<LeftPanelLiveShareWarning />', () => {
8582 ) ) ;
8683
8784 it ( 'renders nothing when user has no live beacons' , ( ) => {
88- const component = getComponent ( ) ;
89- expect ( component . html ( ) ) . toBe ( null ) ;
85+ const { container } = getComponent ( ) ;
86+ expect ( container . innerHTML ) . toBeFalsy ( ) ;
9087 } ) ;
9188
9289 describe ( 'when user has live location monitor' , ( ) => {
@@ -110,17 +107,15 @@ describe('<LeftPanelLiveShareWarning />', () => {
110107 } ) ;
111108
112109 it ( 'renders correctly when not minimized' , ( ) => {
113- const component = getComponent ( ) ;
114- expect ( component ) . toMatchSnapshot ( ) ;
110+ const { asFragment } = getComponent ( ) ;
111+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
115112 } ) ;
116113
117114 it ( 'goes to room of latest beacon when clicked' , ( ) => {
118- const component = getComponent ( ) ;
115+ const { container } = getComponent ( ) ;
119116 const dispatchSpy = jest . spyOn ( dispatcher , 'dispatch' ) ;
120117
121- act ( ( ) => {
122- component . simulate ( 'click' ) ;
123- } ) ;
118+ fireEvent . click ( container . querySelector ( "[role=button]" ) ) ;
124119
125120 expect ( dispatchSpy ) . toHaveBeenCalledWith ( {
126121 action : Action . ViewRoom ,
@@ -134,28 +129,26 @@ describe('<LeftPanelLiveShareWarning />', () => {
134129 } ) ;
135130
136131 it ( 'renders correctly when minimized' , ( ) => {
137- const component = getComponent ( { isMinimized : true } ) ;
138- expect ( component ) . toMatchSnapshot ( ) ;
132+ const { asFragment } = getComponent ( { isMinimized : true } ) ;
133+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
139134 } ) ;
140135
141136 it ( 'renders location publish error' , ( ) => {
142137 mocked ( OwnBeaconStore . instance ) . getLiveBeaconIdsWithLocationPublishError . mockReturnValue (
143138 [ beacon1 . identifier ] ,
144139 ) ;
145- const component = getComponent ( ) ;
146- expect ( component ) . toMatchSnapshot ( ) ;
140+ const { asFragment } = getComponent ( ) ;
141+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
147142 } ) ;
148143
149144 it ( 'goes to room of latest beacon with location publish error when clicked' , ( ) => {
150145 mocked ( OwnBeaconStore . instance ) . getLiveBeaconIdsWithLocationPublishError . mockReturnValue (
151146 [ beacon1 . identifier ] ,
152147 ) ;
153- const component = getComponent ( ) ;
148+ const { container } = getComponent ( ) ;
154149 const dispatchSpy = jest . spyOn ( dispatcher , 'dispatch' ) ;
155150
156- act ( ( ) => {
157- component . simulate ( 'click' ) ;
158- } ) ;
151+ fireEvent . click ( container . querySelector ( "[role=button]" ) ) ;
159152
160153 expect ( dispatchSpy ) . toHaveBeenCalledWith ( {
161154 action : Action . ViewRoom ,
@@ -172,9 +165,9 @@ describe('<LeftPanelLiveShareWarning />', () => {
172165 mocked ( OwnBeaconStore . instance ) . getLiveBeaconIdsWithLocationPublishError . mockReturnValue (
173166 [ beacon1 . identifier ] ,
174167 ) ;
175- const component = getComponent ( ) ;
168+ const { container , rerender } = getComponent ( ) ;
176169 // error mode
177- expect ( component . find ( '.mx_LeftPanelLiveShareWarning' ) . at ( 0 ) . text ( ) ) . toEqual (
170+ expect ( container . querySelector ( '.mx_LeftPanelLiveShareWarning' ) . textContent ) . toEqual (
178171 'An error occurred whilst sharing your live location' ,
179172 ) ;
180173
@@ -183,28 +176,28 @@ describe('<LeftPanelLiveShareWarning />', () => {
183176 OwnBeaconStore . instance . emit ( OwnBeaconStoreEvent . LocationPublishError , 'abc' ) ;
184177 } ) ;
185178
186- component . setProps ( { } ) ;
179+ rerender ( < LeftPanelLiveShareWarning /> ) ;
187180
188181 // default mode
189- expect ( component . find ( '.mx_LeftPanelLiveShareWarning' ) . at ( 0 ) . text ( ) ) . toEqual (
182+ expect ( container . querySelector ( '.mx_LeftPanelLiveShareWarning' ) . textContent ) . toEqual (
190183 'You are sharing your live location' ,
191184 ) ;
192185 } ) ;
193186
194187 it ( 'removes itself when user stops having live beacons' , async ( ) => {
195- const component = getComponent ( { isMinimized : true } ) ;
188+ const { container , rerender } = getComponent ( { isMinimized : true } ) ;
196189 // started out rendered
197- expect ( component . html ( ) ) . toBeTruthy ( ) ;
190+ expect ( container . innerHTML ) . toBeTruthy ( ) ;
198191
199192 act ( ( ) => {
200193 mocked ( OwnBeaconStore . instance ) . isMonitoringLiveLocation = false ;
201194 OwnBeaconStore . instance . emit ( OwnBeaconStoreEvent . MonitoringLivePosition ) ;
202195 } ) ;
203196
204197 await flushPromises ( ) ;
205- component . setProps ( { } ) ;
198+ rerender ( < LeftPanelLiveShareWarning /> ) ;
206199
207- expect ( component . html ( ) ) . toBe ( null ) ;
200+ expect ( container . innerHTML ) . toBeFalsy ( ) ;
208201 } ) ;
209202
210203 it ( 'refreshes beacon liveness monitors when pagevisibilty changes to visible' , ( ) => {
@@ -228,43 +221,41 @@ describe('<LeftPanelLiveShareWarning />', () => {
228221 describe ( 'stopping errors' , ( ) => {
229222 it ( 'renders stopping error' , ( ) => {
230223 OwnBeaconStore . instance . beaconUpdateErrors . set ( beacon2 . identifier , new Error ( 'error' ) ) ;
231- const component = getComponent ( ) ;
232- expect ( component . text ( ) ) . toEqual ( 'An error occurred while stopping your live location' ) ;
224+ const { container } = getComponent ( ) ;
225+ expect ( container . textContent ) . toEqual ( 'An error occurred while stopping your live location' ) ;
233226 } ) ;
234227
235228 it ( 'starts rendering stopping error on beaconUpdateError emit' , ( ) => {
236- const component = getComponent ( ) ;
229+ const { container } = getComponent ( ) ;
237230 // no error
238- expect ( component . text ( ) ) . toEqual ( 'You are sharing your live location' ) ;
231+ expect ( container . textContent ) . toEqual ( 'You are sharing your live location' ) ;
239232
240233 act ( ( ) => {
241234 OwnBeaconStore . instance . beaconUpdateErrors . set ( beacon2 . identifier , new Error ( 'error' ) ) ;
242235 OwnBeaconStore . instance . emit ( OwnBeaconStoreEvent . BeaconUpdateError , beacon2 . identifier , true ) ;
243236 } ) ;
244237
245- expect ( component . text ( ) ) . toEqual ( 'An error occurred while stopping your live location' ) ;
238+ expect ( container . textContent ) . toEqual ( 'An error occurred while stopping your live location' ) ;
246239 } ) ;
247240
248241 it ( 'renders stopping error when beacons have stopping and location errors' , ( ) => {
249242 mocked ( OwnBeaconStore . instance ) . getLiveBeaconIdsWithLocationPublishError . mockReturnValue (
250243 [ beacon1 . identifier ] ,
251244 ) ;
252245 OwnBeaconStore . instance . beaconUpdateErrors . set ( beacon2 . identifier , new Error ( 'error' ) ) ;
253- const component = getComponent ( ) ;
254- expect ( component . text ( ) ) . toEqual ( 'An error occurred while stopping your live location' ) ;
246+ const { container } = getComponent ( ) ;
247+ expect ( container . textContent ) . toEqual ( 'An error occurred while stopping your live location' ) ;
255248 } ) ;
256249
257250 it ( 'goes to room of latest beacon with stopping error when clicked' , ( ) => {
258251 mocked ( OwnBeaconStore . instance ) . getLiveBeaconIdsWithLocationPublishError . mockReturnValue (
259252 [ beacon1 . identifier ] ,
260253 ) ;
261254 OwnBeaconStore . instance . beaconUpdateErrors . set ( beacon2 . identifier , new Error ( 'error' ) ) ;
262- const component = getComponent ( ) ;
255+ const { container } = getComponent ( ) ;
263256 const dispatchSpy = jest . spyOn ( dispatcher , 'dispatch' ) ;
264257
265- act ( ( ) => {
266- component . simulate ( 'click' ) ;
267- } ) ;
258+ fireEvent . click ( container . querySelector ( "[role=button]" ) ) ;
268259
269260 expect ( dispatchSpy ) . toHaveBeenCalledWith ( {
270261 action : Action . ViewRoom ,
0 commit comments