-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...t/builder/voice_recording_attachment_builder/stream_voice_recording_list_player_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
||
void main() { | ||
group('StreamVoiceRecordingListPlayer', () { | ||
const totalDuration = Duration(seconds: 20); | ||
|
||
testWidgets('should show the loading widget', (tester) async { | ||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: const StreamVoiceRecordingListPlayer( | ||
playList: [ | ||
PlayListItem( | ||
duration: totalDuration, | ||
waveForm: [0.1, 0.2, 0.3], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(StreamVoiceRecordingLoading), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show the player widget', (tester) async { | ||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: const StreamVoiceRecordingListPlayer( | ||
playList: [ | ||
PlayListItem( | ||
assetUrl: 'url', | ||
duration: totalDuration, | ||
waveForm: [0.1, 0.2, 0.3], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(StreamVoiceRecordingPlayer), findsOneWidget); | ||
}); | ||
}); | ||
} |
20 changes: 20 additions & 0 deletions
20
...hment/builder/voice_recording_attachment_builder/stream_voice_recording_loading_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
||
void main() { | ||
group('StreamVoiceRecordingLoading', () { | ||
testWidgets('should show a progress indicator', (tester) async { | ||
await tester.pumpWidget( | ||
StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: const StreamVoiceRecordingLoading(), | ||
), | ||
); | ||
|
||
expect(find.byType(CircularProgressIndicator), findsOneWidget); | ||
}); | ||
}); | ||
} |
132 changes: 132 additions & 0 deletions
132
...chment/builder/voice_recording_attachment_builder/stream_voice_recording_player_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:just_audio/just_audio.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
||
class MockAudioPlayer extends Mock implements AudioPlayer { | ||
@override | ||
Future<void> dispose() async {} | ||
} | ||
|
||
void main() { | ||
group('StreamVoiceRecordingPlayer', () { | ||
const totalDuration = Duration(seconds: 20); | ||
|
||
testWidgets('should show the total duration', (tester) async { | ||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: StreamVoiceRecordingPlayer( | ||
player: AudioPlayer(), | ||
duration: totalDuration, | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text(totalDuration.toMinutesAndSeconds()), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show the current duration', (tester) async { | ||
const aSecondLater = Duration(seconds: 1); | ||
final durationStream = StreamController<Duration>.broadcast(); | ||
final audioPlayer = MockAudioPlayer(); | ||
when(() => audioPlayer.positionStream) | ||
.thenAnswer((_) => durationStream.stream); | ||
when(() => audioPlayer.playing).thenReturn(true); | ||
when(() => audioPlayer.playingStream) | ||
.thenAnswer((_) => Stream.value(true)); | ||
when(() => audioPlayer.currentIndex).thenReturn(0); | ||
when(() => audioPlayer.currentIndexStream) | ||
.thenAnswer((_) => Stream.value(0)); | ||
when(() => audioPlayer.playerStateStream).thenAnswer( | ||
(_) => Stream.value(PlayerState(true, ProcessingState.completed))); | ||
|
||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: StreamVoiceRecordingPlayer( | ||
player: audioPlayer, | ||
duration: totalDuration, | ||
), | ||
), | ||
), | ||
); | ||
await tester.pump(const Duration(milliseconds: 200)); | ||
durationStream.add(aSecondLater); | ||
await tester.pump(const Duration(milliseconds: 200)); | ||
expect(find.text(aSecondLater.toMinutesAndSeconds()), findsOneWidget); | ||
durationStream.close(); | ||
}); | ||
|
||
testWidgets('should show the file size if passed', (tester) async { | ||
const fileSize = 1024; | ||
|
||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: StreamVoiceRecordingPlayer( | ||
player: AudioPlayer(), | ||
duration: totalDuration, | ||
fileSize: fileSize, | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text(fileSize.toHumanReadableSize()), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show the default speed value', (tester) async { | ||
final audioPlayer = MockAudioPlayer(); | ||
|
||
when(() => audioPlayer.positionStream) | ||
.thenAnswer((_) => Stream.value(const Duration(milliseconds: 100))); | ||
when(() => audioPlayer.playingStream) | ||
.thenAnswer((_) => Stream.value(true)); | ||
when(() => audioPlayer.playing).thenReturn(true); | ||
when(() => audioPlayer.currentIndex).thenReturn(0); | ||
when(() => audioPlayer.currentIndexStream) | ||
.thenAnswer((_) => Stream.value(0)); | ||
when(() => audioPlayer.speedStream).thenAnswer( | ||
(_) => Stream.value(1), | ||
); | ||
when(() => audioPlayer.playerStateStream).thenAnswer( | ||
(_) => Stream.value(PlayerState(true, ProcessingState.completed))); | ||
|
||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: StreamVoiceRecordingPlayer( | ||
player: audioPlayer, | ||
duration: totalDuration, | ||
), | ||
), | ||
), | ||
); | ||
|
||
await tester.pump(const Duration(milliseconds: 200)); | ||
|
||
expect(find.text('1.0x'), findsOneWidget); | ||
}); | ||
}); | ||
} |
53 changes: 53 additions & 0 deletions
53
...t/builder/voice_recording_attachment_builder/voice_recording_attachment_builder_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
||
import '../../../mocks.dart'; | ||
|
||
void main() { | ||
group('VoiceRecordingAttachmentBuilder', () { | ||
test('should handle voiceRecording attachment type', () { | ||
final builder = VoiceRecordingAttachmentBuilder(); | ||
final message = MocMessage(); | ||
final attachments = { | ||
'voiceRecording': [Attachment()], | ||
}; | ||
|
||
expect(builder.canHandle(message, attachments), true); | ||
}); | ||
|
||
test('should not handle other than voiceRecording attachment type', () { | ||
final builder = VoiceRecordingAttachmentBuilder(); | ||
final message = MocMessage(); | ||
final attachments = { | ||
'gify': [Attachment()], | ||
}; | ||
|
||
expect(builder.canHandle(message, attachments), false); | ||
}); | ||
|
||
testWidgets('should build StreamVoiceRecordingListPlayer', (tester) async { | ||
final builder = VoiceRecordingAttachmentBuilder(); | ||
final message = MocMessage(); | ||
final attachments = { | ||
'voiceRecording': [Attachment()], | ||
}; | ||
|
||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: StreamChatTheme( | ||
data: StreamChatThemeData( | ||
voiceRecordingTheme: StreamVoiceRecordingThemeData.dark(), | ||
), | ||
child: Builder(builder: (context) { | ||
return builder.build(context, message, attachments); | ||
}), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(StreamVoiceRecordingListPlayer), findsOneWidget); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters