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
@@ -1,18 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:golden_toolkit/golden_toolkit.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
import 'simple_frame.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
testGoldens(
|
||||
'it should show no reactions',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StreamChatTheme(
|
||||
await tester.pumpWidgetBuilder(
|
||||
SimpleFrame(
|
||||
child: StreamChatTheme(
|
||||
data: StreamChatThemeData(),
|
||||
child: Container(
|
||||
child: ReactionBubble(
|
||||
@@ -24,15 +26,173 @@ void main() {
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(100, 100),
|
||||
);
|
||||
|
||||
expect(find.byKey(Key('StreamSvgIcon-Icon_thumbs_up_reaction.svg')),
|
||||
findsNothing);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_0');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'it should show a like',
|
||||
testGoldens(
|
||||
'it should show a like - light theme',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
final themeData = ThemeData.light();
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
final theme = StreamChatThemeData.getDefaultTheme(themeData);
|
||||
await tester.pumpWidgetBuilder(
|
||||
StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: theme,
|
||||
child: Container(
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: theme.ownMessageTheme.reactionsBorderColor,
|
||||
backgroundColor: theme.ownMessageTheme.reactionsBackgroundColor,
|
||||
maskColor: theme.ownMessageTheme.reactionsMaskColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(100, 100),
|
||||
);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_like_light');
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'it should show a like - dark theme',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
final themeData = ThemeData.dark();
|
||||
final theme = StreamChatThemeData.getDefaultTheme(themeData);
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidgetBuilder(
|
||||
StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
color: Colors.black,
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: theme.ownMessageTheme.reactionsBorderColor,
|
||||
backgroundColor: theme.ownMessageTheme.reactionsBackgroundColor,
|
||||
maskColor: theme.ownMessageTheme.reactionsMaskColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(100, 100),
|
||||
);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_like_dark');
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'it should show three reactions - light theme',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
final themeData = ThemeData.light();
|
||||
final theme = StreamChatThemeData.getDefaultTheme(themeData);
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidgetBuilder(
|
||||
StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
color: Colors.black,
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'user-id'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: theme.ownMessageTheme.reactionsBorderColor,
|
||||
backgroundColor: theme.ownMessageTheme.reactionsBackgroundColor,
|
||||
maskColor: theme.ownMessageTheme.reactionsMaskColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(140, 140),
|
||||
);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_3_light');
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'it should show three reactions - dark theme',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
final themeData = ThemeData.dark();
|
||||
final theme = StreamChatThemeData.getDefaultTheme(themeData);
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidgetBuilder(
|
||||
StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
color: Colors.black,
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'user-id'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: theme.ownMessageTheme.reactionsBorderColor,
|
||||
backgroundColor: theme.ownMessageTheme.reactionsBackgroundColor,
|
||||
maskColor: theme.ownMessageTheme.reactionsMaskColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(140, 140),
|
||||
);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_3_dark');
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'it should show two reactions with customized ui',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
@@ -41,74 +201,40 @@ void main() {
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeData,
|
||||
home: StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: Colors.black,
|
||||
backgroundColor: Colors.white,
|
||||
maskColor: Colors.white,
|
||||
),
|
||||
await tester.pumpWidgetBuilder(
|
||||
StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'love',
|
||||
user: User(id: 'user-id'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'unknown',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: Colors.red,
|
||||
backgroundColor: Colors.blue,
|
||||
maskColor: Colors.green,
|
||||
highlightOwnReactions: true,
|
||||
reverse: true,
|
||||
flipTail: true,
|
||||
tailCirclesSpacing: 4,
|
||||
),
|
||||
),
|
||||
),
|
||||
surfaceSize: Size(200, 200),
|
||||
);
|
||||
|
||||
expect(find.byKey(Key('StreamSvgIcon-Icon_thumbs_up_reaction.svg')),
|
||||
findsOneWidget);
|
||||
},
|
||||
);
|
||||
testWidgets(
|
||||
'it should show two reactions',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
final themeData = ThemeData();
|
||||
|
||||
when(client.state).thenReturn(clientState);
|
||||
when(clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeData,
|
||||
home: StreamChat(
|
||||
client: client,
|
||||
streamChatThemeData: StreamChatThemeData.getDefaultTheme(themeData),
|
||||
child: Container(
|
||||
child: ReactionBubble(
|
||||
reactions: [
|
||||
Reaction(
|
||||
type: 'like',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
Reaction(
|
||||
type: 'love',
|
||||
user: User(id: 'test'),
|
||||
),
|
||||
],
|
||||
borderColor: Colors.black,
|
||||
backgroundColor: Colors.white,
|
||||
maskColor: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byKey(Key('StreamSvgIcon-Icon_thumbs_up_reaction.svg')),
|
||||
findsOneWidget);
|
||||
expect(find.byKey(Key('StreamSvgIcon-Icon_love_reaction.svg')),
|
||||
findsOneWidget);
|
||||
await screenMatchesGolden(tester, 'reaction_bubble_2');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user