|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:html'; |
| 6 | +import 'package:flutter/services.dart'; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | +import 'package:regular_integration_tests/text_editing_main.dart' as app; |
| 9 | +import 'package:flutter/material.dart'; |
| 10 | + |
| 11 | +import 'package:e2e/e2e.dart'; |
| 12 | + |
| 13 | +void main() { |
| 14 | + E2EWidgetsFlutterBinding.ensureInitialized() as E2EWidgetsFlutterBinding; |
| 15 | + |
| 16 | + testWidgets('Focused text field creates a native input element', |
| 17 | + (WidgetTester tester) async { |
| 18 | + app.main(); |
| 19 | + await tester.pumpAndSettle(); |
| 20 | + |
| 21 | + // TODO(nurhan): https://github.com/flutter/flutter/issues/51885 |
| 22 | + SystemChannels.textInput.setMockMethodCallHandler(null); |
| 23 | + |
| 24 | + // Focus on a TextFormField. |
| 25 | + final Finder finder = find.byKey(const Key('input')); |
| 26 | + expect(finder, findsOneWidget); |
| 27 | + await tester.tap(find.byKey(const Key('input'))); |
| 28 | + |
| 29 | + // A native input element will be appended to the DOM. |
| 30 | + final List<Node> nodeList = document.getElementsByTagName('input'); |
| 31 | + expect(nodeList.length, equals(1)); |
| 32 | + final InputElement input = |
| 33 | + document.getElementsByTagName('input')[0] as InputElement; |
| 34 | + // The element's value will be the same as the textFormField's value. |
| 35 | + expect(input.value, 'Text1'); |
| 36 | + |
| 37 | + // Change the value of the TextFormField. |
| 38 | + final TextFormField textFormField = tester.widget(finder); |
| 39 | + textFormField.controller.text = 'New Value'; |
| 40 | + // DOM element's value also changes. |
| 41 | + expect(input.value, 'New Value'); |
| 42 | + }); |
| 43 | +} |
0 commit comments