test: add tests for stream chat flutter (#335)
* feat: Added tests * feat: Added header test * feat: Added new tests * fix * feat: Added test, fmt * feat: Added delete test * added system and unread ind tests * fix: analysis * added new tests * fix: analysis * added tests * add attachment actions modal tests * fix analysis * fix analysis * add backbutton tests * fix analysis * increase timeout * add channelheader tests * add infotile tests * add reactions modal and channel unread indicator tests * add golden test for reaction bubble * add dark tests * add system message golden * add deletd message golden * add message action modal tests * update goldens * update workflow runner * update goldens * remove channel unread indicator in favor of unread indicator * move file and media screen to sample app * add channel image tesst * add channel_list_header test * add thread_header test * bump up test threashold * fix review Co-authored-by: Salvatore Giordano <[email protected]>
This commit is contained in:
co-authored by
Salvatore Giordano
parent
4946664220
commit
a42b3de6f4
@@ -0,0 +1,144 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stream_chat_flutter/src/back_button.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'BackButton control test',
|
||||
(WidgetTester tester) async {
|
||||
final theme = ThemeData();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: const Material(child: Text('Home')),
|
||||
routes: <String, WidgetBuilder>{
|
||||
'/next': (BuildContext context) {
|
||||
return Material(
|
||||
child: Center(
|
||||
child: StreamChatTheme(
|
||||
data: StreamChatThemeData.getDefaultTheme(theme),
|
||||
child: StreamBackButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// ignore: unawaited_futures
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(StreamBackButton));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Home'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'it should not throw errors if cannot pop',
|
||||
(WidgetTester tester) async {
|
||||
final theme = ThemeData();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: StreamChatTheme(
|
||||
data: StreamChatThemeData.getDefaultTheme(theme),
|
||||
child: StreamBackButton(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(StreamBackButton));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(StreamBackButton), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'BackButton onPressed overrides default pop behavior',
|
||||
(WidgetTester tester) async {
|
||||
final theme = ThemeData();
|
||||
var customCallbackWasCalled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: const Material(child: Text('Home')),
|
||||
routes: <String, WidgetBuilder>{
|
||||
'/next': (BuildContext context) {
|
||||
return Material(
|
||||
child: Center(
|
||||
child: StreamChatTheme(
|
||||
data: StreamChatThemeData.getDefaultTheme(theme),
|
||||
child: StreamBackButton(
|
||||
onPressed: () => customCallbackWasCalled = true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// ignore: unawaited_futures
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Home'), findsNothing); // Start off on the second page.
|
||||
expect(
|
||||
customCallbackWasCalled,
|
||||
false,
|
||||
); // customCallbackWasCalled should still be false.
|
||||
await tester.tap(find.byType(StreamBackButton));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// We're still on the second page.
|
||||
expect(find.text('Home'), findsNothing);
|
||||
// But the custom callback is called.
|
||||
expect(customCallbackWasCalled, true);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'it should show unread count',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: StreamChat(
|
||||
client: client,
|
||||
child: StreamBackButton(
|
||||
showUnreads: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(UnreadIndicator), findsOneWidget);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user