@@ -15,20 +15,16 @@ limitations under the License.
1515*/
1616
1717import React from "react" ;
18- // eslint-disable-next-line deprecate/import
19- import { mount , ReactWrapper } from "enzyme" ;
2018import { mocked } from "jest-mock" ;
2119import { logger } from "matrix-js-sdk/src/logger" ;
22- import { act } from "react-dom/test-utils " ;
20+ import { fireEvent , render , RenderResult } from "@testing-library/react " ;
2321
2422import RecordingPlayback , { PlaybackLayout } from "../../../../src/components/views/audio_messages/RecordingPlayback" ;
2523import { Playback } from "../../../../src/audio/Playback" ;
2624import RoomContext , { TimelineRenderingType } from "../../../../src/contexts/RoomContext" ;
2725import { createAudioContext } from "../../../../src/audio/compat" ;
28- import { findByTestId , flushPromises } from "../../../test-utils" ;
29- import PlaybackWaveform from "../../../../src/components/views/audio_messages/PlaybackWaveform" ;
30- import SeekBar from "../../../../src/components/views/audio_messages/SeekBar" ;
31- import PlaybackClock from "../../../../src/components/views/audio_messages/PlaybackClock" ;
26+ import { flushPromises } from "../../../test-utils" ;
27+ import { IRoomState } from "../../../../src/components/structures/RoomView" ;
3228
3329jest . mock ( "../../../../src/audio/compat" , ( ) => ( {
3430 createAudioContext : jest . fn ( ) ,
@@ -57,12 +53,13 @@ describe("<RecordingPlayback />", () => {
5753
5854 const mockChannelData = new Float32Array ( ) ;
5955
60- const defaultRoom = { roomId : "!room:server.org" , timelineRenderingType : TimelineRenderingType . File } ;
56+ const defaultRoom = { roomId : "!room:server.org" , timelineRenderingType : TimelineRenderingType . File } as IRoomState ;
6157 const getComponent = ( props : React . ComponentProps < typeof RecordingPlayback > , room = defaultRoom ) =>
62- mount ( < RecordingPlayback { ...props } /> , {
63- wrappingComponent : RoomContext . Provider ,
64- wrappingComponentProps : { value : room } ,
65- } ) ;
58+ render (
59+ < RoomContext . Provider value = { room } >
60+ < RecordingPlayback { ...props } />
61+ </ RoomContext . Provider > ,
62+ ) ;
6663
6764 beforeEach ( ( ) => {
6865 jest . spyOn ( logger , "error" ) . mockRestore ( ) ;
@@ -71,7 +68,7 @@ describe("<RecordingPlayback />", () => {
7168 mocked ( createAudioContext ) . mockReturnValue ( mockAudioContext as unknown as AudioContext ) ;
7269 } ) ;
7370
74- const getPlayButton = ( component : ReactWrapper ) => findByTestId ( component , "play-pause-button" ) . at ( 0 ) ;
71+ const getPlayButton = ( component : RenderResult ) => component . getByTestId ( "play-pause-button" ) ;
7572
7673 it ( "renders recording playback" , ( ) => {
7774 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
@@ -82,15 +79,16 @@ describe("<RecordingPlayback />", () => {
8279 it ( "disables play button while playback is decoding" , async ( ) => {
8380 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
8481 const component = getComponent ( { playback } ) ;
85- expect ( getPlayButton ( component ) . props ( ) . disabled ) . toBeTruthy ( ) ;
82+ expect ( getPlayButton ( component ) ) . toHaveAttribute ( "disabled" ) ;
83+ expect ( getPlayButton ( component ) ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
8684 } ) ;
8785
8886 it ( "enables play button when playback is finished decoding" , async ( ) => {
8987 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
9088 const component = getComponent ( { playback } ) ;
9189 await flushPromises ( ) ;
92- component . setProps ( { } ) ;
93- expect ( getPlayButton ( component ) . props ( ) . disabled ) . toBeFalsy ( ) ;
90+ expect ( getPlayButton ( component ) ) . not . toHaveAttribute ( "disabled" ) ;
91+ expect ( getPlayButton ( component ) ) . not . toHaveAttribute ( "aria-disabled" , "true" ) ;
9492 } ) ;
9593
9694 it ( "displays error when playback decoding fails" , async ( ) => {
@@ -101,16 +99,17 @@ describe("<RecordingPlayback />", () => {
10199 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
102100 const component = getComponent ( { playback } ) ;
103101 await flushPromises ( ) ;
104- expect ( component . find ( ".text-warning" ) . length ) . toBeFalsy ( ) ;
102+ expect ( component . container . querySelector ( ".text-warning" ) ) . toBeDefined ( ) ;
105103 } ) ;
106104
107105 it ( "displays pre-prepared playback with correct playback phase" , async ( ) => {
108106 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
109107 await playback . prepare ( ) ;
110108 const component = getComponent ( { playback } ) ;
111109 // playback already decoded, button is not disabled
112- expect ( getPlayButton ( component ) . props ( ) . disabled ) . toBeFalsy ( ) ;
113- expect ( component . find ( ".text-warning" ) . length ) . toBeFalsy ( ) ;
110+ expect ( getPlayButton ( component ) ) . not . toHaveAttribute ( "disabled" ) ;
111+ expect ( getPlayButton ( component ) ) . not . toHaveAttribute ( "aria-disabled" , "true" ) ;
112+ expect ( component . container . querySelector ( ".text-warning" ) ) . toBeFalsy ( ) ;
114113 } ) ;
115114
116115 it ( "toggles playback on play pause button click" , async ( ) => {
@@ -119,9 +118,7 @@ describe("<RecordingPlayback />", () => {
119118 await playback . prepare ( ) ;
120119 const component = getComponent ( { playback } ) ;
121120
122- act ( ( ) => {
123- getPlayButton ( component ) . simulate ( "click" ) ;
124- } ) ;
121+ fireEvent . click ( getPlayButton ( component ) ) ;
125122
126123 expect ( playback . toggle ) . toHaveBeenCalled ( ) ;
127124 } ) ;
@@ -131,9 +128,9 @@ describe("<RecordingPlayback />", () => {
131128 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
132129 const component = getComponent ( { playback, layout : PlaybackLayout . Composer } ) ;
133130
134- expect ( component . find ( PlaybackClock ) . length ) . toBeTruthy ( ) ;
135- expect ( component . find ( PlaybackWaveform ) . length ) . toBeTruthy ( ) ;
136- expect ( component . find ( SeekBar ) . length ) . toBeFalsy ( ) ;
131+ expect ( component . container . querySelector ( ".mx_Clock" ) ) . toBeDefined ( ) ;
132+ expect ( component . container . querySelector ( ".mx_Waveform" ) ) . toBeDefined ( ) ;
133+ expect ( component . container . querySelector ( ".mx_SeekBar" ) ) . toBeFalsy ( ) ;
137134 } ) ;
138135 } ) ;
139136
@@ -142,18 +139,18 @@ describe("<RecordingPlayback />", () => {
142139 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
143140 const component = getComponent ( { playback, layout : PlaybackLayout . Timeline } ) ;
144141
145- expect ( component . find ( PlaybackClock ) . length ) . toBeTruthy ( ) ;
146- expect ( component . find ( PlaybackWaveform ) . length ) . toBeTruthy ( ) ;
147- expect ( component . find ( SeekBar ) . length ) . toBeTruthy ( ) ;
142+ expect ( component . container . querySelector ( ".mx_Clock" ) ) . toBeDefined ( ) ;
143+ expect ( component . container . querySelector ( ".mx_Waveform" ) ) . toBeDefined ( ) ;
144+ expect ( component . container . querySelector ( ".mx_SeekBar" ) ) . toBeDefined ( ) ;
148145 } ) ;
149146
150147 it ( "should be the default" , ( ) => {
151148 const playback = new Playback ( new ArrayBuffer ( 8 ) ) ;
152149 const component = getComponent ( { playback } ) ; // no layout set for test
153150
154- expect ( component . find ( PlaybackClock ) . length ) . toBeTruthy ( ) ;
155- expect ( component . find ( PlaybackWaveform ) . length ) . toBeTruthy ( ) ;
156- expect ( component . find ( SeekBar ) . length ) . toBeTruthy ( ) ;
151+ expect ( component . container . querySelector ( ".mx_Clock" ) ) . toBeDefined ( ) ;
152+ expect ( component . container . querySelector ( ".mx_Waveform" ) ) . toBeDefined ( ) ;
153+ expect ( component . container . querySelector ( ".mx_SeekBar" ) ) . toBeDefined ( ) ;
157154 } ) ;
158155 } ) ;
159156} ) ;
0 commit comments