zefyr

editable_text_test.dart 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2018, the Zefyr project authors. Please see the AUTHORS file
  2. // for details. All rights reserved. Use of this source code is governed by a
  3. // BSD-style license that can be found in the LICENSE file.
  4. import 'package:flutter/widgets.dart';
  5. import 'package:flutter_test/flutter_test.dart';
  6. import 'package:zefyr/zefyr.dart';
  7. import '../testing.dart';
  8. void main() {
  9. group('$ZefyrEditableText', () {
  10. testWidgets('user input', (tester) async {
  11. final editor = EditorSandBox(tester: tester);
  12. await editor.pumpAndTap();
  13. final currentValue = editor.document.toPlainText();
  14. await enterText(tester, 'Added $currentValue');
  15. expect(editor.document.toPlainText(), 'Added This House Is A Circus\n');
  16. });
  17. testWidgets('autofocus', (tester) async {
  18. final editor = EditorSandBox(tester: tester, autofocus: true);
  19. await editor.pump();
  20. expect(editor.focusNode.hasFocus, isTrue);
  21. });
  22. testWidgets('no autofocus', (tester) async {
  23. final editor = EditorSandBox(tester: tester);
  24. await editor.pump();
  25. expect(editor.focusNode.hasFocus, isFalse);
  26. });
  27. });
  28. }
  29. Future<Null> enterText(WidgetTester tester, String text) async {
  30. return TestAsyncUtils.guard(() async {
  31. tester.testTextInput.updateEditingValue(
  32. TextEditingValue(
  33. text: text,
  34. selection: TextSelection.collapsed(offset: 6),
  35. ),
  36. );
  37. await tester.idle();
  38. });
  39. }