@@ -15,7 +15,7 @@ limitations under the License.
1515*/
1616
1717import React from "react" ;
18- import { render , screen } from "@testing-library/react" ;
18+ import { act , render , screen } from "@testing-library/react" ;
1919import { mocked } from "jest-mock" ;
2020import { MatrixClient , MatrixEvent } from "matrix-js-sdk/src/matrix" ;
2121
@@ -26,12 +26,12 @@ import {
2626 VoiceBroadcastRecordingBody ,
2727 VoiceBroadcastRecordingsStore ,
2828 VoiceBroadcastRecording ,
29- shouldDisplayAsVoiceBroadcastRecordingTile ,
3029 VoiceBroadcastPlaybackBody ,
3130 VoiceBroadcastPlayback ,
3231 VoiceBroadcastPlaybacksStore ,
3332} from "../../../src/voice-broadcast" ;
3433import { mkEvent , stubClient } from "../../test-utils" ;
34+ import { RelationsHelper } from "../../../src/events/RelationsHelper" ;
3535
3636jest . mock ( "../../../src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody" , ( ) => ( {
3737 VoiceBroadcastRecordingBody : jest . fn ( ) ,
@@ -41,9 +41,7 @@ jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastPlayb
4141 VoiceBroadcastPlaybackBody : jest . fn ( ) ,
4242} ) ) ;
4343
44- jest . mock ( "../../../src/voice-broadcast/utils/shouldDisplayAsVoiceBroadcastRecordingTile" , ( ) => ( {
45- shouldDisplayAsVoiceBroadcastRecordingTile : jest . fn ( ) ,
46- } ) ) ;
44+ jest . mock ( "../../../src/events/RelationsHelper" ) ;
4745
4846describe ( "VoiceBroadcastBody" , ( ) => {
4947 const roomId = "!room:example.com" ;
@@ -111,22 +109,38 @@ describe("VoiceBroadcastBody", () => {
111109
112110 describe ( "when displaying a voice broadcast recording" , ( ) => {
113111 beforeEach ( ( ) => {
114- mocked ( shouldDisplayAsVoiceBroadcastRecordingTile ) . mockReturnValue ( true ) ;
112+ renderVoiceBroadcast ( ) ;
115113 } ) ;
116114
117115 it ( "should render a voice broadcast recording body" , ( ) => {
118- renderVoiceBroadcast ( ) ;
119116 screen . getByTestId ( "voice-broadcast-recording-body" ) ;
120117 } ) ;
118+
119+ describe ( "and the recordings ends" , ( ) => {
120+ beforeEach ( ( ) => {
121+ const stoppedEvent = mkVoiceBroadcastInfoEvent ( VoiceBroadcastInfoState . Stopped ) ;
122+ // get the RelationsHelper instanced used in VoiceBroadcastBody
123+ const relationsHelper = mocked ( RelationsHelper ) . mock . instances [ 5 ] ;
124+ act ( ( ) => {
125+ // invoke the callback of the VoiceBroadcastBody hook to simulate an ended broadcast
126+ // @ts -ignore
127+ mocked ( relationsHelper . on ) . mock . calls [ 0 ] [ 1 ] ( stoppedEvent ) ;
128+ } ) ;
129+ } ) ;
130+
131+ it ( "should render a voice broadcast playback body" , ( ) => {
132+ screen . getByTestId ( "voice-broadcast-playback-body" ) ;
133+ } ) ;
134+ } ) ;
121135 } ) ;
122136
123137 describe ( "when displaying a voice broadcast playback" , ( ) => {
124138 beforeEach ( ( ) => {
125- mocked ( shouldDisplayAsVoiceBroadcastRecordingTile ) . mockReturnValue ( false ) ;
139+ mocked ( client ) . getUserId . mockReturnValue ( "@other:example.com" ) ;
140+ renderVoiceBroadcast ( ) ;
126141 } ) ;
127142
128143 it ( "should render a voice broadcast playback body" , ( ) => {
129- renderVoiceBroadcast ( ) ;
130144 screen . getByTestId ( "voice-broadcast-playback-body" ) ;
131145 } ) ;
132146 } ) ;
0 commit comments