Skip to content

Commit af69cbf

Browse files
Get route-transition duration robustly
1 parent 3d3b1c1 commit af69cbf

File tree

3 files changed

+60
-31
lines changed

3 files changed

+60
-31
lines changed

test/widgets/action_sheet_test.dart

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
140140
// like if it's in padding around a Paragraph.
141141
await tester.longPress(find.byType(MessageContent), warnIfMissed: false);
142142
// sheet appears onscreen; default duration of bottom-sheet enter animation
143-
await tester.pump(const Duration(milliseconds: 250));
143+
await transitionDurationObserver.pumpPastTransition(tester);
144144
// Check the action sheet did in fact open, so we don't defeat any tests that
145145
// use simple `find.byIcon`-style checks to test presence/absence of a button.
146146
check(find.byType(BottomSheet)).findsOne();
@@ -199,19 +199,22 @@ void main() {
199199
check(find.byType(InboxPageBody)).findsOne();
200200

201201
await tester.longPress(find.text(someChannel.name).hitTestable());
202-
await tester.pump(const Duration(milliseconds: 250));
202+
await transitionDurationObserver.pumpPastTransition(tester);
203203
}
204204

205205
Future<void> showFromSubscriptionList(WidgetTester tester) async {
206+
final transitionDurationObserver = TransitionDurationObserver();
207+
206208
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
209+
navigatorObservers: [transitionDurationObserver],
207210
child: const HomePage()));
208211
await tester.pump();
209212
await tester.tap(find.byIcon(ZulipIcons.hash_italic));
210213
await tester.pump();
211214
check(find.byType(SubscriptionListPageBody)).findsOne();
212215

213216
await tester.longPress(find.text(someChannel.name).hitTestable());
214-
await tester.pump(const Duration(milliseconds: 250));
217+
await transitionDurationObserver.pumpPastTransition(tester);
215218
}
216219

217220
Future<void> showFromMsglistAppBar(WidgetTester tester, {
@@ -220,6 +223,8 @@ void main() {
220223
}) async {
221224
channel ??= someChannel;
222225

226+
final transitionDurationObserver = TransitionDurationObserver();
227+
223228
connection.prepare(json: eg.newestGetMessagesResult(
224229
foundOldest: true, messages: []).toJson());
225230
if (narrow case ChannelNarrow()) {
@@ -229,31 +234,35 @@ void main() {
229234
}
230235
await tester.pumpWidget(TestZulipApp(
231236
accountId: eg.selfAccount.id,
237+
navigatorObservers: [transitionDurationObserver],
232238
child: MessageListPage(
233239
initNarrow: narrow)));
234240
await tester.pumpAndSettle();
235241

236242
await tester.longPress(find.descendant(
237243
of: find.byType(ZulipAppBar),
238244
matching: find.text(channel.name)));
239-
await tester.pump(const Duration(milliseconds: 250));
245+
await transitionDurationObserver.pumpPastTransition(tester);
240246
}
241247

242248
Future<void> showFromRecipientHeader(WidgetTester tester, {
243249
StreamMessage? message,
244250
}) async {
245251
message ??= someMessage;
246252

253+
final transitionDurationObserver = TransitionDurationObserver();
254+
247255
connection.prepare(json: eg.newestGetMessagesResult(
248256
foundOldest: true, messages: [message]).toJson());
249257
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
258+
navigatorObservers: [transitionDurationObserver],
250259
child: const MessageListPage(initNarrow: CombinedFeedNarrow())));
251260
await tester.pumpAndSettle();
252261

253262
await tester.longPress(find.descendant(
254263
of: find.byType(RecipientHeader),
255264
matching: find.text(message.displayRecipient ?? '')));
256-
await tester.pump(const Duration(milliseconds: 250));
265+
await transitionDurationObserver.pumpPastTransition(tester);
257266
}
258267

