Fixes TextField hinttext in a11y_assessment (#150007)

b/317131589
This commit is contained in:
chunhtai 2024-06-10 12:58:58 -07:00 committed by GitHub
parent c0b2645b8a
commit bc0134d3d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 2 deletions

View file

@ -32,6 +32,7 @@ class _MainWidget extends StatelessWidget {
children: <Widget>[
const TextField(
key: Key('enabled text field'),
maxLines: null,
decoration: InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',
@ -40,6 +41,7 @@ class _MainWidget extends StatelessWidget {
),
TextField(
key: const Key('disabled text field'),
maxLines: null,
decoration: const InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',

View file

@ -34,7 +34,6 @@ class _MainWidget extends StatelessWidget {
key: Key('enabled password'),
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
),
obscureText: true,
),
@ -42,7 +41,6 @@ class _MainWidget extends StatelessWidget {
key: Key('disabled password'),
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
),
enabled: false,
obscureText: true,

View file

@ -30,4 +30,24 @@ void main() {
expect(passwordField.enabled, isFalse);
}
});
testWidgets('text field passwords do not have hint text', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldPasswordUseCase());
expect(find.byType(TextField), findsExactly(2));
// Test the enabled password
{
final Finder finder = find.byKey(const Key('enabled password'));
final TextField textField = tester.widget<TextField>(finder);
expect(textField.decoration?.hintText, isNull);
}
// Test the disabled password
{
final Finder finder = find.byKey(const Key('disabled password'));
final TextField textField = tester.widget<TextField>(finder);
expect(textField.decoration?.hintText, isNull);
}
});
}

View file

@ -30,4 +30,28 @@ void main() {
expect(textField.enabled, isFalse);
}
});
testWidgets('font size increase does not ellipsize hint text', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldUseCase());
await tester.pumpWidget(MaterialApp(
home: MediaQuery.withClampedTextScaling(
minScaleFactor: 3,
maxScaleFactor: 3,
child: Builder(
builder: (BuildContext context) {
return TextFieldUseCase().build(context);
},
),
),
));
// Test the enabled text field
{
final Finder finder = find.byKey(const Key('enabled text field'));
await tester.tap(finder);
await tester.pumpAndSettle();
final Size size = tester.getSize(finder);
// Should have a multi-line height.
expect(size.height, 280);
}
});
}