fix tests
This commit is contained in:
@@ -107,6 +107,8 @@ void main() {
|
||||
]);
|
||||
when(() => client.wsConnectionStatusStream)
|
||||
.thenAnswer((_) => Stream.value(ConnectionStatus.disconnected));
|
||||
when(() => client.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
when(() => clientState.totalUnreadCountStream)
|
||||
.thenAnswer((i) => Stream.value(1));
|
||||
|
||||
|
||||
@@ -53,15 +53,6 @@ void main() {
|
||||
)
|
||||
]));
|
||||
|
||||
when(() => channelState.typingEvents).thenAnswer((i) => [
|
||||
User(id: 'other-user', extraData: {'name': 'demo'})
|
||||
]);
|
||||
when(() => channelState.typingEventsStream)
|
||||
.thenAnswer((i) => Stream.value([
|
||||
User(id: 'other-user', extraData: {'name': 'demo'}),
|
||||
User(id: 'other-user', extraData: {'name': 'demo'}),
|
||||
]));
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: StreamChat(
|
||||
client: client,
|
||||
@@ -75,7 +66,6 @@ void main() {
|
||||
));
|
||||
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
expect(find.byType(StreamSvgIcon), findsNWidgets(8));
|
||||
expect(find.byKey(const Key('messageInputText')), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -2,7 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
|
||||
|
||||
class MockClient extends Mock implements StreamChatClient {}
|
||||
class MockClient extends Mock implements StreamChatClient {
|
||||
MockClient() {
|
||||
when(() => wsConnectionStatus).thenReturn(ConnectionStatus.connected);
|
||||
}
|
||||
}
|
||||
|
||||
class MockClientState extends Mock implements ClientState {}
|
||||
|
||||
@@ -17,7 +21,12 @@ class MockChannel extends Mock implements Channel {
|
||||
}
|
||||
}
|
||||
|
||||
class MockChannelState extends Mock implements ChannelClientState {}
|
||||
class MockChannelState extends Mock implements ChannelClientState {
|
||||
MockChannelState() {
|
||||
when(() => typingEvents).thenReturn([]);
|
||||
when(() => typingEventsStream).thenAnswer((_) => Stream.value([]));
|
||||
}
|
||||
}
|
||||
|
||||
class MockNavigatorObserver extends Mock implements NavigatorObserver {}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ void main() {
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
expect(find.text('0'), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -346,40 +346,36 @@ class StreamChannelState extends State<StreamChannel> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var child = widget.child;
|
||||
if (widget.showLoading &&
|
||||
(initialMessageId != null || channel.state == null)) {
|
||||
child = FutureBuilder<List<bool>>(
|
||||
future: Future.wait(_futures),
|
||||
initialData: [
|
||||
channel.state != null,
|
||||
if (initialMessageId != null) false,
|
||||
],
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
var message = snapshot.error.toString();
|
||||
if (snapshot.error is DioError) {
|
||||
final dioError = snapshot.error as DioError?;
|
||||
if (dioError?.type == DioErrorType.response) {
|
||||
message = dioError!.message;
|
||||
} else {
|
||||
message = 'Check your connection and retry';
|
||||
}
|
||||
Widget child = FutureBuilder<List<bool>>(
|
||||
future: Future.wait(_futures),
|
||||
initialData: [
|
||||
channel.state != null,
|
||||
if (initialMessageId != null) false,
|
||||
],
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
var message = snapshot.error.toString();
|
||||
if (snapshot.error is DioError) {
|
||||
final dioError = snapshot.error as DioError?;
|
||||
if (dioError?.type == DioErrorType.response) {
|
||||
message = dioError!.message;
|
||||
} else {
|
||||
message = 'Check your connection and retry';
|
||||
}
|
||||
return Center(child: Text(message));
|
||||
}
|
||||
final initialized = snapshot.data![0];
|
||||
final dataLoaded = initialMessageId == null || snapshot.data![1];
|
||||
if (!initialized || !dataLoaded) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
return widget.child;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Center(child: Text(message));
|
||||
}
|
||||
final initialized = snapshot.data![0];
|
||||
// ignore: avoid_bool_literals_in_conditional_expressions
|
||||
final dataLoaded = initialMessageId == null ? true : snapshot.data![1];
|
||||
if (widget.showLoading && (!initialized || !dataLoaded)) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
return widget.child;
|
||||
},
|
||||
);
|
||||
if (initialMessageId != null) {
|
||||
child = Material(child: child);
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ void main() {
|
||||
when(() => mockChannel.state.isUpToDate).thenReturn(true);
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value([]));
|
||||
when(() => mockChannel.state.messages).thenReturn([]);
|
||||
|
||||
await tester.pumpWidget(
|
||||
StreamChannel(
|
||||
@@ -133,6 +134,7 @@ void main() {
|
||||
when(() => mockChannel.state.isUpToDate).thenReturn(true);
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value([]));
|
||||
when(() => mockChannel.state.messages).thenReturn([]);
|
||||
when(() => mockChannel.initialized).thenAnswer((_) => Future.value(true));
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -174,6 +176,7 @@ void main() {
|
||||
when(() => mockChannel.state.messages).thenReturn(messages);
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value(messages));
|
||||
when(() => mockChannel.state.messages).thenReturn(messages);
|
||||
when(() => mockChannel.initialized).thenAnswer((_) => Future.value(true));
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -220,6 +223,7 @@ void main() {
|
||||
const error = 'Error! Error! Error!';
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.error(error));
|
||||
when(() => mockChannel.state.messages).thenReturn([]);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
@@ -259,6 +263,7 @@ void main() {
|
||||
const messages = <Message>[];
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value(messages));
|
||||
when(() => mockChannel.state.messages).thenReturn(messages);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
@@ -305,6 +310,7 @@ void main() {
|
||||
const messages = <Message>[];
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value(messages));
|
||||
when(() => mockChannel.state.messages).thenReturn(messages);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
@@ -349,6 +355,7 @@ void main() {
|
||||
final messages = _generateMessages();
|
||||
when(() => mockChannel.state.messagesStream)
|
||||
.thenAnswer((_) => Stream.value(messages));
|
||||
when(() => mockChannel.state.messages).thenReturn(messages);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
|
||||
@@ -4,6 +4,10 @@ import 'package:stream_chat/stream_chat.dart';
|
||||
class MockLogger extends Mock implements Logger {}
|
||||
|
||||
class MockClient extends Mock implements StreamChatClient {
|
||||
MockClient() {
|
||||
when(() => wsConnectionStatus).thenReturn(ConnectionStatus.connected);
|
||||
}
|
||||
|
||||
@override
|
||||
final Logger logger = MockLogger();
|
||||
|
||||
|
||||
@@ -235,6 +235,14 @@ void main() {
|
||||
final mockClient = MockClient();
|
||||
const streamChatCoreKey = Key('streamChatCore');
|
||||
const childKey = Key('child');
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(() => mockClient.disconnect()).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
final streamChatCore = StreamChatCore(
|
||||
key: streamChatCoreKey,
|
||||
client: mockClient,
|
||||
@@ -247,13 +255,6 @@ void main() {
|
||||
expect(find.byKey(streamChatCoreKey), findsOneWidget);
|
||||
expect(find.byKey(childKey), findsOneWidget);
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(mockClient.disconnect).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
final streamChatCoreState = tester.state<StreamChatCoreState>(
|
||||
find.byKey(streamChatCoreKey),
|
||||
);
|
||||
@@ -323,6 +324,14 @@ void main() {
|
||||
const childKey = Key('child');
|
||||
final _connectivityController =
|
||||
BehaviorSubject.seeded(ConnectivityResult.none);
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(() => mockClient.disconnect()).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
final streamChatCore = StreamChatCore(
|
||||
key: streamChatCoreKey,
|
||||
client: mockClient,
|
||||
@@ -335,13 +344,6 @@ void main() {
|
||||
expect(find.byKey(streamChatCoreKey), findsOneWidget);
|
||||
expect(find.byKey(childKey), findsOneWidget);
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(mockClient.disconnect).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
_connectivityController.add(ConnectivityResult.mobile);
|
||||
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
@@ -397,6 +399,14 @@ void main() {
|
||||
const childKey = Key('child');
|
||||
final _connectivityController =
|
||||
BehaviorSubject.seeded(ConnectivityResult.none);
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(() => mockClient.disconnect()).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
final streamChatCore = StreamChatCore(
|
||||
key: streamChatCoreKey,
|
||||
client: mockClient,
|
||||
@@ -409,13 +419,6 @@ void main() {
|
||||
expect(find.byKey(streamChatCoreKey), findsOneWidget);
|
||||
expect(find.byKey(childKey), findsOneWidget);
|
||||
|
||||
final event = Event();
|
||||
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event));
|
||||
when(() => mockClient.connect()).thenAnswer((_) async => event);
|
||||
when(mockClient.disconnect).thenAnswer((_) async => null);
|
||||
when(() => mockClient.wsConnectionStatus)
|
||||
.thenReturn(ConnectionStatus.disconnected);
|
||||
|
||||
final streamChatCoreState = tester.state<StreamChatCoreState>(
|
||||
find.byKey(streamChatCoreKey),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user