Skip to content

Commit 3ade4ff

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

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

test/widgets/action_sheet_test.dart

Lines changed: 19 additions & 11 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,26 +199,29 @@ 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+
transitionDurationObserver = TransitionDurationObserver();
206207
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
208+
navigatorObservers: [transitionDurationObserver],
207209
child: const HomePage()));
208210
await tester.pump();
209211
await tester.tap(find.byIcon(ZulipIcons.hash_italic));
210212
await tester.pump();
211213
check(find.byType(SubscriptionListPageBody)).findsOne();
212214

213215
await tester.longPress(find.text(someChannel.name).hitTestable());
214-
await tester.pump(const Duration(milliseconds: 250));
216+
await transitionDurationObserver.pumpPastTransition(tester);
215217
}
216218

217219
Future<void> showFromMsglistAppBar(WidgetTester tester, {
218220
ZulipStream? channel,
219221
required Narrow narrow,
220222
}) async {
221223
channel ??= someChannel;
224+
transitionDurationObserver = TransitionDurationObserver();
222225

223226
connection.prepare(json: eg.newestGetMessagesResult(
224227
foundOldest: true, messages: []).toJson());
@@ -229,31 +232,34 @@ void main() {
229232
}
230233
await tester.pumpWidget(TestZulipApp(
231234
accountId: eg.selfAccount.id,
235+
navigatorObservers: [transitionDurationObserver],
232236
child: MessageListPage(
233237
initNarrow: narrow)));
234238
await tester.pumpAndSettle();
235239

236240
await tester.longPress(find.descendant(
237241
of: find.byType(ZulipAppBar),
238242
matching: find.text(channel.name)));
239-
await tester.pump(const Duration(milliseconds: 250));
243+
await transitionDurationObserver.pumpPastTransition(tester);
240244
}
241245

242246
Future<void> showFromRecipientHeader(WidgetTester tester, {
243247
StreamMessage? message,
244248
}) async {
245249
message ??= someMessage;
250+
transitionDurationObserver = TransitionDurationObserver();
246251

247252
connection.prepare(json: eg.newestGetMessagesResult(
248253
foundOldest: true, messages: [message]).toJson());
249254
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
255+
navigatorObservers: [transitionDurationObserver],
250256
child: const MessageListPage(initNarrow: CombinedFeedNarrow())));
251257
await tester.pumpAndSettle();
252258

253259
await tester.longPress(find.descendant(
254260
of: find.byType(RecipientHeader),
255261
matching: find.text(message.displayRecipient ?? '')));
256-
await tester.pump(const Duration(milliseconds: 250));
262+
await transitionDurationObserver.pumpPastTransition(tester);
257263
}
258264

