@@ -15,7 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from "react" ;
18
- import { render , screen } from "@testing-library/react" ;
18
+ import { act , render , screen } from "@testing-library/react" ;
19
19
import { mocked } from "jest-mock" ;
20
20
import { MatrixClient , MatrixEvent } from "matrix-js-sdk/src/matrix" ;
21
21
@@ -26,12 +26,12 @@ import {
26
26
VoiceBroadcastRecordingBody ,
27
27
VoiceBroadcastRecordingsStore ,
28
28
VoiceBroadcastRecording ,
29
- shouldDisplayAsVoiceBroadcastRecordingTile ,
30
29
VoiceBroadcastPlaybackBody ,
31
30
VoiceBroadcastPlayback ,
32
31
VoiceBroadcastPlaybacksStore ,
33
32
} from "../../../src/voice-broadcast" ;
34
33
import { mkEvent , stubClient } from "../../test-utils" ;
34
+ import { RelationsHelper } from "../../../src/events/RelationsHelper" ;
35
35
36
36
jest . mock ( "../../../src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody" , ( ) => ( {
37
37
VoiceBroadcastRecordingBody : jest . fn ( ) ,
@@ -41,9 +41,7 @@ jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastPlayb
41
41
VoiceBroadcastPlaybackBody : jest . fn ( ) ,
42
42
} ) ) ;
43
43
44
- jest . mock ( "../../../src/voice-broadcast/utils/shouldDisplayAsVoiceBroadcastRecordingTile" , ( ) => ( {
45
- shouldDisplayAsVoiceBroadcastRecordingTile : jest . fn ( ) ,
46
- } ) ) ;
44
+ jest . mock ( "../../../src/events/RelationsHelper" ) ;
47
45
48
46
describe ( "VoiceBroadcastBody" , ( ) => {
49
47
const roomId = "!room:example.com" ;
@@ -111,22 +109,38 @@ describe("VoiceBroadcastBody", () => {
111
109
112
110
describe ( "when displaying a voice broadcast recording" , ( ) => {
113
111
beforeEach ( ( ) => {
114
- mocked ( shouldDisplayAsVoiceBroadcastRecordingTile ) . mockReturnValue ( true ) ;
112
+ renderVoiceBroadcast ( ) ;
115
113
} ) ;
116
114
117
115
it ( "should render a voice broadcast recording body" , ( ) => {
118
- renderVoiceBroadcast ( ) ;
119
116
screen . getByTestId ( "voice-broadcast-recording-body" ) ;
120
117
} ) ;
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
+ } ) ;
121
135
} ) ;
122
136
123
137
describe ( "when displaying a voice broadcast playback" , ( ) => {
124
138
beforeEach ( ( ) => {
125
- mocked ( shouldDisplayAsVoiceBroadcastRecordingTile ) . mockReturnValue ( false ) ;
139
+ mocked ( client ) . getUserId . mockReturnValue ( "@other:example.com" ) ;
140
+ renderVoiceBroadcast ( ) ;
126
141
} ) ;
127
142
128
143
it ( "should render a voice broadcast playback body" , ( ) => {
129
- renderVoiceBroadcast ( ) ;
130
144
screen . getByTestId ( "voice-broadcast-playback-body" ) ;
131
145
} ) ;
132
146
} ) ;
0 commit comments