@@ -4,16 +4,30 @@ import 'package:flutter_test/flutter_test.dart';
44import 'package:mocktail/mocktail.dart' ;
55import 'package:record/record.dart' ;
66import 'package:stream_chat_flutter/src/audio/audio_playlist_state.dart' ;
7+ import 'package:stream_chat_flutter/src/components/message_composer/message_composer_recording_locked.dart' ;
8+ import 'package:stream_chat_flutter/src/components/message_composer/message_composer_recording_ongoing.dart' ;
79import 'package:stream_chat_flutter/stream_chat_flutter.dart' ;
810
911import '../src/fakes.dart' ;
1012import '../src/golden_theme.dart' ;
1113import '../src/mocks.dart' ;
1214
13- Widget _buildRecorderButtonScaffold ({
15+ class _MockAudioRecorder extends Mock implements AudioRecorder {}
16+
17+ StreamAudioRecorderController _makeRecorderController (AudioRecorderState initialState) {
18+ final mockRecorder = _MockAudioRecorder ();
19+ when (() => mockRecorder.onAmplitudeChanged (any ())).thenAnswer ((_) => const Stream .empty ());
20+ when (() => mockRecorder.dispose ()).thenAnswer ((_) async {});
21+ return StreamAudioRecorderController .raw (
22+ config: const RecordConfig (numChannels: 1 ),
23+ recorder: mockRecorder,
24+ initialState: initialState,
25+ );
26+ }
27+
28+ Widget _buildVoiceRecordingMessageInputScaffold ({
1429 required MockClient client,
1530 required MockChannel channel,
16- required AudioRecorderState recordState,
1731}) {
1832 return MaterialApp (
1933 theme: docsScreenshotsTheme (),
@@ -26,18 +40,21 @@ Widget _buildRecorderButtonScaffold({
2640 showLoading: false ,
2741 channel: channel,
2842 child: Scaffold (
29- body: Center (
30- child: StreamAudioRecorderButton (recordState: recordState),
43+ body: Column (
44+ children: [
45+ Expanded (child: Container ()),
46+ const StreamMessageInput (enableVoiceRecording: true ),
47+ ],
3148 ),
3249 ),
3350 ),
3451 ),
3552 );
3653}
3754
38- Widget _buildVoiceRecordingMessageInputScaffold ({
55+ Widget _buildVoiceRecorderScaffold ({
3956 required MockClient client,
40- required MockChannel channel ,
57+ required Widget child ,
4158}) {
4259 return MaterialApp (
4360 theme: docsScreenshotsTheme (),
@@ -46,16 +63,10 @@ Widget _buildVoiceRecordingMessageInputScaffold({
4663 client: client,
4764 streamChatThemeData: docsStreamChatThemeData (),
4865 connectivityStream: Stream .value ([ConnectivityResult .mobile]),
49- child: StreamChannel (
50- showLoading: false ,
51- channel: channel,
52- child: Scaffold (
53- body: Column (
54- children: [
55- Expanded (child: Container ()),
56- const StreamMessageInput (enableVoiceRecording: true ),
57- ],
58- ),
66+ child: Scaffold (
67+ body: Padding (
68+ padding: const EdgeInsets .all (8 ),
69+ child: Center (child: child),
5970 ),
6071 ),
6172 ),
@@ -74,6 +85,10 @@ void _setupChannel(MockClient client, MockClientState clientState, MockChannel c
7485void main () {
7586 TestWidgetsFlutterBinding .ensureInitialized ();
7687
88+ setUpAll (() {
89+ registerFallbackValue (Duration .zero);
90+ });
91+
7792 final originalRecordPlatform = RecordPlatform .instance;
7893 setUp (() => RecordPlatform .instance = FakeRecordPlatform ());
7994 tearDown (() => RecordPlatform .instance = originalRecordPlatform);
@@ -96,25 +111,6 @@ void main() {
96111 },
97112 );
98113
99- goldenTest (
100- 'voice recording idle with tooltip' ,
101- fileName: 'voice_recording_idle_tooltip' ,
102- constraints: const BoxConstraints .tightFor (width: 375 , height: 80 ),
103- builder: () {
104- final client = MockClient ();
105- final clientState = MockClientState ();
106- final channel = MockChannel ();
107- final channelState = MockChannelState ();
108- _setupChannel (client, clientState, channel, channelState);
109-
110- return _buildRecorderButtonScaffold (
111- client: client,
112- channel: channel,
113- recordState: const RecordStateIdle (message: 'Hold to record' ),
114- );
115- },
116- );
117-
118114 goldenTest (
119115 'voice recording enabled (mic button visible)' ,
120116 fileName: 'voice_recording_enabled' ,
@@ -136,20 +132,19 @@ void main() {
136132 goldenTest (
137133 'voice recording hold recording state' ,
138134 fileName: 'voice_recording_hold_recording' ,
139- constraints: const BoxConstraints .tightFor (width: 375 , height: 80 ),
135+ constraints: const BoxConstraints .tightFor (width: 375 , height: 56 ),
140136 builder: () {
141137 final client = MockClient ();
142- final clientState = MockClientState ();
143- final channel = MockChannel ();
144- final channelState = MockChannelState ();
145- _setupChannel (client, clientState, channel, channelState);
146138
147- return _buildRecorderButtonScaffold (
139+ final holdState = RecordStateRecordingHold (
140+ duration: const Duration (seconds: 5 ),
141+ waveform: List .generate (20 , (i) => (i % 5 ) / 5.0 ),
142+ );
143+
144+ return _buildVoiceRecorderScaffold (
148145 client: client,
149- channel: channel,
150- recordState: RecordStateRecordingHold (
151- duration: const Duration (seconds: 5 ),
152- waveform: List .generate (20 , (i) => (i % 5 ) / 5.0 ),
146+ child: StreamMessageComposerRecordingOngoing (
147+ audioRecorderController: _makeRecorderController (holdState),
153148 ),
154149 );
155150 },
@@ -158,20 +153,23 @@ void main() {
158153 goldenTest (
159154 'voice recording locked recording state' ,
160155 fileName: 'voice_recording_locked_recording' ,
161- constraints: const BoxConstraints .tightFor (width: 375 , height: 80 ),
156+ constraints: const BoxConstraints .tightFor (width: 375 , height: 120 ),
162157 builder: () {
163158 final client = MockClient ();
164- final clientState = MockClientState ();
165- final channel = MockChannel ();
166- final channelState = MockChannelState ();
167- _setupChannel (client, clientState, channel, channelState);
168159
169- return _buildRecorderButtonScaffold (
160+ final lockedState = RecordStateRecordingLocked (
161+ duration: const Duration (seconds: 12 ),
162+ waveform: List .generate (20 , (i) => (i % 5 ) / 5.0 ),
163+ );
164+
165+ return _buildVoiceRecorderScaffold (
170166 client: client,
171- channel: channel,
172- recordState: RecordStateRecordingLocked (
173- duration: const Duration (seconds: 12 ),
174- waveform: List .generate (20 , (i) => (i % 5 ) / 5.0 ),
167+ child: MessageComposerRecordingLocked (
168+ audioRecorderController: _makeRecorderController (lockedState),
169+ feedback: const AudioRecorderFeedback (),
170+ messageInputController: StreamMessageInputController (),
171+ sendMessageCallback: null ,
172+ state: lockedState,
175173 ),
176174 );
177175 },
@@ -180,46 +178,31 @@ void main() {
180178 goldenTest (
181179 'voice recording finished state' ,
182180 fileName: 'voice_recording_finished' ,
183- constraints: const BoxConstraints .tightFor (width: 375 , height: 80 ),
181+ constraints: const BoxConstraints .tightFor (width: 375 , height: 120 ),
184182 builder: () {
185183 final client = MockClient ();
186- final clientState = MockClientState ();
187- final channel = MockChannel ();
188- final channelState = MockChannelState ();
189- _setupChannel (client, clientState, channel, channelState);
190184
191- return _buildRecorderButtonScaffold (
192- client: client,
193- channel: channel,
194- recordState: RecordStateStopped (
195- audioRecording: Attachment (
196- type: 'voiceRecording' ,
197- assetUrl: 'https://example.com/recording.m4a' ,
198- extraData: const {
199- 'duration' : 15.0 ,
200- 'waveform_data' : < double > [0.1 , 0.5 , 0.9 , 0.4 , 0.2 ],
201- },
202- ),
185+ final stoppedState = RecordStateStopped (
186+ audioRecording: Attachment (
187+ type: 'voiceRecording' ,
188+ assetUrl: 'https://example.com/recording.m4a' ,
189+ uploadState: const UploadState .success (),
190+ extraData: const {
191+ 'duration' : 15.0 ,
192+ 'waveform_data' : < double > [0.1 , 0.5 , 0.9 , 0.4 , 0.2 ],
193+ },
203194 ),
204195 );
205- },
206- );
207-
208- goldenTest (
209- 'voice recording stopped state' ,
210- fileName: 'voice_recording_stopped' ,
211- constraints: const BoxConstraints .tightFor (width: 375 , height: 80 ),
212- builder: () {
213- final client = MockClient ();
214- final clientState = MockClientState ();
215- final channel = MockChannel ();
216- final channelState = MockChannelState ();
217- _setupChannel (client, clientState, channel, channelState);
218196
219- return _buildRecorderButtonScaffold (
197+ return _buildVoiceRecorderScaffold (
220198 client: client,
221- channel: channel,
222- recordState: const RecordStateIdle (),
199+ child: MessageComposerRecordingStopped (
200+ audioRecorderController: _makeRecorderController (stoppedState),
201+ feedback: const AudioRecorderFeedback (),
202+ messageInputController: StreamMessageInputController (),
203+ sendMessageCallback: null ,
204+ recordingState: stoppedState,
205+ ),
223206 );
224207 },
225208 );
0 commit comments