From c2bbd60b27bec0f20c48534b115db5772058404d Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 29 Jun 2026 13:56:28 -0700 Subject: [PATCH 1/6] Re-enabled dialog_test. TestSemantics to tester.semantics.find. --- .../dialog_test.dart | 89 +++++-------------- 1 file changed, 22 insertions(+), 67 deletions(-) rename packages/cupertino_ui/{temporarily_disabled_tests => test}/dialog_test.dart (96%) diff --git a/packages/cupertino_ui/temporarily_disabled_tests/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart similarity index 96% rename from packages/cupertino_ui/temporarily_disabled_tests/dialog_test.dart rename to packages/cupertino_ui/test/dialog_test.dart index 9125825606e5..f77665dbb09d 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@Skip( - 'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.', -) // This file is run as part of a reduced test set in CI on Mac and Windows // machines. @Tags(['reduced-test-set']) @@ -19,8 +16,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/semantics_tester.dart'; - void main() { testWidgets('Overall appearance is correct for the light theme', (WidgetTester tester) async { await tester.pumpWidget( @@ -683,7 +678,6 @@ void main() { }); testWidgets('Has semantic annotations', (WidgetTester tester) async { - final semantics = SemanticsTester(tester); await tester.pumpWidget( const CupertinoApp( home: CupertinoAlertDialog( @@ -697,63 +691,26 @@ void main() { ), ); + final Finder dialogFinder = find.bySemanticsLabel('Alert'); + final SemanticsNode dialog = tester.semantics.find(find.bySemanticsLabel('Alert')); + expect(dialog.role, SemanticsRole.alertDialog); + expect(dialog, isSemantics(namesRoute: true, scopesRoute: true)); expect( - semantics, - hasSemantics( - TestSemantics.root( - children: [ - TestSemantics( - children: [ - TestSemantics( - children: [ - TestSemantics( - flags: [SemanticsFlag.scopesRoute], - children: [ - TestSemantics( - flags: [ - SemanticsFlag.scopesRoute, - SemanticsFlag.namesRoute, - ], - role: SemanticsRole.alertDialog, - label: 'Alert', - children: [ - TestSemantics( - flags: [SemanticsFlag.hasImplicitScrolling], - children: [ - TestSemantics(label: 'The Title'), - TestSemantics(label: 'Content'), - ], - ), - TestSemantics( - flags: [SemanticsFlag.hasImplicitScrolling], - children: [ - TestSemantics( - flags: [SemanticsFlag.isButton], - label: 'Cancel', - ), - TestSemantics( - flags: [SemanticsFlag.isButton], - label: 'OK', - ), - ], - ), - ], - ), - ], - ), - ], - ), - ], - ), - ], - ), - ignoreId: true, - ignoreRect: true, - ignoreTransform: true, - ), + find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('The Title')), + findsOneWidget, ); - - semantics.dispose(); + expect( + find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('Content')), + findsOneWidget, + ); + final SemanticsNode buttonOK = tester.semantics.find( + find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('OK')), + ); + expect(buttonOK, isSemantics(isButton: true)); + final SemanticsNode buttonCancel = tester.semantics.find( + find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('Cancel')), + ); + expect(buttonCancel, isSemantics(isButton: true)); }); testWidgets('Dialog default action style', (WidgetTester tester) async { @@ -1699,8 +1656,6 @@ void main() { }); testWidgets('showCupertinoDialog - custom barrierLabel', (WidgetTester tester) async { - final semantics = SemanticsTester(tester); - await tester.pumpWidget( CupertinoApp( home: Builder( @@ -1732,12 +1687,12 @@ void main() { ); expect( - semantics, - isNot( - includesNodeWith(label: 'Custom label', flags: [SemanticsFlag.namesRoute]), + find.semantics.byPredicate( + (SemanticsNode semantics) => + semantics.label == 'Custom label' && semantics.hasFlag(SemanticsFlag.namesRoute), ), + findsNothing, ); - semantics.dispose(); }); testWidgets('showCupertinoDialog - custom barrierColor', (WidgetTester tester) async { From cf7cc299598cc21b3ba86b416de688dae78c755b Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 29 Jun 2026 13:57:20 -0700 Subject: [PATCH 2/6] Unawaited --- packages/cupertino_ui/test/dialog_test.dart | 85 ++++++++++++--------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/packages/cupertino_ui/test/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart index f77665dbb09d..16765c3aebc8 100644 --- a/packages/cupertino_ui/test/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -7,6 +7,7 @@ @Tags(['reduced-test-set']) library; +import 'dart:async' show unawaited; import 'dart:math'; import 'dart:ui'; @@ -570,16 +571,18 @@ void main() { final BuildContext context = tester.element(find.text('Go')); - showCupertinoDialog( - context: context, - builder: (BuildContext context) { - return Container( - width: 100.0, - height: 100.0, - alignment: Alignment.center, - child: const Text('Dialog'), - ); - }, + unawaited( + showCupertinoDialog( + context: context, + builder: (BuildContext context) { + return Container( + width: 100.0, + height: 100.0, + alignment: Alignment.center, + child: const Text('Dialog'), + ); + }, + ), ); await tester.pumpAndSettle(const Duration(seconds: 1)); @@ -597,17 +600,19 @@ void main() { final BuildContext context = tester.element(find.text('Go')); - showCupertinoDialog( - context: context, - barrierDismissible: true, - builder: (BuildContext context) { - return Container( - width: 100.0, - height: 100.0, - alignment: Alignment.center, - child: const Text('Dialog'), - ); - }, + unawaited( + showCupertinoDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return Container( + width: 100.0, + height: 100.0, + alignment: Alignment.center, + child: const Text('Dialog'), + ); + }, + ), ); await tester.pumpAndSettle(const Duration(seconds: 1)); @@ -1868,12 +1873,14 @@ void main() { ); final BuildContext context = tester.element(find.text('Test')); - showCupertinoDialog( - context: context, - builder: (BuildContext context) { - return const Placeholder(); - }, - anchorPoint: const Offset(1000, 0), + unawaited( + showCupertinoDialog( + context: context, + builder: (BuildContext context) { + return const Placeholder(); + }, + anchorPoint: const Offset(1000, 0), + ), ); await tester.pumpAndSettle(); @@ -1906,11 +1913,13 @@ void main() { ); final BuildContext context = tester.element(find.text('Test')); - showCupertinoDialog( - context: context, - builder: (BuildContext context) { - return const Placeholder(); - }, + unawaited( + showCupertinoDialog( + context: context, + builder: (BuildContext context) { + return const Placeholder(); + }, + ), ); await tester.pumpAndSettle(); @@ -1943,11 +1952,13 @@ void main() { ); final BuildContext context = tester.element(find.text('Test')); - showCupertinoDialog( - context: context, - builder: (BuildContext context) { - return const Placeholder(); - }, + unawaited( + showCupertinoDialog( + context: context, + builder: (BuildContext context) { + return const Placeholder(); + }, + ), ); await tester.pumpAndSettle(); From ab8a7ceba58b5c771f0c852de0e221338f31ae81 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 29 Jun 2026 15:57:56 -0700 Subject: [PATCH 3/6] SemanticsHandle --- packages/cupertino_ui/test/dialog_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/cupertino_ui/test/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart index 16765c3aebc8..c3b5a32a2149 100644 --- a/packages/cupertino_ui/test/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -683,6 +683,9 @@ void main() { }); testWidgets('Has semantic annotations', (WidgetTester tester) async { + final SemanticsHandle semanticsHandle = tester.ensureSemantics(); + addTearDown(semanticsHandle.dispose); + await tester.pumpWidget( const CupertinoApp( home: CupertinoAlertDialog( @@ -1661,6 +1664,9 @@ void main() { }); testWidgets('showCupertinoDialog - custom barrierLabel', (WidgetTester tester) async { + final SemanticsHandle semanticsHandle = tester.ensureSemantics(); + addTearDown(semanticsHandle.dispose); + await tester.pumpWidget( CupertinoApp( home: Builder( From b335d18ba59731000af96732ef0c938685818244 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 29 Jun 2026 16:01:27 -0700 Subject: [PATCH 4/6] Simplify byPredicate to byLabel --- packages/cupertino_ui/test/dialog_test.dart | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/cupertino_ui/test/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart index c3b5a32a2149..3f520954a75a 100644 --- a/packages/cupertino_ui/test/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -1697,13 +1697,7 @@ void main() { ), ); - expect( - find.semantics.byPredicate( - (SemanticsNode semantics) => - semantics.label == 'Custom label' && semantics.hasFlag(SemanticsFlag.namesRoute), - ), - findsNothing, - ); + expect(find.semantics.byLabel('Custom label'), findsNothing); }); testWidgets('showCupertinoDialog - custom barrierColor', (WidgetTester tester) async { From d977332a27bb2e18459369c93248dc5eaf1c617d Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 29 Jun 2026 18:50:50 -0700 Subject: [PATCH 5/6] No ensureSemantics needed. --- packages/cupertino_ui/test/dialog_test.dart | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/cupertino_ui/test/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart index 3f520954a75a..b995d83ae286 100644 --- a/packages/cupertino_ui/test/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -683,9 +683,6 @@ void main() { }); testWidgets('Has semantic annotations', (WidgetTester tester) async { - final SemanticsHandle semanticsHandle = tester.ensureSemantics(); - addTearDown(semanticsHandle.dispose); - await tester.pumpWidget( const CupertinoApp( home: CupertinoAlertDialog( @@ -1664,9 +1661,6 @@ void main() { }); testWidgets('showCupertinoDialog - custom barrierLabel', (WidgetTester tester) async { - final SemanticsHandle semanticsHandle = tester.ensureSemantics(); - addTearDown(semanticsHandle.dispose); - await tester.pumpWidget( CupertinoApp( home: Builder( From 4ee13ef3849ae14a85c1c66aa8d2b760a2723abe Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Wed, 1 Jul 2026 09:33:36 -0700 Subject: [PATCH 6/6] Test whole tree. --- packages/cupertino_ui/test/dialog_test.dart | 37 ++++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/cupertino_ui/test/dialog_test.dart b/packages/cupertino_ui/test/dialog_test.dart index b995d83ae286..c43a5600d19a 100644 --- a/packages/cupertino_ui/test/dialog_test.dart +++ b/packages/cupertino_ui/test/dialog_test.dart @@ -696,26 +696,31 @@ void main() { ), ); - final Finder dialogFinder = find.bySemanticsLabel('Alert'); final SemanticsNode dialog = tester.semantics.find(find.bySemanticsLabel('Alert')); expect(dialog.role, SemanticsRole.alertDialog); - expect(dialog, isSemantics(namesRoute: true, scopesRoute: true)); expect( - find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('The Title')), - findsOneWidget, - ); - expect( - find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('Content')), - findsOneWidget, - ); - final SemanticsNode buttonOK = tester.semantics.find( - find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('OK')), - ); - expect(buttonOK, isSemantics(isButton: true)); - final SemanticsNode buttonCancel = tester.semantics.find( - find.descendant(of: dialogFinder, matching: find.bySemanticsLabel('Cancel')), + dialog, + isSemantics( + namesRoute: true, + scopesRoute: true, + children: [ + isSemantics( + hasImplicitScrolling: true, + children: [ + isSemantics(label: 'The Title'), + isSemantics(label: 'Content'), + ], + ), + isSemantics( + hasImplicitScrolling: true, + children: [ + isSemantics(label: 'Cancel', isButton: true), + isSemantics(label: 'OK', isButton: true), + ], + ), + ], + ), ); - expect(buttonCancel, isSemantics(isButton: true)); }); testWidgets('Dialog default action style', (WidgetTester tester) async {