text button case rework (#154943)

Rework on the text button use case to pass [b/347102786](https://b.corp.google.com/347102786), 

After talking with the tester, it seems like there isn't an issue with the A11y of the text button, rather just how the test case is set up. In order for the text case to pass, there needs to be real time feedback of an action that is done by pressing the text button (think of a dialog popup, or form submission notification). 

So I rewrote the test case to mimic a simple form with a submit button that once submitted, will let the user know it is submitted with a snack bar notification. https://screencast.googleplex.com/cast/NTM0ODc1NDIxMDE2MDY0MHwzYWI4MTZhMS1hMA
This commit is contained in:
Denis Bowen 2024-09-13 14:11:08 -05:00 committed by GitHub
parent 07647cae9f
commit 47aed96ca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 39 deletions

View File

@ -25,9 +25,8 @@ class MainWidget extends StatefulWidget {
} }
class MainWidgetState extends State<MainWidget> { class MainWidgetState extends State<MainWidget> {
int _count = 0;
String pageTitle = getUseCaseName(TextButtonUseCase()); String pageTitle = getUseCaseName(TextButtonUseCase());
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -36,35 +35,34 @@ class MainWidgetState extends State<MainWidget> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')), title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')),
), ),
body: Center( body: Form(
key: _formKey,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
MergeSemantics( TextFormField(
child: Row( // The validator receives the text that the user has entered.
mainAxisAlignment: MainAxisAlignment.center, validator: (String? value) {
children: <Widget>[ if (value == null || value.isEmpty) {
const Text('This is a TextButton:'), return 'Please enter some text';
TextButton( }
onPressed: () { return null;
setState(() { _count++; }); },
},
child: const Text('Action'),
),
Text('Clicked $_count time(s).'),
],
),
), ),
const MergeSemantics( Padding(
child: Row( padding: const EdgeInsets.symmetric(vertical: 16),
mainAxisAlignment: MainAxisAlignment.center, child: ElevatedButton(
children: <Widget>[ onPressed: () {
Text('This is a disabled TextButton:'), // Validate returns true if the form is valid, or false otherwise.
TextButton( if (_formKey.currentState!.validate()) {
onPressed: null, // If the form is valid, display a snackbar. In the real world,
child: Text('Action Disabled'), // this might also send a request to a server.
), ScaffoldMessenger.of(context).showSnackBar(
], const SnackBar(content: Text('Form submitted')),
);
}
},
child: const Text('Submit'),
), ),
), ),
], ],

View File

@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:a11y_assessments/use_cases/text_button.dart'; import 'package:a11y_assessments/use_cases/text_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart'; import 'test_utils.dart';
@ -10,22 +11,21 @@ import 'test_utils.dart';
void main() { void main() {
testWidgets('text button can run', (WidgetTester tester) async { testWidgets('text button can run', (WidgetTester tester) async {
await pumpsUseCase(tester, TextButtonUseCase()); await pumpsUseCase(tester, TextButtonUseCase());
expect(find.text('Action'), findsOneWidget); expect(find.text('Submit'), findsOneWidget);
expect(find.text('Action Disabled'), findsOneWidget);
}); });
testWidgets('text button increments correctly when clicked', testWidgets('submit causes snackbar to show', (WidgetTester tester) async {
(WidgetTester tester) async {
await pumpsUseCase(tester, TextButtonUseCase()); await pumpsUseCase(tester, TextButtonUseCase());
final Finder textFormField = find.byType(TextFormField);
final Finder submitButton = find.text('Submit');
expect(find.text('Action'), findsOneWidget); // Enter text in field and submit.
await tester.tap(find.text('Action')); await tester.enterText(textFormField, 'test text');
await tester.pumpAndSettle(); await tester.tap(submitButton);
expect(find.text('Clicked 1 time(s).'), findsOneWidget); await tester.pump();
await tester.tap(find.text('Action')); // Verify that the snackbar is visible.
await tester.pumpAndSettle(); expect(find.text('Form submitted'), findsOneWidget);
expect(find.text('Clicked 2 time(s).'), findsOneWidget);
}); });
testWidgets('text button demo page has one h1 tag', (WidgetTester tester) async { testWidgets('text button demo page has one h1 tag', (WidgetTester tester) async {