@@ -1061,6 +1061,82 @@ void main() {
1061
1061
});
1062
1062
});
1063
1063
1064
+ group ('MarkTopicAsReadButton' , () {
1065
+ Future <void > setupToTopicActionSheetWithUnreadMessages (WidgetTester tester, {
1066
+ ZulipStream ? channel,
1067
+ }) async {
1068
+ addTearDown (testBinding.reset);
1069
+
1070
+ final effectiveChannel = channel ?? eg.stream ();
1071
+ const topicName = TopicName ('test topic' );
1072
+ final message = eg.streamMessage (stream: effectiveChannel, topic: 'test topic' );
1073
+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot (
1074
+ realmUsers: [eg.selfUser],
1075
+ streams: [effectiveChannel],
1076
+ subscriptions: [eg.subscription (effectiveChannel)]));
1077
+ store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
1078
+ connection = store.connection as FakeApiConnection ;
1079
+
1080
+ connection.prepare (json: eg.newestGetMessagesResult (
1081
+ foundOldest: true , messages: [message]).toJson ());
1082
+
1083
+ await store.addMessage (message);
1084
+ store.unreads.streams[effectiveChannel.streamId] ?? = {};
1085
+ store.unreads.streams[effectiveChannel.streamId]! [topicName] ?? = QueueList <int >();
1086
+ store.unreads.streams[effectiveChannel.streamId]! [topicName]! .add (message.id);
1087
+
1088
+ await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
1089
+ child: MessageListPage (initNarrow: TopicNarrow (effectiveChannel.streamId, topicName))));
1090
+ await tester.pumpAndSettle ();
1091
+
1092
+ await tester.longPress (find.byType (ZulipAppBar ));
1093
+ await tester.pump (const Duration (milliseconds: 250 ));
1094
+ }
1095
+
1096
+ Future <void > setupToTopicActionSheetWithNoUnreadMessages (WidgetTester tester) async {
1097
+ addTearDown (testBinding.reset);
1098
+
1099
+ final channel = eg.stream ();
1100
+ const topicName = TopicName ('test topic' );
1101
+ final message = eg.streamMessage (stream: channel, topic: 'test topic' , flags: [MessageFlag .read]);
1102
+
1103
+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot (
1104
+ realmUsers: [eg.selfUser],
1105
+ streams: [channel],
1106
+ subscriptions: [eg.subscription (channel)]));
1107
+ store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
1108
+ connection = store.connection as FakeApiConnection ;
1109
+
1110
+ connection.prepare (json: eg.newestGetMessagesResult (
1111
+ foundOldest: true , messages: [message]).toJson ());
1112
+
1113
+ await store.addMessage (message);
1114
+
1115
+ await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
1116
+ child: MessageListPage (initNarrow: TopicNarrow (channel.streamId, topicName))));
1117
+ await tester.pumpAndSettle ();
1118
+
1119
+ await tester.longPress (find.byType (ZulipAppBar ));
1120
+ await tester.pump (const Duration (milliseconds: 250 ));
1121
+ }
1122
+
1123
+ group ('visibility' , () {
1124
+ testWidgets ('shows button when topic has unread messages' , (tester) async {
1125
+ await setupToTopicActionSheetWithUnreadMessages (tester);
1126
+
1127
+ final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
1128
+ check (find.text (zulipLocalizations.actionSheetOptionMarkTopicAsRead)).findsOne ();
1129
+ });
1130
+
1131
+ testWidgets ('hides button when topic has no unread messages' , (tester) async {
1132
+ await setupToTopicActionSheetWithNoUnreadMessages (tester);
1133
+
1134
+ final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
1135
+ check (find.text (zulipLocalizations.actionSheetOptionMarkTopicAsRead)).findsNothing ();
1136
+ });
1137
+ });
1138
+ });
1139
+
1064
1140
group ('MessageActionSheetCancelButton' , () {
1065
1141
final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
1066
1142
0 commit comments