Merge branch 'develop' into feat/positioned-list-experiment

This commit is contained in:
Gordon Hayes
2021-10-18 11:22:01 +02:00
97 changed files with 1226 additions and 879 deletions
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
@@ -8,13 +9,21 @@ 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.client).thenReturn(client);
when(() => channel.state).thenReturn(channelClientState);
when(() => channelClientState.threadsStream)
.thenAnswer((_) => const Stream.empty());
@@ -24,6 +33,15 @@ void main() {
when(() => channelClientState.isUpToDate).thenReturn(true);
when(() => channelClientState.isUpToDateStream)
.thenAnswer((_) => Stream.value(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
@@ -48,4 +66,65 @@ void main() {
expect(find.byType(MessageListView), findsOneWidget);
expect(find.byKey(emptyWidgetKey), findsOneWidget);
});
testWidgets('renders a non empty message list view with custom background',
(tester) async {
final message = Message(
id: 'message1',
text: 'Hello world!',
user: User(
id: 'user',
name: 'Test User',
),
);
when(() => channelClientState.messagesStream).thenAnswer(
(_) => Stream.value([message]),
);
when(() => channelClientState.messages).thenReturn([message]);
const nonEmptyWidgetKey = Key('non_empty_widget');
await tester.runAsync(() async {
await tester.pumpWidget(
MaterialApp(
home: DefaultAssetBundle(
bundle: rootBundle,
child: StreamChat(
client: client,
streamChatThemeData: StreamChatThemeData.light().copyWith(
messageListViewTheme: const MessageListViewThemeData(
backgroundColor: Colors.grey,
backgroundImage: DecorationImage(
image: AssetImage('images/placeholder.png'),
fit: BoxFit.none,
),
),
),
child: StreamChannel(
channel: channel,
child: const MessageListView(
key: nonEmptyWidgetKey,
),
),
),
),
),
);
await tester.pumpAndSettle();
});
bool findBackground(Widget widget) =>
widget is Container &&
widget.decoration is BoxDecoration &&
(widget.decoration! as BoxDecoration).image != null;
expect(find.byType(MessageListView), findsOneWidget);
expect(find.byKey(nonEmptyWidgetKey), findsOneWidget);
expect(
find.byWidgetPredicate(
findBackground,
description: 'findBackground',
),
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));
}
}
@@ -59,7 +59,7 @@ final _channelPreviewThemeControl = ChannelPreviewThemeData(
color: const Color(0xff7A7A7A),
),
lastMessageAtStyle: TextTheme.light().footnote.copyWith(
color: ColorTheme.light().textHighEmphasis.withOpacity(.5),
color: ColorTheme.light().textHighEmphasis.withOpacity(0.5),
),
indicatorIconSize: 16,
);
@@ -83,7 +83,7 @@ final _channelPreviewThemeControlMidLerp = ChannelPreviewThemeData(
fontSize: 12,
),
lastMessageAtStyle: TextTheme.light().footnote.copyWith(
color: const Color(0x807f7f7f).withOpacity(.5),
color: const Color(0x807f7f7f).withOpacity(0.5),
),
indicatorIconSize: 16,
);
@@ -102,7 +102,7 @@ final _channelPreviewThemeControlDark = ChannelPreviewThemeData(
color: const Color(0xff7A7A7A),
),
lastMessageAtStyle: TextTheme.dark().footnote.copyWith(
color: ColorTheme.dark().textHighEmphasis.withOpacity(.5),
color: ColorTheme.dark().textHighEmphasis.withOpacity(0.5),
),
indicatorIconSize: 16,
);
@@ -109,6 +109,37 @@ void main() {
expect(messageListViewTheme.backgroundColor,
_messageListViewThemeDataControlDark.backgroundColor);
});
testWidgets(
'Pass backgroundImage to MessageListViewThemeData return backgroundImage',
(WidgetTester tester) async {
late BuildContext _context;
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => StreamChat(
client: MockStreamChatClient(),
streamChatThemeData: StreamChatThemeData.light()
.copyWith(messageListViewTheme: _messageListViewThemeDataImage),
child: child,
),
home: Builder(
builder: (BuildContext context) {
_context = context;
return Scaffold(
body: StreamChannel(
channel: MockChannel(),
child: const MessageListView(),
),
);
},
),
),
);
final messageListViewTheme = MessageListViewTheme.of(_context);
expect(messageListViewTheme.backgroundImage,
_messageListViewThemeDataImage.backgroundImage);
});
}
final _messageListViewThemeDataControl = MessageListViewThemeData(
@@ -122,3 +153,10 @@ const _messageListViewThemeDataControlHalfLerp = MessageListViewThemeData(
final _messageListViewThemeDataControlDark = MessageListViewThemeData(
backgroundColor: ColorTheme.dark().barsBg,
);
const _messageListViewThemeDataImage = MessageListViewThemeData(
backgroundImage: DecorationImage(
image: AssetImage('example/assets/background_doodle.png'),
fit: BoxFit.cover,
),
);