diff --git a/assets/l10n/app_en.arb b/assets/l10n/app_en.arb index d66f143151..73ae6294e6 100644 --- a/assets/l10n/app_en.arb +++ b/assets/l10n/app_en.arb @@ -330,6 +330,10 @@ "@dialogContinue": { "description": "Button label in dialogs to proceed." }, + "dialogClose": "Close", + "@dialogClose": { + "description": "Button label in dialogs to close." + }, "errorDialogContinue": "OK", "@errorDialogContinue": { "description": "Button label in error dialogs to acknowledge the error and close the dialog." @@ -611,5 +615,13 @@ "errorReactionRemovingFailedTitle": "Removing reaction failed", "@errorReactionRemovingFailedTitle": { "description": "Error title when removing a message reaction fails" + }, + "emojiReactionsMore": "more", + "@emojiReactionsMore": { + "description": "Label for a button opening the emoji picker." + }, + "emojiPickerSearchEmoji": "Search emoji", + "@emojiPickerSearchEmoji": { + "description": "Hint text for the emoji picker search text field." } } diff --git a/lib/generated/l10n/zulip_localizations.dart b/lib/generated/l10n/zulip_localizations.dart index 9d293139f8..1fdd9f47c2 100644 --- a/lib/generated/l10n/zulip_localizations.dart +++ b/lib/generated/l10n/zulip_localizations.dart @@ -529,6 +529,12 @@ abstract class ZulipLocalizations { /// **'Continue'** String get dialogContinue; + /// Button label in dialogs to close. + /// + /// In en, this message translates to: + /// **'Close'** + String get dialogClose; + /// Button label in error dialogs to acknowledge the error and close the dialog. /// /// In en, this message translates to: @@ -906,6 +912,18 @@ abstract class ZulipLocalizations { /// In en, this message translates to: /// **'Removing reaction failed'** String get errorReactionRemovingFailedTitle; + + /// Label for a button opening the emoji picker. + /// + /// In en, this message translates to: + /// **'more'** + String get emojiReactionsMore; + + /// Hint text for the emoji picker search text field. + /// + /// In en, this message translates to: + /// **'Search emoji'** + String get emojiPickerSearchEmoji; } class _ZulipLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/generated/l10n/zulip_localizations_ar.dart b/lib/generated/l10n/zulip_localizations_ar.dart index ae652f3c7e..1b7c162972 100644 --- a/lib/generated/l10n/zulip_localizations_ar.dart +++ b/lib/generated/l10n/zulip_localizations_ar.dart @@ -260,6 +260,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations { @override String get dialogContinue => 'Continue'; + @override + String get dialogClose => 'Close'; + @override String get errorDialogContinue => 'OK'; @@ -484,4 +487,10 @@ class ZulipLocalizationsAr extends ZulipLocalizations { @override String get errorReactionRemovingFailedTitle => 'Removing reaction failed'; + + @override + String get emojiReactionsMore => 'more'; + + @override + String get emojiPickerSearchEmoji => 'Search emoji'; } diff --git a/lib/generated/l10n/zulip_localizations_en.dart b/lib/generated/l10n/zulip_localizations_en.dart index fe2c93d236..8e17bc76bb 100644 --- a/lib/generated/l10n/zulip_localizations_en.dart +++ b/lib/generated/l10n/zulip_localizations_en.dart @@ -260,6 +260,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations { @override String get dialogContinue => 'Continue'; + @override + String get dialogClose => 'Close'; + @override String get errorDialogContinue => 'OK'; @@ -484,4 +487,10 @@ class ZulipLocalizationsEn extends ZulipLocalizations { @override String get errorReactionRemovingFailedTitle => 'Removing reaction failed'; + + @override + String get emojiReactionsMore => 'more'; + + @override + String get emojiPickerSearchEmoji => 'Search emoji'; } diff --git a/lib/generated/l10n/zulip_localizations_ja.dart b/lib/generated/l10n/zulip_localizations_ja.dart index 6d82e0d19c..6b7dbd9be2 100644 --- a/lib/generated/l10n/zulip_localizations_ja.dart +++ b/lib/generated/l10n/zulip_localizations_ja.dart @@ -260,6 +260,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations { @override String get dialogContinue => 'Continue'; + @override + String get dialogClose => 'Close'; + @override String get errorDialogContinue => 'OK'; @@ -484,4 +487,10 @@ class ZulipLocalizationsJa extends ZulipLocalizations { @override String get errorReactionRemovingFailedTitle => 'Removing reaction failed'; + + @override + String get emojiReactionsMore => 'more'; + + @override + String get emojiPickerSearchEmoji => 'Search emoji'; } diff --git a/lib/widgets/action_sheet.dart b/lib/widgets/action_sheet.dart index 0abe3eeb09..25f0783de1 100644 --- a/lib/widgets/action_sheet.dart +++ b/lib/widgets/action_sheet.dart @@ -222,11 +222,19 @@ class ReactionButtons extends StatelessWidget { : zulipLocalizations.errorReactionAddingFailedTitle); } + void _onMorePressed() { + // Dismiss current action sheet before opening emoji picker sheet. + Navigator.of(pageContext).pop(); + + showEmojiPickerSheet(pageContext: pageContext, message: message); + } + @override Widget build(BuildContext context) { assert(EmojiStore.popularEmojiCandidates.every( (emoji) => emoji.emojiType == ReactionType.unicodeEmoji)); + final zulipLocalizations = ZulipLocalizations.of(context); final store = PerAccountStoreWidget.of(pageContext); final designVariables = DesignVariables.of(context); @@ -240,32 +248,57 @@ class ReactionButtons extends StatelessWidget { return Container( decoration: BoxDecoration(color: designVariables.contextMenuItemBg.withFadedAlpha(0.12)), - child: Row( - spacing: 1, - children: List.unmodifiable(EmojiStore.popularEmojiCandidates.mapIndexed((index, emoji) { - final isSelfVoted = hasSelfVote(emoji); - return Flexible(child: InkWell( - onTap: () => _onReactionPressed(emoji: emoji, isSelfVoted: isSelfVoted), - splashFactory: NoSplash.splashFactory, - borderRadius: index == 0 - ? const BorderRadius.only(topLeft: Radius.circular(7)) - : null, - overlayColor: WidgetStateColor.resolveWith((states) => - states.any((e) => e == WidgetState.pressed) - ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) - : Colors.transparent), - child: Container( - width: double.infinity, - padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 5), - alignment: Alignment.center, - color: isSelfVoted - ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + child: Row(children: [ + Flexible(child: Row( + spacing: 1, + children: List.unmodifiable(EmojiStore.popularEmojiCandidates.mapIndexed((index, emoji) { + final isSelfVoted = hasSelfVote(emoji); + return Flexible(child: InkWell( + onTap: () => _onReactionPressed(emoji: emoji, isSelfVoted: isSelfVoted), + splashFactory: NoSplash.splashFactory, + borderRadius: index == 0 + ? const BorderRadius.only(topLeft: Radius.circular(7)) : null, - child: UnicodeEmojiWidget( - emojiDisplay: emoji.emojiDisplay as UnicodeEmojiDisplay, - notoColorEmojiTextSize: 20.1, - size: 24)))); - })))); + overlayColor: WidgetStateColor.resolveWith((states) => + states.any((e) => e == WidgetState.pressed) + ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + : Colors.transparent), + child: Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 5), + alignment: Alignment.center, + color: isSelfVoted + ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + : null, + child: UnicodeEmojiWidget( + emojiDisplay: emoji.emojiDisplay as UnicodeEmojiDisplay, + notoColorEmojiTextSize: 20.1, + size: 24)))); + })))), + InkWell( + onTap: _onMorePressed, + splashFactory: NoSplash.splashFactory, + borderRadius: const BorderRadius.only(topRight: Radius.circular(7)), + overlayColor: WidgetStateColor.resolveWith((states) => + states.any((e) => e == WidgetState.pressed) + ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + : Colors.transparent), + child: Padding( + padding: const EdgeInsetsDirectional.fromSTEB(12, 12, 4, 12), + child: Row(children: [ + Text(zulipLocalizations.emojiReactionsMore, + textAlign: TextAlign.end, + style: TextStyle( + color: designVariables.contextMenuItemText, + fontSize: 14, + ).merge(weightVariableTextStyle(context, wght: 600))), + Icon(ZulipIcons.chevron_right, + color: designVariables.contextMenuItemText, + size: 24), + ]), + )), + ]), + ); } } diff --git a/lib/widgets/emoji_reaction.dart b/lib/widgets/emoji_reaction.dart index 00f7e9b334..9c0c2dead6 100644 --- a/lib/widgets/emoji_reaction.dart +++ b/lib/widgets/emoji_reaction.dart @@ -3,12 +3,16 @@ import 'package:flutter/material.dart'; import '../api/exception.dart'; import '../api/model/model.dart'; import '../api/route/messages.dart'; +import '../generated/l10n/zulip_localizations.dart'; +import '../model/autocomplete.dart'; import '../model/emoji.dart'; import 'color.dart'; import 'dialog.dart'; import 'emoji.dart'; +import 'inset_shadow.dart'; import 'store.dart'; import 'text.dart'; +import 'theme.dart'; /// Emoji-reaction styles that differ between light and dark themes. class EmojiReactionTheme extends ThemeExtension { @@ -401,3 +405,222 @@ Future doAddOrRemoveReaction({ return; } } + +/// Opens a browsable and searchable emoji picker bottom sheet. +void showEmojiPickerSheet({ + required BuildContext pageContext, + required Message message, +}) { + final store = PerAccountStoreWidget.of(pageContext); + showModalBottomSheet( + context: pageContext, + // Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect + // on my iPhone 13 Pro but is marked as "much slower": + // https://api.flutter.dev/flutter/dart-ui/Clip.html + clipBehavior: Clip.antiAlias, + useSafeArea: true, + isScrollControlled: true, + builder: (BuildContext context) { + return SafeArea( + child: Padding( + // By default, when software keyboard is opened, the ListView + // expands behind the software keyboard — resulting in some + // list entries being covered by the keyboard. Add explicit + // bottom padding the size of the keyboard, which fixes this. + padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom), + // For _EmojiPickerItem, and RealmContentNetworkImage used in ImageEmojiWidget. + child: PerAccountStoreWidget( + accountId: store.accountId, + child: EmojiPicker(pageContext: pageContext, message: message)))); + }); +} + +@visibleForTesting +class EmojiPicker extends StatefulWidget { + const EmojiPicker({ + super.key, + required this.pageContext, + required this.message, + }); + + final BuildContext pageContext; + final Message message; + + @override + State createState() => _EmojiPickerState(); +} + +class _EmojiPickerState extends State with PerAccountStoreAwareStateMixin { + late TextEditingController _controller; + + EmojiAutocompleteView? _viewModel; + List _resultsToDisplay = const []; + + @override + void initState() { + super.initState(); + _controller = TextEditingController() + ..addListener(_handleControllerUpdate); + } + + void _initViewModel(EmojiAutocompleteQuery query) { + final store = PerAccountStoreWidget.of(context); + _viewModel = EmojiAutocompleteView.init(store: store, query: query) + ..addListener(_handleViewModelUpdate); + } + + @override + void onNewStore() { + if (_viewModel != null) { + _viewModel!.dispose(); + } + _initViewModel(EmojiAutocompleteQuery(_controller.text)); + } + + void _handleControllerUpdate() { + if (_viewModel != null) { + _viewModel!.query = EmojiAutocompleteQuery(_controller.text); + } + } + + void _handleViewModelUpdate() { + setState(() { + _resultsToDisplay = List.unmodifiable(_viewModel!.results); + }); + } + + @override + void dispose() { + _viewModel?.dispose(); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final zulipLocalizations = ZulipLocalizations.of(context); + final designVariables = DesignVariables.of(context); + + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding(padding: const EdgeInsetsDirectional.only(start: 8, top: 4), + child: Row(children: [ + // TODO(design): Make sure if we need a button to clear the textfield. + Flexible(child: Padding( + padding: const EdgeInsets.symmetric(vertical: 2), + child: TextField( + controller: _controller, + autofocus: true, + decoration: InputDecoration( + hintText: zulipLocalizations.emojiPickerSearchEmoji, + contentPadding: const EdgeInsetsDirectional.only(start: 10, top: 6), + filled: true, + fillColor: designVariables.bgSearchInput, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: BorderSide.none), + hintStyle: TextStyle(color: designVariables.textMessage)), + style: const TextStyle(fontSize: 19, height: 26 / 19)))), + TextButton( + onPressed: () => Navigator.pop(context), + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + splashFactory: NoSplash.splashFactory, + foregroundColor: designVariables.contextMenuItemText, + ).copyWith(backgroundColor: WidgetStateColor.resolveWith((states) => + states.contains(WidgetState.pressed) + ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + : Colors.transparent)), + child: Text(zulipLocalizations.dialogClose, + style: const TextStyle(fontSize: 20, height: 30 / 20))), + ])), + Expanded(child: InsetShadowBox( + top: 8, bottom: 8, + color: designVariables.bgContextMenu, + child: ListView.builder( + padding: const EdgeInsets.symmetric(vertical: 8), + itemCount: _resultsToDisplay.length, + itemBuilder: (context, i) => EmojiPickerListEntry( + pageContext: widget.pageContext, + emoji: _resultsToDisplay[i].candidate, + message: widget.message)))), + ]); + } +} + +@visibleForTesting +class EmojiPickerListEntry extends StatelessWidget { + const EmojiPickerListEntry({ + super.key, + required this.pageContext, + required this.emoji, + required this.message, + }); + + final BuildContext pageContext; + final EmojiCandidate emoji; + final Message message; + + static const _emojiSize = 24.0; + static const _notoColorEmojiTextSize = 20.1; + + void _onPressed() { + // Dismiss the enclosing action sheet immediately, + // for swift UI feedback that the user's selection was received. + Navigator.pop(pageContext); + + doAddOrRemoveReaction( + context: pageContext, + doRemoveReaction: false, + messageId: message.id, + emoji: emoji, + errorDialogTitle: + ZulipLocalizations.of(pageContext).errorReactionAddingFailedTitle); + } + + @override + Widget build(BuildContext context) { + final store = PerAccountStoreWidget.of(context); + final designVariables = DesignVariables.of(context); + + final emojiDisplay = emoji.emojiDisplay.resolve(store.userSettings); + final Widget? glyph = switch (emojiDisplay) { + ImageEmojiDisplay() => + ImageEmojiWidget(size: _emojiSize, emojiDisplay: emojiDisplay), + UnicodeEmojiDisplay() => + UnicodeEmojiWidget( + size: _emojiSize, notoColorEmojiTextSize: _notoColorEmojiTextSize, + emojiDisplay: emojiDisplay), + TextEmojiDisplay() => null, // The text is already shown separately. + }; + + final label = emoji.aliases.isEmpty + ? emoji.emojiName + : [emoji.emojiName, ...emoji.aliases].join(", "); // TODO(#1080) + + return InkWell( + onTap: _onPressed, + splashFactory: NoSplash.splashFactory, + overlayColor: WidgetStateColor.resolveWith((states) => + states.any((e) => e == WidgetState.pressed) + ? designVariables.contextMenuItemBg.withFadedAlpha(0.20) + : Colors.transparent), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Row(children: [ + if (glyph != null) + Padding( + padding: const EdgeInsets.all(10), + child: glyph), + Flexible(child: Text(label, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 17, + height: 18 / 17, + color: designVariables.textMessage))) + ]), + )); + } +} diff --git a/lib/widgets/theme.dart b/lib/widgets/theme.dart index 13bb12b391..39ba1cdea8 100644 --- a/lib/widgets/theme.dart +++ b/lib/widgets/theme.dart @@ -134,6 +134,8 @@ class DesignVariables extends ThemeExtension { mainBackground: const Color(0xfff0f0f0), textInput: const Color(0xff000000), title: const Color(0xff1a1a1a), + bgSearchInput: const Color(0xffe3e3e3), + textMessage: const Color(0xff262626), channelColorSwatches: ChannelColorSwatches.light, atMentionMarker: const HSLColor.fromAHSL(0.5, 0, 0, 0.2).toColor(), contextMenuCancelBg: const Color(0xff797986).withValues(alpha: 0.15), @@ -175,6 +177,8 @@ class DesignVariables extends ThemeExtension { mainBackground: const Color(0xff1d1d1d), textInput: const Color(0xffffffff).withValues(alpha: 0.9), title: const Color(0xffffffff), + bgSearchInput: const Color(0xff313131), + textMessage: const Color(0xffffffff).withValues(alpha: 0.8), channelColorSwatches: ChannelColorSwatches.dark, contextMenuCancelBg: const Color(0xff797986).withValues(alpha: 0.15), // the same as the light mode in Figma contextMenuCancelPressedBg: const Color(0xff797986).withValues(alpha: 0.20), // the same as the light mode in Figma @@ -223,6 +227,8 @@ class DesignVariables extends ThemeExtension { required this.mainBackground, required this.textInput, required this.title, + required this.bgSearchInput, + required this.textMessage, required this.channelColorSwatches, required this.atMentionMarker, required this.contextMenuCancelBg, @@ -272,6 +278,8 @@ class DesignVariables extends ThemeExtension { final Color mainBackground; final Color textInput; final Color title; + final Color bgSearchInput; + final Color textMessage; // Not exactly from the Figma design, but from Vlad anyway. final ChannelColorSwatches channelColorSwatches; @@ -316,6 +324,8 @@ class DesignVariables extends ThemeExtension { Color? mainBackground, Color? textInput, Color? title, + Color? bgSearchInput, + Color? textMessage, ChannelColorSwatches? channelColorSwatches, Color? atMentionMarker, Color? contextMenuCancelBg, @@ -355,6 +365,8 @@ class DesignVariables extends ThemeExtension { mainBackground: mainBackground ?? this.mainBackground, textInput: textInput ?? this.textInput, title: title ?? this.title, + bgSearchInput: bgSearchInput ?? this.bgSearchInput, + textMessage: textMessage ?? this.textMessage, channelColorSwatches: channelColorSwatches ?? this.channelColorSwatches, atMentionMarker: atMentionMarker ?? this.atMentionMarker, contextMenuCancelBg: contextMenuCancelBg ?? this.contextMenuCancelBg, @@ -401,6 +413,8 @@ class DesignVariables extends ThemeExtension { mainBackground: Color.lerp(mainBackground, other.mainBackground, t)!, textInput: Color.lerp(textInput, other.textInput, t)!, title: Color.lerp(title, other.title, t)!, + bgSearchInput: Color.lerp(bgSearchInput, other.bgSearchInput, t)!, + textMessage: Color.lerp(textMessage, other.textMessage, t)!, channelColorSwatches: ChannelColorSwatches.lerp(channelColorSwatches, other.channelColorSwatches, t), atMentionMarker: Color.lerp(atMentionMarker, other.atMentionMarker, t)!, contextMenuCancelBg: Color.lerp(contextMenuCancelBg, other.contextMenuCancelBg, t)!, diff --git a/test/widgets/action_sheet_test.dart b/test/widgets/action_sheet_test.dart index aa27c53afb..05276c777f 100644 --- a/test/widgets/action_sheet_test.dart +++ b/test/widgets/action_sheet_test.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'package:checks/checks.dart'; import 'package:flutter/material.dart'; @@ -9,6 +10,7 @@ import 'package:zulip/api/model/events.dart'; import 'package:zulip/api/model/model.dart'; import 'package:zulip/api/route/channels.dart'; import 'package:zulip/api/route/messages.dart'; +import 'package:zulip/api/route/realm.dart'; import 'package:zulip/model/binding.dart'; import 'package:zulip/model/compose.dart'; import 'package:zulip/model/emoji.dart'; @@ -21,6 +23,7 @@ import 'package:zulip/widgets/action_sheet.dart'; import 'package:zulip/widgets/compose_box.dart'; import 'package:zulip/widgets/content.dart'; import 'package:zulip/widgets/emoji.dart'; +import 'package:zulip/widgets/emoji_reaction.dart'; import 'package:zulip/widgets/icons.dart'; import 'package:zulip/widgets/message_list.dart'; import 'package:share_plus_platform_interface/method_channel/method_channel_share.dart'; @@ -33,6 +36,7 @@ import '../model/emoji_test.dart'; import '../model/test_store.dart'; import '../stdlib_checks.dart'; import '../test_clipboard.dart'; +import '../test_images.dart'; import '../test_share_plus.dart'; import 'compose_box_checks.dart'; import 'dialog_checks.dart'; @@ -199,6 +203,149 @@ void main() { }); } }); + + group('emoji picker;', () { + Future setupEmojiPicker(WidgetTester tester, { + required Message message, + required Narrow narrow, + }) async { + final httpClient = FakeImageHttpClient(); + debugNetworkImageHttpClientProvider = () => httpClient; + httpClient.request.response + ..statusCode = HttpStatus.ok + ..content = kSolidBlueAvatar; + + await setupToMessageActionSheet(tester, message: message, narrow: narrow); + store.setServerEmojiData(ServerEmojiData(codeToNames: { + '1f4a4': ['zzz', 'sleepy'], // (just 'zzz' in real data) + })); + await store.handleEvent(RealmEmojiUpdateEvent(id: 1, realmEmoji: { + '1': eg.realmEmojiItem(emojiCode: '1', emojiName: 'buzzing'), + })); + + await tester.tap(find.ancestor( + of: find.byIcon(ZulipIcons.chevron_right), + matching: find.byType(InkWell))); + await tester.pumpAndSettle(); + await tester.ensureVisible(find.byType(EmojiPicker)); + } + + final searchFieldFinder = find.widgetWithText(TextField, 'Search emoji'); + + Condition conditionEmojiListEntry({ + required ReactionType emojiType, + required String emojiCode, + required String emojiName, + }) { + return (Subject it) => it.isA() + ..emoji.which((it) => it + ..emojiType.equals(emojiType) + ..emojiCode.equals(emojiCode) + ..emojiName.equals(emojiName)); + } + + List> arePopularCandidates = popularCandidates.map((c) => + conditionEmojiListEntry( + emojiType: c.emojiType, + emojiCode: c.emojiCode, + emojiName: c.emojiName)).toList(); + + testWidgets('show, search', (tester) async { + final message = eg.streamMessage(); + await setupEmojiPicker(tester, message: message, narrow: TopicNarrow.ofMessage(message)); + + check(tester.widgetList(find.byType(EmojiPickerListEntry))).deepEquals([ + ...arePopularCandidates, + conditionEmojiListEntry( + emojiType: ReactionType.realmEmoji, + emojiCode: '1', + emojiName: 'buzzing'), + conditionEmojiListEntry( + emojiType: ReactionType.zulipExtraEmoji, + emojiCode: 'zulip', + emojiName: 'zulip'), + conditionEmojiListEntry( + emojiType: ReactionType.unicodeEmoji, + emojiCode: '1f4a4', + emojiName: 'zzz'), + ]); + + tester.widget(searchFieldFinder); + await tester.enterText(searchFieldFinder, 'z'); + await tester.pump(); + + check(tester.widgetList(find.byType(EmojiPickerListEntry))).deepEquals([ + conditionEmojiListEntry( + emojiType: ReactionType.zulipExtraEmoji, + emojiCode: 'zulip', + emojiName: 'zulip'), + conditionEmojiListEntry( + emojiType: ReactionType.unicodeEmoji, + emojiCode: '1f4a4', + emojiName: 'zzz'), + conditionEmojiListEntry( + emojiType: ReactionType.realmEmoji, + emojiCode: '1', + emojiName: 'buzzing'), + ]); + + tester.widget(searchFieldFinder); + await tester.enterText(searchFieldFinder, 'zz'); + await tester.pump(); + + check(tester.widgetList(find.byType(EmojiPickerListEntry))).deepEquals([ + conditionEmojiListEntry( + emojiType: ReactionType.unicodeEmoji, + emojiCode: '1f4a4', + emojiName: 'zzz'), + conditionEmojiListEntry( + emojiType: ReactionType.realmEmoji, + emojiCode: '1', + emojiName: 'buzzing'), + ]); + + debugNetworkImageHttpClientProvider = null; + }); + + testWidgets('adding success', (tester) async { + final message = eg.streamMessage(); + await setupEmojiPicker(tester, message: message, narrow: TopicNarrow.ofMessage(message)); + + connection.prepare(json: {}); + await tester.tap(find.text('\u{1f4a4}')); // 'zzz' emoji + await tester.pump(Duration.zero); + + check(connection.lastRequest).isA() + ..method.equals('POST') + ..url.path.equals('/api/v1/messages/${message.id}/reactions') + ..bodyFields.deepEquals({ + 'reaction_type': 'unicode_emoji', + 'emoji_code': '1f4a4', + 'emoji_name': 'zzz', + }); + + debugNetworkImageHttpClientProvider = null; + }); + + testWidgets('request has an error', (tester) async { + final message = eg.streamMessage(); + await setupEmojiPicker(tester, message: message, narrow: TopicNarrow.ofMessage(message)); + + connection.prepare(httpStatus: 400, json: { + 'code': 'BAD_REQUEST', + 'msg': 'Invalid message(s)', + 'result': 'error', + }); + await tester.tap(find.text('\u{1f4a4}')); // 'zzz' emoji + await tester.pump(Duration.zero); // error arrives; error dialog shows + + await tester.tap(find.byWidget(checkErrorDialog(tester, + expectedTitle: 'Adding reaction failed', + expectedMessage: 'Invalid message(s)'))); + + debugNetworkImageHttpClientProvider = null; + }); + }); }); group('StarButton', () { @@ -763,3 +910,7 @@ void main() { extension UnicodeEmojiWidgetChecks on Subject { Subject get emojiDisplay => has((x) => x.emojiDisplay, 'emojiDisplay'); } + +extension EmojiPickerListItemChecks on Subject { + Subject get emoji => has((x) => x.emoji, 'emoji'); +}