Repository navigation
[cupertino_ui] Migrate route_test.dart to SemanticsHandle
#11993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,17 @@ | |
| // 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.', | ||
| ) | ||
| @TestOn('!chrome') | ||
| library; | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:cupertino_ui/cupertino_ui.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/rendering.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| import '../widgets/semantics_tester.dart'; | ||
|
|
||
| void main() { | ||
| late MockNavigatorObserver navigatorObserver; | ||
|
|
||
|
|
@@ -1571,11 +1567,11 @@ void main() { | |
| if (paintColor.value == color.value) { | ||
| return true; | ||
| } | ||
| throw ''' | ||
| fail(''' | ||
| For a rect with an expected left-side position: $dx (drawn at ${rect.left}): | ||
| Expected a rect with color: $color, | ||
| And drew a rect with color: $paintColor. | ||
| '''; | ||
| '''); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -1653,10 +1649,10 @@ void main() { | |
| final bool isOnScreen = rect.left >= 0 && rect.right <= 600.0; | ||
|
|
||
| if (isOnScreen) { | ||
| throw ''' | ||
| fail(''' | ||
| Expected: no visible rects on-screen. | ||
| Found: $rect. | ||
| '''; | ||
| '''); | ||
| } | ||
| } | ||
| return true; | ||
|
|
@@ -2045,7 +2041,8 @@ void main() { | |
| WidgetTester tester, | ||
| ) async { | ||
| debugDefaultTargetPlatformOverride = TargetPlatform.iOS; | ||
| final semantics = SemanticsTester(tester); | ||
| final SemanticsHandle handle = tester.ensureSemantics(); | ||
|
|
||
| await tester.pumpWidget( | ||
| CupertinoApp( | ||
| home: Navigator( | ||
|
|
@@ -2072,24 +2069,18 @@ void main() { | |
| await tester.tap(find.text('tap')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect( | ||
| semantics, | ||
| isNot( | ||
| includesNodeWith( | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus], | ||
| label: 'Dismiss', | ||
| ), | ||
| ), | ||
| ); | ||
| expect(find.semantics.byLabel('Dismiss'), findsNothing); | ||
|
|
||
| debugDefaultTargetPlatformOverride = null; | ||
| semantics.dispose(); | ||
| handle.dispose(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
|
|
||
| testWidgets('showCupertinoModalPopup allows for semantics dismiss when set', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| debugDefaultTargetPlatformOverride = TargetPlatform.iOS; | ||
| final semantics = SemanticsTester(tester); | ||
| final SemanticsHandle handle = tester.ensureSemantics(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overriding debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() {
debugDefaultTargetPlatformOverride = null;
});
final SemanticsHandle handle = tester.ensureSemantics();
addTearDown(handle.dispose); |
||
|
|
||
| await tester.pumpWidget( | ||
| CupertinoApp( | ||
| home: Navigator( | ||
|
|
@@ -2118,14 +2109,12 @@ void main() { | |
| await tester.pumpAndSettle(); | ||
|
|
||
| expect( | ||
| semantics, | ||
| includesNodeWith( | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.dismiss], | ||
| label: 'Dismiss', | ||
| ), | ||
| find.semantics.byLabel('Dismiss'), | ||
| isSemantics(label: 'Dismiss', hasTapAction: true, hasDismissAction: true), | ||
| ); | ||
|
|
||
| debugDefaultTargetPlatformOverride = null; | ||
| semantics.dispose(); | ||
| handle.dispose(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
|
|
||
| testWidgets('showCupertinoModalPopup passes RouteSettings to PopupRoute', ( | ||
|
|
@@ -2559,12 +2548,14 @@ void main() { | |
| ); | ||
| final BuildContext context = tester.element(find.text('Test')); | ||
|
|
||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| anchorPoint: const Offset(1000, 0), | ||
| unawaited( | ||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| anchorPoint: const Offset(1000, 0), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -2597,11 +2588,13 @@ void main() { | |
| ); | ||
| final BuildContext context = tester.element(find.text('Test')); | ||
|
|
||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| unawaited( | ||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -2634,11 +2627,13 @@ void main() { | |
| ); | ||
| final BuildContext context = tester.element(find.text('Test')); | ||
|
|
||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| unawaited( | ||
| showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -2673,12 +2668,14 @@ void main() { | |
| ); | ||
|
|
||
| final BuildContext context = tester.element(find.text('Test')); | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| anchorPoint: const Offset(1000, 0), | ||
| unawaited( | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| anchorPoint: const Offset(1000, 0), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -2711,11 +2708,13 @@ void main() { | |
| ); | ||
|
|
||
| final BuildContext context = tester.element(find.text('Test')); | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| unawaited( | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -2748,11 +2747,13 @@ void main() { | |
| ); | ||
|
|
||
| final BuildContext context = tester.element(find.text('Test')); | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| unawaited( | ||
| showCupertinoModalPopup<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return const Placeholder(); | ||
| }, | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
|
|
@@ -3137,10 +3138,12 @@ void main() { | |
| await tester.pump(); | ||
| expect(focusNode.hasFocus, true); | ||
|
|
||
| showCupertinoModalPopup<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: true, | ||
| builder: (BuildContext context) => const Text('popup'), | ||
| unawaited( | ||
| showCupertinoModalPopup<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: true, | ||
| builder: (BuildContext context) => const Text('popup'), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
| expect(FocusScope.of(tester.element(find.text('popup'))).hasFocus, true); | ||
|
|
@@ -3150,10 +3153,12 @@ void main() { | |
| await tester.pumpAndSettle(); | ||
| expect(focusNode.hasFocus, true); | ||
|
|
||
| showCupertinoModalPopup<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: false, | ||
| builder: (BuildContext context) => const Text('popup'), | ||
| unawaited( | ||
| showCupertinoModalPopup<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: false, | ||
| builder: (BuildContext context) => const Text('popup'), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
| expect(FocusScope.of(tester.element(find.text('popup'))).hasFocus, false); | ||
|
|
@@ -3174,10 +3179,12 @@ void main() { | |
| await tester.pump(); | ||
| expect(focusNode.hasFocus, true); | ||
|
|
||
| showCupertinoDialog<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: true, | ||
| builder: (BuildContext context) => const Text('dialog'), | ||
| unawaited( | ||
| showCupertinoDialog<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: true, | ||
| builder: (BuildContext context) => const Text('dialog'), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
| expect(FocusScope.of(tester.element(find.text('dialog'))).hasFocus, true); | ||
|
|
@@ -3187,10 +3194,12 @@ void main() { | |
| await tester.pumpAndSettle(); | ||
| expect(focusNode.hasFocus, true); | ||
|
|
||
| showCupertinoDialog<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: false, | ||
| builder: (BuildContext context) => const Text('dialog'), | ||
| unawaited( | ||
| showCupertinoDialog<void>( | ||
| context: navigatorKey.currentContext!, | ||
| requestFocus: false, | ||
| builder: (BuildContext context) => const Text('dialog'), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
| expect(FocusScope.of(tester.element(find.text('dialog'))).hasFocus, false); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overriding
debugDefaultTargetPlatformOverridewithout ensuring it is reset in anaddTearDownblock can leak the iOS platform override to subsequent tests if this test fails. UsingaddTearDownensures that both the platform override and theSemanticsHandleare properly cleaned up regardless of test success or failure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensureSemantics is no longer needed per @chunhtai.