259268
Future<void> showFromTopicListAppBar(WidgetTester tester, {int? streamId}) async {
@@ -739,7 +748,7 @@ void main() {
739748

740749
await tester.longPress(find.text(topic));
741750
// sheet appears onscreen; default duration of bottom-sheet enter animation
742-
await tester.pump(const Duration(milliseconds: 250));
751+
await transitionDurationObserver.pumpPastTransition(tester);
743752
}
744753

745754
Future<void> showFromAppBar(WidgetTester tester, {
@@ -766,7 +775,7 @@ void main() {
766775
effectiveTopic.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
767776
await tester.longPress(topicRow);
768777
// sheet appears onscreen; default duration of bottom-sheet enter animation
769-
await tester.pump(const Duration(milliseconds: 250));
778+
await transitionDurationObserver.pumpPastTransition(tester);
770779
}
771780

772781
Future<void> showFromRecipientHeader(WidgetTester tester, {
@@ -785,7 +794,7 @@ void main() {
785794
of: find.byType(RecipientHeader),
786795
matching: find.text(effectiveMessage.topic.displayName!)));
787796
// sheet appears onscreen; default duration of bottom-sheet enter animation
788-
await tester.pump(const Duration(milliseconds: 250));
797+
await transitionDurationObserver.pumpPastTransition(tester);
789798
}
790799

791800
final actionSheetFinder = find.byType(BottomSheet);
@@ -2037,21 +2046,28 @@ void main() {
20372046
check(await Clipboard.getData('text/plain')).isNotNull().text.equals('Hello world');
20382047
});
20392048

2040-
testWidgets('can show snackbar on success', (tester) async {
2049+
testWidgets('can show snackbar on success', (WidgetTester tester) async {
20412050
// Regression test for: https://github.com/zulip/zulip-flutter/issues/732
2042-
testBinding.deviceInfoResult = const IosDeviceInfo(systemVersion: '16.0');
2043-
2051+
final TransitionDurationObserver transitionDurationObserver = TransitionDurationObserver();
2052+
await tester.pumpWidget(
2053+
MaterialApp(
2054+
navigatorObservers: <NavigatorObserver>[transitionDurationObserver],
2055+
home: Scaffold(
2056+
body: Builder(builder: (context) {
2057+
testBinding.deviceInfoResult = const IosDeviceInfo(systemVersion: '16.0');
2058+
final message = eg.streamMessage();
2059+
setupToMessageActionSheet(tester,message: message,narrow: TopicNarrow.ofMessage(message));
2060+
return const SizedBox.shrink();}
2061+
))));
20442062
final message = eg.streamMessage();
2045-
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));
2046-
20472063
// Make the request take a bit of time to complete…
20482064
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world',
20492065
delay: const Duration(milliseconds: 500));
20502066
await tapCopyMessageTextButton(tester);
20512067
// … and pump a frame to finish the NavigationState.pop animation…
2052-
await tester.pump(const Duration(milliseconds: 250));
2068+
await transitionDurationObserver.pumpPastTransition(tester);
20532069
// … before the request finishes. This is the repro condition for #732.
2054-
await tester.pump(const Duration(milliseconds: 250));
2070+
await transitionDurationObserver.pumpPastTransition(tester);
20552071

20562072
final snackbar = tester.widget<SnackBar>(find.byType(SnackBar));
20572073
check(snackbar.behavior).equals(SnackBarBehavior.floating);
@@ -2283,7 +2299,7 @@ void main() {
22832299
// See comment in setupToMessageActionSheet about warnIfMissed: false
22842300
await tester.longPress(find.byType(MessageContent), warnIfMissed: false);
22852301
// sheet appears onscreen; default duration of bottom-sheet enter animation
2286-
await tester.pump(const Duration(milliseconds: 250));
2302+
await transitionDurationObserver.pumpPastTransition(tester);
22872303
check(find.byType(BottomSheet)).findsOne();
22882304
checkButtonIsPresent(expected);
22892305

test/widgets/compose_box_test.dart

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ void main() {
17191719
await tester.longPress(find.byWidgetPredicate((widget) =>
17201720
widget is MessageWithPossibleSender && widget.item.message.id == messageId));
17211721
// sheet appears onscreen; default duration of bottom-sheet enter animation
1722-
await tester.pump(const Duration(milliseconds: 250));
1722+
await tester.pumpAndSettle();
17231723
final findEditButton = find.descendant(
17241724
of: find.byType(BottomSheet),
17251725
matching: find.byIcon(ZulipIcons.edit, skipOffstage: false));
@@ -1862,10 +1862,17 @@ void main() {
18621862
await tester.pump();
18631863
check(state).controller.content.text.equals('composing something');
18641864
});
1865-
1866-
testWidgets('interrupting message edit: proceed through confirmation dialog', (tester) async {
1867-
await prepareMessageNotSent(tester, narrow: topicNarrow);
1868-
1865+
testWidgets('interrupting message edit: proceed through confirmation dialog', (WidgetTester tester) async {
1866+
final TransitionDurationObserver transitionDurationObserver = TransitionDurationObserver();
1867+
1868+
await tester.pumpWidget(
1869+
MaterialApp(
1870+
navigatorObservers: <NavigatorObserver>[transitionDurationObserver],
1871+
home: Scaffold(
1872+
body: Builder(builder: (context) {
1873+
prepareMessageNotSent(tester, narrow: topicNarrow);
1874+
return const SizedBox.shrink();},
1875+
))));
18691876
final messageToEdit = eg.streamMessage(
18701877
sender: eg.selfUser, stream: channel, topic: topic,
18711878
content: 'message to edit');
@@ -1875,21 +1882,28 @@ void main() {
18751882
await startEditInteractionFromActionSheet(tester, messageId: messageToEdit.id,
18761883
originalRawContent: 'message to edit',
18771884
delay: Duration.zero);
1878-
await tester.pump(const Duration(milliseconds: 250)); // bottom-sheet animation
1885+
await transitionDurationObserver.pumpPastTransition(tester);// bottom-sheet animation
18791886

18801887
await tester.tap(failedMessageFinder);
18811888
await tester.pump();
18821889
check(state).controller.content.text.equals('message to edit');
18831890

1884-
await expectAndHandleDiscardForMessageNotSentConfirmation(tester,
1885-
shouldContinue: true);
1891+
await expectAndHandleDiscardForMessageNotSentConfirmation(tester, shouldContinue: true);
18861892
await tester.pump();
18871893
check(state).controller.content.text.equals(failedMessageContent);
18881894
});
18891895

1890-
testWidgets('interrupting message edit: cancel confirmation dialog', (tester) async {
1891-
await prepareMessageNotSent(tester, narrow: topicNarrow);
1892-
1896+
testWidgets('interrupting message edit: cancel confirmation dialog', (WidgetTester tester) async {
1897+
final TransitionDurationObserver transitionDurationObserver = TransitionDurationObserver();
1898+
1899+
await tester.pumpWidget(
1900+
MaterialApp(
1901+
navigatorObservers: <NavigatorObserver>[transitionDurationObserver],
1902+
home: Scaffold(
1903+
body: Builder(builder: (context) {
1904+
prepareMessageNotSent(tester, narrow: topicNarrow);
1905+
return const SizedBox.shrink();},
1906+
))));
18931907
final messageToEdit = eg.streamMessage(
18941908
sender: eg.selfUser, stream: channel, topic: topic,
18951909
content: 'message to edit');
@@ -1899,7 +1913,7 @@ void main() {
18991913
await startEditInteractionFromActionSheet(tester, messageId: messageToEdit.id,
19001914
originalRawContent: 'message to edit',
19011915
delay: Duration.zero);
1902-
await tester.pump(const Duration(milliseconds: 250)); // bottom-sheet animation
1916+
await transitionDurationObserver.pumpPastTransition(tester); // bottom-sheet animation
19031917

19041918
await tester.tap(failedMessageFinder);
19051919
await tester.pump();
@@ -2352,4 +2366,4 @@ enum _EditInteractionStart {
23522366
_EditInteractionStart.restoreFailedEdit => 'from restoring a failed edit',
23532367
};
23542368
}
2355-
}
2369+
}

test/widgets/emoji_reaction_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ void main() {
434434
// request the message action sheet
435435
await tester.longPress(find.byType(MessageContent));
436436
// sheet appears onscreen; default duration of bottom-sheet enter animation
437-
await tester.pump(const Duration(milliseconds: 250));
438-
437+
await transitionDurationObserver.pumpPastTransition(tester);
439438
await store.handleEvent(RealmEmojiUpdateEvent(id: 1, realmEmoji: {
440439
'1': eg.realmEmojiItem(emojiCode: '1', emojiName: 'buzzing'),
441440
}));

0 commit comments

Comments
 (0)