259265
Future<void> showFromTopicListAppBar(WidgetTester tester, {int? streamId}) async {
@@ -739,7 +745,7 @@ void main() {
739745

740746
await tester.longPress(find.text(topic));
741747
// sheet appears onscreen; default duration of bottom-sheet enter animation
742-
await tester.pump(const Duration(milliseconds: 250));
748+
await transitionDurationObserver.pumpPastTransition(tester);
743749
}
744750

745751
Future<void> showFromAppBar(WidgetTester tester, {
@@ -766,7 +772,7 @@ void main() {
766772
effectiveTopic.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
767773
await tester.longPress(topicRow);
768774
// sheet appears onscreen; default duration of bottom-sheet enter animation
769-
await tester.pump(const Duration(milliseconds: 250));
775+
await transitionDurationObserver.pumpPastTransition(tester);
770776
}
771777

772778
Future<void> showFromRecipientHeader(WidgetTester tester, {
@@ -785,7 +791,7 @@ void main() {
785791
of: find.byType(RecipientHeader),
786792
matching: find.text(effectiveMessage.topic.displayName!)));
787793
// sheet appears onscreen; default duration of bottom-sheet enter animation
788-
await tester.pump(const Duration(milliseconds: 250));
794+
await transitionDurationObserver.pumpPastTransition(tester);
789795
}
790796

791797
final actionSheetFinder = find.byType(BottomSheet);
@@ -2049,9 +2055,11 @@ void main() {
20492055
delay: const Duration(milliseconds: 500));
20502056
await tapCopyMessageTextButton(tester);
20512057
// … and pump a frame to finish the NavigationState.pop animation…
2052-
await tester.pump(const Duration(milliseconds: 250));
2058+
await transitionDurationObserver.pumpPastTransition(tester);
20532059
// … before the request finishes. This is the repro condition for #732.
2054-
await tester.pump(const Duration(milliseconds: 250));
2060+
await transitionDurationObserver.pumpPastTransition(tester);
2061+
// …pump for snackbar to show
2062+
await tester.pumpAndSettle();
20552063

20562064
final snackbar = tester.widget<SnackBar>(find.byType(SnackBar));
20572065
check(snackbar.behavior).equals(SnackBarBehavior.floating);
@@ -2283,7 +2291,7 @@ void main() {
22832291
// See comment in setupToMessageActionSheet about warnIfMissed: false
22842292
await tester.longPress(find.byType(MessageContent), warnIfMissed: false);
22852293
// sheet appears onscreen; default duration of bottom-sheet enter animation
2286-
await tester.pump(const Duration(milliseconds: 250));
2294+
await transitionDurationObserver.pumpPastTransition(tester);
22872295
check(find.byType(BottomSheet)).findsOne();
22882296
checkButtonIsPresent(expected);
22892297

test/widgets/compose_box_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void main() {
5050
late PerAccountStore store;
5151
late FakeApiConnection connection;
5252
late ComposeBoxState state;
53+
late TransitionDurationObserver transitionDurationObserver;
5354

5455
// Caution: when testing edit-message UI, this will often be stale;
5556
// read state.controller instead.
@@ -96,6 +97,7 @@ void main() {
9697
store = await testBinding.globalStore.perAccount(selfAccount.id);
9798

9899
connection = store.connection as FakeApiConnection;
100+
transitionDurationObserver = TransitionDurationObserver();
99101

100102
connection.prepare(json:
101103
eg.newestGetMessagesResult(foundOldest: true, messages: messages).toJson());
@@ -104,6 +106,7 @@ void main() {
104106
connection.prepare(json: GetStreamTopicsResult(topics: []).toJson());
105107
}
106108
await tester.pumpWidget(TestZulipApp(accountId: selfAccount.id,
109+
navigatorObservers: [transitionDurationObserver],
107110
child: MessageListPage(initNarrow: narrow)));
108111
await tester.pumpAndSettle();
109112
connection.takeRequests();
@@ -1719,7 +1722,7 @@ void main() {
17191722
await tester.longPress(find.byWidgetPredicate((widget) =>
17201723
widget is MessageWithPossibleSender && widget.item.message.id == messageId));
17211724
// sheet appears onscreen; default duration of bottom-sheet enter animation
1722-
await tester.pump(const Duration(milliseconds: 250));
1725+
await transitionDurationObserver.pumpPastTransition(tester);
17231726
final findEditButton = find.descendant(
17241727
of: find.byType(BottomSheet),
17251728
matching: find.byIcon(ZulipIcons.edit, skipOffstage: false));
@@ -1862,7 +1865,6 @@ void main() {
18621865
await tester.pump();
18631866
check(state).controller.content.text.equals('composing something');
18641867
});
1865-
18661868
testWidgets('interrupting message edit: proceed through confirmation dialog', (tester) async {
18671869
await prepareMessageNotSent(tester, narrow: topicNarrow);
18681870

@@ -1875,7 +1877,7 @@ void main() {
18751877
await startEditInteractionFromActionSheet(tester, messageId: messageToEdit.id,
18761878
originalRawContent: 'message to edit',
18771879
delay: Duration.zero);
1878-
await tester.pump(const Duration(milliseconds: 250)); // bottom-sheet animation
1880+
await transitionDurationObserver.pumpPastTransition(tester); // bottom-sheet animation
18791881

18801882
await tester.tap(failedMessageFinder);
18811883
await tester.pump();
@@ -1889,7 +1891,6 @@ void main() {
18891891

18901892
testWidgets('interrupting message edit: cancel confirmation dialog', (tester) async {
18911893
await prepareMessageNotSent(tester, narrow: topicNarrow);
1892-
18931894
final messageToEdit = eg.streamMessage(
18941895
sender: eg.selfUser, stream: channel, topic: topic,
18951896
content: 'message to edit');
@@ -1899,7 +1900,7 @@ void main() {
18991900
await startEditInteractionFromActionSheet(tester, messageId: messageToEdit.id,
19001901
originalRawContent: 'message to edit',
19011902
delay: Duration.zero);
1902-
await tester.pump(const Duration(milliseconds: 250)); // bottom-sheet animation
1903+
await transitionDurationObserver.pumpPastTransition(tester); // bottom-sheet animation
19031904

19041905
await tester.tap(failedMessageFinder);
19051906
await tester.pump();
@@ -2352,4 +2353,4 @@ enum _EditInteractionStart {
23522353
_EditInteractionStart.restoreFailedEdit => 'from restoring a failed edit',
23532354
};
23542355
}
2355-
}
2356+
}

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)