@@ -16,7 +16,8 @@ limitations under the License.
1616
1717import React from "react" ;
1818// eslint-disable-next-line deprecate/import
19- import { mount } from "enzyme" ;
19+ import { render , screen , waitFor } from "@testing-library/react" ;
20+ import userEvent from "@testing-library/user-event" ;
2021import { jest } from "@jest/globals" ;
2122import { mocked , MockedObject } from "jest-mock" ;
2223import { MatrixClient } from "matrix-js-sdk/src/client" ;
@@ -33,8 +34,6 @@ import { RightPanelPhases } from "../../../src/stores/right-panel/RightPanelStor
3334import RightPanelStore from "../../../src/stores/right-panel/RightPanelStore" ;
3435import { UPDATE_EVENT } from "../../../src/stores/AsyncStore" ;
3536import { WidgetLayoutStore } from "../../../src/stores/widgets/WidgetLayoutStore" ;
36- import RoomSummaryCard from "../../../src/components/views/right_panel/RoomSummaryCard" ;
37- import MemberList from "../../../src/components/views/rooms/MemberList" ;
3837import { SdkContextClass } from "../../../src/contexts/SDKContext" ;
3938
4039const RightPanelBase = wrapInMatrixClientContext ( _RightPanel ) ;
@@ -111,15 +110,14 @@ describe("RightPanel", () => {
111110 } ) ;
112111 await viewedRoom ;
113112
114- const wrapper = mount ( < RightPanel room = { r1 } resizeNotifier = { resizeNotifier } /> ) ;
115- expect ( wrapper . find ( RoomSummaryCard ) . exists ( ) ) . toEqual ( true ) ;
113+ const { container } = render ( < RightPanel room = { r1 } resizeNotifier = { resizeNotifier } /> ) ;
114+ expect ( container . getElementsByClassName ( "mx_RoomSummaryCard" ) ) . toHaveLength ( 1 ) ;
116115
117116 const switchedPhases = waitForRpsUpdate ( ) ;
118- wrapper . find ( "AccessibleButton.mx_RoomSummaryCard_icon_people" ) . simulate ( "click" ) ;
117+ userEvent . click ( screen . getByText ( / p e o p l e / i ) ) ;
119118 await switchedPhases ;
120- wrapper . update ( ) ;
121119
122- expect ( wrapper . find ( MemberList ) . exists ( ) ) . toEqual ( true ) ;
120+ expect ( container . getElementsByClassName ( "mx_MemberList" ) ) . toHaveLength ( 1 ) ;
123121 } ) ;
124122
125123 it ( "renders info from only one room during room changes" , async ( ) => {
@@ -154,39 +152,34 @@ describe("RightPanel", () => {
154152 await spinUpStores ( ) ;
155153
156154 // Run initial render with room 1, and also running lifecycle methods
157- const wrapper = mount ( < RightPanel room = { r1 } resizeNotifier = { resizeNotifier } /> ) ;
155+ const { container , rerender } = render ( < RightPanel room = { r1 } resizeNotifier = { resizeNotifier } /> ) ;
158156 // Wait for RPS room 1 updates to fire
159157 const rpsUpdated = waitForRpsUpdate ( ) ;
160158 dis . dispatch ( {
161159 action : Action . ViewRoom ,
162160 room_id : "r1" ,
163161 } ) ;
164162 await rpsUpdated ;
163+ await waitFor ( ( ) => expect ( screen . queryByTestId ( "spinner" ) ) . not . toBeInTheDocument ( ) ) ;
165164
166- // After all that setup, now to the interesting part...
167- // We want to verify that as we change to room 2, we should always have
168- // the correct right panel state for whichever room we are showing.
169- const instance = wrapper . find ( _RightPanel ) . instance ( ) as _RightPanel ;
170- const rendered = new Promise < void > ( ( resolve ) => {
171- jest . spyOn ( instance , "render" ) . mockImplementation ( ( ) => {
172- const { props, state } = instance ;
173- if ( props . room . roomId === "r2" && state . phase === RightPanelPhases . RoomMemberList ) {
174- throw new Error ( "Tried to render room 1 state for room 2" ) ;
175- }
176- if ( props . room . roomId === "r2" && state . phase === RightPanelPhases . RoomSummary ) {
177- resolve ( ) ;
178- }
179- return null ;
180- } ) ;
181- } ) ;
165+ // room one will be in the RoomMemberList phase - confirm this is rendered
166+ expect ( container . getElementsByClassName ( "mx_MemberList" ) ) . toHaveLength ( 1 ) ;
182167
183- // Switch to room 2
168+ // wait for RPS room 2 updates to fire, then rerender
169+ const _rpsUpdated = waitForRpsUpdate ( ) ;
184170 dis . dispatch ( {
185171 action : Action . ViewRoom ,
186172 room_id : "r2" ,
187173 } ) ;
188- wrapper . setProps ( { room : r2 } ) ;
174+ await _rpsUpdated ;
175+ rerender ( < RightPanel room = { r2 } resizeNotifier = { resizeNotifier } /> ) ;
189176
190- await rendered ;
177+ // After all that setup, now to the interesting part...
178+ // We want to verify that as we change to room 2, we should always have
179+ // the correct right panel state for whichever room we are showing, so we
180+ // confirm we do not have the MemberList class on the page and that we have
181+ // the expected room title
182+ expect ( container . getElementsByClassName ( "mx_MemberList" ) ) . toHaveLength ( 0 ) ;
183+ expect ( screen . getByRole ( "heading" , { name : "r2" } ) ) . toBeInTheDocument ( ) ;
191184 } ) ;
192185} ) ;
0 commit comments