Skip to content

Commit 212afe5

Browse files
committed
action_sheet test [nfc]: Pull out showFromInbox helper
1 parent 4498df6 commit 212afe5

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

test/widgets/action_sheet_test.dart

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22

33
import 'package:checks/checks.dart';
4+
import 'package:collection/collection.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter/services.dart';
67
import 'package:flutter_checks/flutter_checks.dart';
@@ -143,6 +144,32 @@ void main() {
143144
connection = store.connection as FakeApiConnection;
144145
}
145146

147+
Future<void> showFromInbox(WidgetTester tester, {
148+
String topic = someTopic,
149+
}) async {
150+
final channelIdsWithUnreads = store.unreads.streams.keys;
151+
final hasTopicWithUnreads = channelIdsWithUnreads.any((streamId) =>
152+
store.unreads.countInTopicNarrow(streamId, TopicName(topic)) > 0);
153+
if (!hasTopicWithUnreads) {
154+
throw FlutterError.fromParts([
155+
ErrorSummary('showFromInbox called without an unread message'),
156+
ErrorHint(
157+
'Before calling showFromInbox, ensure that [Unreads] '
158+
'has an unread message in the relevant topic. ',
159+
),
160+
]);
161+
}
162+
163+
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
164+
child: const HomePage()));
165+
await tester.pump();
166+
check(find.byType(InboxPageBody)).findsOne();
167+
168+
await tester.longPress(find.text(topic));
169+
// sheet appears onscreen; default duration of bottom-sheet enter animation
170+
await tester.pump(const Duration(milliseconds: 250));
171+
}
172+
146173
group('showTopicActionSheet', () {
147174
void checkButtons() {
148175
final actionSheetFinder = find.byType(BottomSheet);
@@ -164,14 +191,7 @@ void main() {
164191
topic: someTopic,
165192
unreadMessageIds: [someMessage.id],
166193
)]));
167-
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
168-
child: const HomePage()));
169-
await tester.pump();
170-
check(find.byType(InboxPageBody)).findsOne();
171-
172-
await tester.longPress(find.text(someTopic));
173-
// sheet appears onscreen; default duration of bottom-sheet enter animation
174-
await tester.pump(const Duration(milliseconds: 250));
194+
await showFromInbox(tester);
175195
checkButtons();
176196
});
177197

0 commit comments

Comments
 (0)