diff --git a/test/page_screenshots_test.dart b/test/page_screenshots_test.dart index 4a2613b2..985f282e 100644 --- a/test/page_screenshots_test.dart +++ b/test/page_screenshots_test.dart @@ -712,7 +712,12 @@ void main() { await tester.pump(); // It stays up, saying so, until the capture has stopped. expect(find.text('Stopping…'), findsOneWidget); - // The clock moves too, so the dialog's closing animation plays out. + // The clock moves too, so the dialog's closing animation plays out. The + // toast is shown while real time passes here, so its closing timer runs + // on real time: it is looked for as it shows, and taken away at once, + // so it neither closes before the check on a slow machine nor closes + // itself after the test, on a torn-down tree. + var toldCancelled = false; for (var i = 0; i < 400 && find.text('Saving screenshots').evaluate().isNotEmpty; i++) { @@ -720,6 +725,11 @@ void main() { () => Future.delayed(const Duration(milliseconds: 16)), ); await tester.pump(const Duration(milliseconds: 16)); + if (!toldCancelled && + find.text('Screenshots cancelled.').evaluate().isNotEmpty) { + toldCancelled = true; + toastification.dismissAll(delayForAnimation: false); + } } for (var i = 0; i < 10; i++) { await tester.pump(const Duration(milliseconds: 100)); @@ -729,10 +739,10 @@ void main() { expect(find.byType(EditorToolbar), findsOneWidget); expect(find.text('Library'), findsNothing); expect(folder.listSync(), isEmpty); - expect(find.text('Screenshots cancelled.'), findsOneWidget); + expect(toldCancelled, isTrue); ignoreTestFontOverflow(tester); - // Let the toast leave. - await tester.pump(const Duration(seconds: 10)); + // Let the toast's removal play out. + await tester.pump(const Duration(seconds: 4)); }); testWidgets('a finished capture closes only its own dialog', (tester) async {