Add tests for ordered_traversal_group.0.dart (#152849)

Contributes to https://github.com/flutter/flutter/issues/130459

It adds a test for
- `examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart`
This commit is contained in:
Valentin Vignal 2024-08-06 10:28:25 +08:00 committed by GitHub
parent 0397e890be
commit ff3ad8290e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 4 deletions

View File

@ -343,7 +343,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart',
'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart',
'examples/api/test/widgets/animated_list/animated_list.0_test.dart',
'examples/api/test/widgets/focus_traversal/ordered_traversal_policy.0_test.dart',
'examples/api/test/widgets/image/image.frame_builder.0_test.dart',
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
'examples/api/test/widgets/page_storage/page_storage.0_test.dart',

View File

@ -8,9 +8,9 @@ import 'package:flutter_api_samples/widgets/focus_traversal/focus_traversal_grou
import 'package:flutter_test/flutter_test.dart';
void main() {
bool hasFocus(WidgetTester tester, String text) {
return Focus.of(tester.element(find.text(text))).hasPrimaryFocus;
}
bool hasFocus(WidgetTester tester, String text) {
return Focus.of(tester.element(find.text(text))).hasPrimaryFocus;
}
testWidgets('The focus updates should follow the focus traversal groups policy', (WidgetTester tester) async {
await tester.pumpWidget(

View File

@ -0,0 +1,38 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_traversal/ordered_traversal_policy.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
bool hasFocus(WidgetTester tester, String text) {
return Focus.of(tester.element(find.text(text))).hasPrimaryFocus;
}
testWidgets('The focus updates should follow the focus traversal groups policy', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OrderedTraversalPolicyExampleApp(),
);
expect(hasFocus(tester, 'One'), isTrue);
const List<String> focusOrder = <String>[
'Two',
'Three',
'Four',
'Five',
'Six',
'One',
];
for (final String text in focusOrder) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
expect(hasFocus(tester, text), isTrue);
}
});
}