fix(ui): fix tests

This commit is contained in:
Salvatore Giordano
2021-10-09 20:06:27 +03:00
committed by Efthymios Sarmpanis
parent 7d90dc0cfe
commit 549f3f03d5
4 changed files with 38 additions and 12 deletions
@@ -969,7 +969,7 @@ class _MessageListViewState extends State<MessageListView> {
}
final userId = StreamChat.of(context).currentUser!.id;
final isMyMessage = message.user!.id == userId;
final isMyMessage = message.user?.id == userId;
final nextMessage = index - 1 >= 0 ? messages[index - 1] : null;
final isNextUserSame =
nextMessage != null && message.user!.id == nextMessage.user!.id;
@@ -987,7 +987,7 @@ class _MessageWidgetState extends State<MessageWidget>
return widget.usernameBuilder!(context, widget.message);
}
return Text(
widget.message.user!.name,
widget.message.user?.name ?? '',
maxLines: 1,
key: usernameKey,
style: widget.messageTheme.messageAuthorStyle,
@@ -12,21 +12,38 @@ import 'mocks.dart';
void main() {
late StreamChatClient client;
late Channel channel;
late ChannelClientState channelClientState;
late ClientState clientState;
setUp(() {
client = MockClient();
clientState = MockClientState();
when(() => client.state).thenAnswer((_) => clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'testid'));
when(() => clientState.currentUserStream)
.thenAnswer((_) => Stream.value(OwnUser(id: 'testid')));
channel = MockChannel();
when(() => channel.on(any(), any(), any(), any()))
.thenAnswer((_) => const Stream.empty());
final channelClientState = MockChannelState();
channelClientState = MockChannelState();
when(() => channel.state).thenReturn(channelClientState);
when(() => channelClientState.threadsStream)
.thenAnswer((_) => const Stream.empty());
when(() => channelClientState.messagesStream)
.thenAnswer((_) => const Stream.empty());
when(() => channelClientState.messages)
.thenReturn([Message(text: 'Hello World!')]);
when(() => channelClientState.messages).thenReturn([]);
when(() => channelClientState.isUpToDateStream)
.thenAnswer((_) => Stream.value(true));
when(() => channelClientState.isUpToDate).thenReturn(true);
when(() => channelClientState.unreadCountStream)
.thenAnswer((_) => Stream.value(0));
when(() => channelClientState.unreadCount).thenReturn(0);
when(() => channelClientState.readStream)
.thenAnswer((_) => const Stream.empty());
when(() => channelClientState.read).thenReturn([]);
when(() => channelClientState.membersStream)
.thenAnswer((_) => const Stream.empty());
when(() => channelClientState.members).thenReturn([]);
});
// https://github.com/GetStream/stream-chat-flutter/issues/674
@@ -54,6 +71,11 @@ void main() {
testWidgets('renders empty message list view with custom background',
(tester) async {
when(() => channelClientState.messagesStream)
.thenAnswer((_) => Stream.value([Message(text: 'Hello world!')]));
when(() => channelClientState.messages)
.thenReturn([Message(text: 'Hello world!')]);
const emptyWidgetKey = Key('empty_widget');
await tester.pumpWidget(
@@ -63,12 +85,14 @@ void main() {
child: StreamChat(
client: client,
streamChatThemeData: StreamChatThemeData.light().copyWith(
messageListViewTheme: const MessageListViewThemeData(
backgroundColor: Colors.grey,
backgroundImage: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
))),
messageListViewTheme: const MessageListViewThemeData(
backgroundColor: Colors.grey,
backgroundImage: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
),
),
),
child: StreamChannel(
channel: channel,
child: MessageListView(
@@ -82,7 +106,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(MessageListView), findsOneWidget);
expect(find.byKey(emptyWidgetKey), findsOneWidget);
expect(find.byKey(emptyWidgetKey), findsNothing);
expect(find.byType(DecorationImage, skipOffstage: false), findsOneWidget);
});
}
@@ -5,6 +5,8 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
class MockClient extends Mock implements StreamChatClient {
MockClient() {
when(() => wsConnectionStatus).thenReturn(ConnectionStatus.connected);
when(() => wsConnectionStatusStream)
.thenAnswer((_) => Stream.value(ConnectionStatus.connected));
}
}