add reaction_bubble_test
This commit is contained in:
@@ -21,7 +21,7 @@ class ReactionBubble extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final reactionAssets = StreamChatTheme.of(context).reactionIcons;
|
final reactionIcons = StreamChatTheme.of(context).reactionIcons;
|
||||||
return Transform(
|
return Transform(
|
||||||
transform: Matrix4.rotationY(reverse ? pi : 0),
|
transform: Matrix4.rotationY(reverse ? pi : 0),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
@@ -42,11 +42,11 @@ class ReactionBubble extends StatelessWidget {
|
|||||||
child: Wrap(
|
child: Wrap(
|
||||||
children: [
|
children: [
|
||||||
...reactions.map((reaction) {
|
...reactions.map((reaction) {
|
||||||
final reactionAsset = reactionAssets.firstWhere(
|
final reactionIcon = reactionIcons.firstWhere(
|
||||||
(reactionAsset) => reactionAsset.type == reaction.type,
|
(r) => r.type == reaction.type,
|
||||||
orElse: () => null,
|
orElse: () => null,
|
||||||
);
|
);
|
||||||
if (reactionAsset == null) {
|
if (reactionIcon == null) {
|
||||||
return Text(
|
return Text(
|
||||||
'?',
|
'?',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -56,7 +56,7 @@ class ReactionBubble extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Icon(
|
return Icon(
|
||||||
reactionAsset.iconData,
|
reactionIcon.iconData,
|
||||||
size: 16,
|
size: 16,
|
||||||
color: StreamChatTheme.of(context).accentColor,
|
color: StreamChatTheme.of(context).accentColor,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
|
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
|
||||||
|
|
||||||
@@ -25,7 +23,7 @@ class ReactionPicker extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final reactionAssets = StreamChatTheme.of(context).reactionIcons;
|
final reactionIcons = StreamChatTheme.of(context).reactionIcons;
|
||||||
return Stack(
|
return Stack(
|
||||||
fit: StackFit.passthrough,
|
fit: StackFit.passthrough,
|
||||||
children: [
|
children: [
|
||||||
@@ -39,7 +37,7 @@ class ReactionPicker extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: reactionAssets.map((reactionIcon) {
|
children: reactionIcons.map((reactionIcon) {
|
||||||
final ownReactionIndex = message.ownReactions?.indexWhere(
|
final ownReactionIndex = message.ownReactions?.indexWhere(
|
||||||
(reaction) => reaction.type == reactionIcon.type) ??
|
(reaction) => reaction.type == reactionIcon.type) ??
|
||||||
-1;
|
-1;
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class StreamChatThemeData {
|
|||||||
Widget Function(BuildContext, Channel) defaultChannelImage,
|
Widget Function(BuildContext, Channel) defaultChannelImage,
|
||||||
Widget Function(BuildContext, User) defaultUserImage,
|
Widget Function(BuildContext, User) defaultUserImage,
|
||||||
IconThemeData primaryIconTheme,
|
IconThemeData primaryIconTheme,
|
||||||
List<ReactionIcon> reactionAssets,
|
List<ReactionIcon> reactionIcons,
|
||||||
}) =>
|
}) =>
|
||||||
StreamChatThemeData(
|
StreamChatThemeData(
|
||||||
primaryColor: primaryColor ?? this.primaryColor,
|
primaryColor: primaryColor ?? this.primaryColor,
|
||||||
@@ -211,7 +211,7 @@ class StreamChatThemeData {
|
|||||||
this.otherMessageTheme.avatarTheme,
|
this.otherMessageTheme.avatarTheme,
|
||||||
) ??
|
) ??
|
||||||
this.otherMessageTheme,
|
this.otherMessageTheme,
|
||||||
reactionIcons: reactionAssets ?? this.reactionIcons,
|
reactionIcons: reactionIcons ?? this.reactionIcons,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Get the default Stream Chat theme
|
/// Get the default Stream Chat theme
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
|
||||||
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets(
|
||||||
|
'it should show no reactions',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: StreamChatTheme(
|
||||||
|
data: StreamChatThemeData(),
|
||||||
|
child: Container(
|
||||||
|
child: ReactionBubble(
|
||||||
|
reactions: [],
|
||||||
|
borderColor: Colors.black,
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsNothing);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'it should show a thumb up',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final themeData = ThemeData();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: themeData,
|
||||||
|
home: StreamChatTheme(
|
||||||
|
data: StreamChatThemeData.getDefaultTheme(themeData),
|
||||||
|
child: Container(
|
||||||
|
child: ReactionBubble(
|
||||||
|
reactions: [
|
||||||
|
Reaction(
|
||||||
|
type: 'thumbs_up',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
borderColor: Colors.black,
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
testWidgets(
|
||||||
|
'it should show two reactions',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final themeData = ThemeData();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: themeData,
|
||||||
|
home: StreamChatTheme(
|
||||||
|
data: StreamChatThemeData.getDefaultTheme(themeData),
|
||||||
|
child: Container(
|
||||||
|
child: ReactionBubble(
|
||||||
|
reactions: [
|
||||||
|
Reaction(
|
||||||
|
type: 'thumbs_up',
|
||||||
|
),
|
||||||
|
Reaction(
|
||||||
|
type: 'love',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
borderColor: Colors.black,
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsOneWidget);
|
||||||
|
expect(find.byIcon(StreamIcons.love_reaction), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user