xuty 3 年 前
コミット
b89b7f53a0
1 ファイル変更44 行追加0 行削除
  1. 44 0
      test/src/terminal_view_test.dart

+ 44 - 0
test/src/terminal_view_test.dart

@@ -7,6 +7,8 @@ import 'package:xterm/xterm.dart';
 import '../_fixture/_fixture.dart';
 
 void main() {
+  final binding = TestWidgetsFlutterBinding.ensureInitialized();
+
   testWidgets(
     'Golden test',
     (WidgetTester tester) async {
@@ -27,4 +29,46 @@ void main() {
     },
     skip: !Platform.isMacOS,
   );
+
+  group('TerminalView.readOnly', () {
+    testWidgets('works', (WidgetTester tester) async {
+      final terminalOutput = <String>[];
+      final terminal = Terminal(onOutput: terminalOutput.add);
+
+      await tester.pumpWidget(MaterialApp(
+        home: Scaffold(
+          body: TerminalView(terminal, readOnly: true, autofocus: true),
+        ),
+      ));
+
+      // https://github.com/flutter/flutter/issues/11181#issuecomment-314936646
+      await tester.tap(find.byType(TerminalView));
+      await tester.pump(Duration(seconds: 1));
+
+      binding.testTextInput.enterText('ls -al');
+      await binding.idle();
+
+      expect(terminalOutput.join(), isEmpty);
+    });
+
+    testWidgets('does not block input when false', (WidgetTester tester) async {
+      final terminalOutput = <String>[];
+      final terminal = Terminal(onOutput: terminalOutput.add);
+
+      await tester.pumpWidget(MaterialApp(
+        home: Scaffold(
+          body: TerminalView(terminal, readOnly: false, autofocus: true),
+        ),
+      ));
+
+      // https://github.com/flutter/flutter/issues/11181#issuecomment-314936646
+      await tester.tap(find.byType(TerminalView));
+      await tester.pump(Duration(seconds: 1));
+
+      binding.testTextInput.enterText('ls -al');
+      await binding.idle();
+
+      expect(terminalOutput.join(), 'ls -al');
+    });
+  });
 }