Unverified Commit b93f71f9 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

NNDB TextField tests (#67696)

Just another nnbd conversion PR.
parent 23c7ee9d
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -173,7 +171,7 @@ void main() {
});
testWidgets('onChanged callbacks are called', (WidgetTester tester) async {
String _value;
late String _value;
await tester.pumpWidget(
MaterialApp(
......@@ -203,7 +201,7 @@ void main() {
child: Center(
child: TextFormField(
autovalidateMode: AutovalidateMode.always,
validator: (String value) {
validator: (String? value) {
_validateCalled++;
return null;
},
......@@ -229,7 +227,7 @@ void main() {
child: TextFormField(
enabled: true,
autovalidateMode: AutovalidateMode.always,
validator: (String value) {
validator: (String? value) {
_validateCalled += 1;
return null;
},
......@@ -272,25 +270,25 @@ void main() {
await tester.pumpWidget(buildFrame(true, false));
Text helperWidget = tester.widget(find.text(helperText));
Text counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style.color, isNot(equals(Colors.transparent)));
expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style!.color, isNot(equals(Colors.transparent)));
await tester.pumpWidget(buildFrame(true, true));
counterWidget = tester.widget(find.text(counterText));
Text errorWidget = tester.widget(find.text(errorText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style.color, isNot(equals(Colors.transparent)));
expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style!.color, isNot(equals(Colors.transparent)));
// When enabled is false, the helper/error and counter are not visible.
await tester.pumpWidget(buildFrame(false, false));
helperWidget = tester.widget(find.text(helperText));
counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, equals(Colors.transparent));
expect(counterWidget.style.color, equals(Colors.transparent));
expect(helperWidget.style!.color, equals(Colors.transparent));
expect(counterWidget.style!.color, equals(Colors.transparent));
await tester.pumpWidget(buildFrame(false, true));
errorWidget = tester.widget(find.text(errorText));
counterWidget = tester.widget(find.text(counterText));
expect(counterWidget.style.color, equals(Colors.transparent));
expect(errorWidget.style.color, equals(Colors.transparent));
expect(counterWidget.style!.color, equals(Colors.transparent));
expect(errorWidget.style!.color, equals(Colors.transparent));
});
testWidgets('passing a buildCounter shows returned widget', (WidgetTester tester) async {
......@@ -298,7 +296,7 @@ void main() {
home: Material(
child: Center(
child: TextFormField(
buildCounter: (BuildContext context, { int currentLength, int maxLength, bool isFocused }) {
buildCounter: (BuildContext context, { int? currentLength, int? maxLength, bool? isFocused }) {
return Text('${currentLength.toString()} of ${maxLength.toString()}');
},
maxLength: 10,
......@@ -434,7 +432,7 @@ void main() {
testWidgets('onChanged callbacks value and FormFieldState.value are sync', (WidgetTester tester) async {
bool _called = false;
FormFieldState<String> state;
late FormFieldState<String> state;
await tester.pumpWidget(
MaterialApp(
......@@ -484,7 +482,7 @@ void main() {
child: Scaffold(
body: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) {
validator: (String? value) {
_validateCalled++;
return null;
},
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -21,7 +19,7 @@ class MockClipboard {
case 'Clipboard.getData':
return _clipboardData;
case 'Clipboard.setData':
_clipboardData = methodCall.arguments;
_clipboardData = methodCall.arguments as Object;
break;
}
}
......@@ -38,9 +36,9 @@ void main() {
group('canSelectAll', () {
Widget createEditableText({
Key key,
String text,
TextSelection selection,
required Key key,
String? text,
TextSelection? selection,
}) {
final TextEditingController controller = TextEditingController(text: text)
..selection = selection ?? const TextSelection.collapsed(offset: -1);
......@@ -59,7 +57,7 @@ void main() {
testWidgets('should return false when there is no text', (WidgetTester tester) async {
final GlobalKey<EditableTextState> key = GlobalKey();
await tester.pumpWidget(createEditableText(key: key));
expect(materialTextSelectionControls.canSelectAll(key.currentState), false);
expect(materialTextSelectionControls.canSelectAll(key.currentState!), false);
});
testWidgets('should return true when there is text and collapsed selection', (WidgetTester tester) async {
......@@ -68,7 +66,7 @@ void main() {
key: key,
text: '123',
));
expect(materialTextSelectionControls.canSelectAll(key.currentState), true);
expect(materialTextSelectionControls.canSelectAll(key.currentState!), true);
});
testWidgets('should return true when there is text and partial uncollapsed selection', (WidgetTester tester) async {
......@@ -78,7 +76,7 @@ void main() {
text: '123',
selection: const TextSelection(baseOffset: 1, extentOffset: 2),
));
expect(materialTextSelectionControls.canSelectAll(key.currentState), true);
expect(materialTextSelectionControls.canSelectAll(key.currentState!), true);
});
testWidgets('should return false when there is text and full selection', (WidgetTester tester) async {
......@@ -88,7 +86,7 @@ void main() {
text: '123',
selection: const TextSelection(baseOffset: 0, extentOffset: 3),
));
expect(materialTextSelectionControls.canSelectAll(key.currentState), false);
expect(materialTextSelectionControls.canSelectAll(key.currentState!), false);
});
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -74,7 +72,7 @@ void main() {
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, defaultCursorColor);
expect(Color(renderEditable.selectionColor.value), defaultSelectionColor);
expect(Color(renderEditable.selectionColor!.value), defaultSelectionColor);
// Test the selection handle color.
await tester.pumpWidget(
......@@ -117,7 +115,7 @@ void main() {
await tester.pumpAndSettle();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, textSelectionTheme.cursorColor.withAlpha(0));
expect(renderEditable.cursorColor, textSelectionTheme.cursorColor!.withAlpha(0));
expect(renderEditable.selectionColor, textSelectionTheme.selectionColor);
// Test the selection handle color.
......@@ -170,7 +168,7 @@ void main() {
await tester.pumpAndSettle();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, widgetTextSelectionTheme.cursorColor.withAlpha(0));
expect(renderEditable.cursorColor, widgetTextSelectionTheme.cursorColor!.withAlpha(0));
expect(renderEditable.selectionColor, widgetTextSelectionTheme.selectionColor);
// Test the selection handle color.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment