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