From 8098b5e63ea8bd669ca0aef12b469cadadfcac31 Mon Sep 17 00:00:00 2001 From: xster Date: Tue, 22 Jan 2019 10:51:39 -0800 Subject: [PATCH] Fill editable_text.dart test coverage (#26793) --- .../test/widgets/editable_text_test.dart | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 8331df37ee..4b59feb4ab 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -1980,7 +1980,7 @@ testWidgets( expect(called, 2); }); - testWidgets('default keyboardAppearance is resepcted', (WidgetTester tester) async { + testWidgets('default keyboardAppearance is respected', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/22212. final List log = []; @@ -2008,7 +2008,7 @@ testWidgets( expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.light'); }); - testWidgets('custom keyboardAppearance is resepcted', (WidgetTester tester) async { + testWidgets('custom keyboardAppearance is respected', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/22212. final List log = []; @@ -2036,6 +2036,54 @@ testWidgets( expect(setClient.method, 'TextInput.setClient'); expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.dark'); }); + + testWidgets( + 'Composing text is underlined and underline is cleared when losing focus', + (WidgetTester tester) async { + final TextEditingController controller = TextEditingController.fromValue( + const TextEditingValue( + text: 'text composing text', + selection: TextSelection.collapsed(offset: 14), + composing: TextRange(start: 5, end: 14), + ), + ); + final GlobalKey editableTextKey = + GlobalKey(); + final FocusNode focusNode = FocusNode(); + + await tester.pumpWidget(MaterialApp( // So we can show overlays. + home: EditableText( + autofocus: true, + backgroundCursorColor: Colors.grey, + key: editableTextKey, + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: cursorColor, + selectionControls: materialTextSelectionControls, + keyboardType: TextInputType.text, + onEditingComplete: () { + // This prevents the default focus change behavior on submission. + }, + ), + )); + + assert(focusNode.hasFocus); + + final RenderEditable renderEditable = findRenderEditable(tester); + // The actual text span is split into 3 parts with the middle part underlined. + expect(renderEditable.text.children.length, 3); + expect(renderEditable.text.children[1].text, 'composing'); + expect(renderEditable.text.children[1].style.decoration, TextDecoration.underline); + + focusNode.unfocus(); + await tester.pump(); + + expect(renderEditable.text.children, isNull); + // Everything's just formated the same way now. + expect(renderEditable.text.text, 'text composing text'); + expect(renderEditable.text.style.decoration, isNull); + }); } class MockTextSelectionControls extends Mock implements TextSelectionControls {}