Skip to content

Commit cdc1d7b

Browse files
committed
action_sheet test [nfc]: Pull out showFromInbox helper
1 parent 41f114f commit cdc1d7b

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

test/widgets/action_sheet_test.dart

Lines changed: 31 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,35 @@ void main() {
143144
connection = store.connection as FakeApiConnection;
144145
}
145146

147+
Future<void> showFromInbox(WidgetTester tester, {
148+
String topic = someTopic,
149+
}) async {
150+
assert(() {
151+
final channelIdsWithUnreads = store.unreads.streams.keys;
152+
final topicWithUnreads = channelIdsWithUnreads.firstWhereOrNull((streamId) =>
153+
store.unreads.countInTopicNarrow(streamId, TopicName(topic)) > 0);
154+
if (topicWithUnreads == null) {
155+
throw FlutterError.fromParts([
156+
ErrorSummary('showFromInbox called without an unread message'),
157+
ErrorHint(
158+
'Before calling showFromInbox, ensure that [Unreads] '
159+
'has an unread message in the relevant topic. ',
160+
),
161+
]);
162+
}
163+
return true;
164+
}());
165+
166+
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
167+
child: const HomePage()));
168+
await tester.pump();
169+
check(find.byType(InboxPageBody)).findsOne();
170+
171+
await tester.longPress(find.text(topic));
172+
// sheet appears onscreen; default duration of bottom-sheet enter animation
173+
await tester.pump(const Duration(milliseconds: 250));
174+
}
175+
146176
group('showTopicActionSheet', () {
147177
void checkButtons() {
148178
final actionSheetFinder = find.byType(BottomSheet);
@@ -164,14 +194,7 @@ void main() {
164194
topic: someTopic,
165195
unreadMessageIds: [someMessage.id],
166196
)]));
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));
197+
await showFromInbox(tester);
175198
checkButtons();
176199
});
177200

0 commit comments

Comments
 (0)