Add tests for editable_text.on_changed.0.dart API example. (#148874)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Adds tests for `examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart`
This commit is contained in:
parent
aa6382093e
commit
7be97ab781
@ -395,7 +395,6 @@ final Set<String> _knownMissingTests = <String>{
|
|||||||
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
|
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
|
||||||
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
|
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
|
||||||
'examples/api/test/widgets/notification_listener/notification.0_test.dart',
|
'examples/api/test/widgets/notification_listener/notification.0_test.dart',
|
||||||
'examples/api/test/widgets/editable_text/editable_text.on_changed.0_test.dart',
|
|
||||||
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.1_test.dart',
|
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.1_test.dart',
|
||||||
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.0_test.dart',
|
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.0_test.dart',
|
||||||
'examples/api/test/widgets/tween_animation_builder/tween_animation_builder.0_test.dart',
|
'examples/api/test/widgets/tween_animation_builder/tween_animation_builder.0_test.dart',
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
// 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_api_samples/widgets/editable_text/editable_text.on_changed.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Verify correct labels are displayed', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.OnChangedExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.text('What number comes next in the sequence?'),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(find.text('1, 1, 2, 3, 5, 8...?'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Does not show dialog when answer is not correct', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.OnChangedExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), '33');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Shows dialog when answer is correct', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.OnChangedExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), '13');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(find.text('That is correct!'), findsOneWidget);
|
||||||
|
expect(find.text('13 is the right answer.'), findsOneWidget);
|
||||||
|
expect(find.text('OK'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Closes dialog on OK button tap', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.OnChangedExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), '13');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.ancestor(
|
||||||
|
of: find.text('OK'),
|
||||||
|
matching: find.byType(TextButton),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsNothing);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user