Skip to content

Commit

Permalink
Adding test for file and audio
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroBorgesFerreira committed Mar 23, 2023
1 parent 34b4ccd commit 3cc53a8
Showing 1 changed file with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,95 @@ void main() {
},
);

testWidgets(
'Test that is possible to add a audio message with file attachments too',
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
final channelState = MockChannelState();
final lastMessageAt = DateTime.parse('2020-06-22 12:00:00');

when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
when(() => channel.lastMessageAt).thenReturn(lastMessageAt);
when(() => channel.state).thenReturn(channelState);
when(() => channel.client).thenReturn(client);
when(() => channel.isMuted).thenReturn(false);
when(() => channel.isMutedStream).thenAnswer((i) => Stream.value(false));
when(() => channel.extraDataStream).thenAnswer(
(i) => Stream.value({
'name': 'test',
}),
);
when(() => channel.extraData).thenReturn({
'name': 'test',
});
when(() => channelState.membersStream).thenAnswer(
(i) => Stream.value([
Member(
userId: 'user-id',
user: User(id: 'user-id'),
)
]),
);
when(() => channelState.members).thenReturn([
Member(
userId: 'user-id',
user: User(id: 'user-id'),
),
]);
when(() => channelState.messages).thenReturn([
Message(
text: 'hello',
user: User(id: 'other-user'),
)
]);
when(() => channelState.messagesStream).thenAnswer(
(i) => Stream.value([
Message(
text: 'hello',
user: User(id: 'other-user'),
)
]),
);

final messageInputController = StreamMessageInputController();

await tester.pumpWidget(MaterialApp(
home: StreamChat(
client: client,
child: StreamChannel(
channel: channel,
child: Scaffold(
body: StreamMessageInput(
enableAudioRecord: false,
messageInputController: messageInputController,
),
),
),
),
));

messageInputController.attachments += [
Attachment(type: 'audio_recording'),
Attachment(type: 'file'),
];

await tester.pump();

expect(
find.byWidgetPredicate((widget) => widget is AudioPlayerComposeMessage),
findsOneWidget,
);

expect(
find.byWidgetPredicate((widget) => widget is StreamFileAttachment),
findsOneWidget,
);
},
);

testWidgets(
'Test that start the audio input correctly appears',
(WidgetTester tester) async {
Expand Down

0 comments on commit 3cc53a8

Please sign in to comment.