One Flutter client for network-computer: drive a remote Linux/Mac desktop from Android, iPhone, iPad, or desktop over WebRTC.

0 downloads

network-computer-flutter/test/soft_keyboard_test.dart
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/network-computer-flutter.git
HTTPS
https://gitstable.com/git/askrobots/network-computer-flutter.git
SSH
ssh://git@gitstable.com:2222/askrobots/network-computer-flutter.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Quellhorst No colour (compare) in ⋯: the desk's picture in grey on this device c74471a 1 month, 3 weeks ago History
soft_keyboard_test.dart · 3.8 KB · 146 lines
1import 'package:flutter/material.dart';
2import 'package:flutter/services.dart';
3import 'package:flutter_test/flutter_test.dart';
4import 'package:network_computer/protocol.dart';
5import 'package:network_computer/soft_keyboard.dart';
6
7const z = '\u200B\u200B\u200B\u200B'; // what the hidden field holds between keys
8
9Future<List<String>> run(WidgetTester t, Future<void> Function() act) async {
10 final got = <String>[];
11 await t.pumpWidget(
12 MaterialApp(
13 home: Scaffold(
14 body: Align(
15 alignment: Alignment.bottomCenter,
16 child: SoftKeyboard(
17 onEvent: (InputEvent e) => got.add('${e.t} ${e.code}'),
18 ),
19 ),
20 ),
21 ),
22 );
23 await t.pump();
24 await act();
25 await t.pump();
26 return got;
27}
28
29final field = find.byKey(const Key('soft-keyboard-field'));
30
31void main() {
32 test('US keys for characters', () {
33 expect(usKey('a'), ('KeyA', false));
34 expect(usKey('A'), ('KeyA', true));
35 expect(usKey('7'), ('Digit7', false));
36 expect(usKey('&'), ('Digit7', true));
37 expect(usKey('?'), ('Slash', true));
38 expect(usKey('’'), ('Quote', false));
39 expect(usKey('\n'), ('Enter', false));
40 expect(usKey('é'), null);
41 });
42
43 testWidgets('the device keyboard comes up by itself', (t) async {
44 await run(t, () async {});
45 expect(t.testTextInput.isVisible, true);
46 });
47
48 testWidgets('typing: letters, capitals with shift, space', (t) async {
49 final e = await run(t, () => t.enterText(field, '${z}Hi a'));
50 expect(e, [
51 'kd ShiftLeft',
52 'kd KeyH',
53 'ku KeyH',
54 'ku ShiftLeft',
55 'kd KeyI',
56 'ku KeyI',
57 'kd Space',
58 'ku Space',
59 'kd KeyA',
60 'ku KeyA',
61 ]);
62 });
63
64 testWidgets('each key on its own, as a keyboard types them', (t) async {
65 final e = await run(t, () async {
66 await t.enterText(field, '${z}o');
67 await t.enterText(field, '${z}k');
68 });
69 expect(e, ['kd KeyO', 'ku KeyO', 'kd KeyK', 'ku KeyK']);
70 });
71
72 testWidgets('backspace, and return is Enter', (t) async {
73 final e = await run(t, () async {
74 await t.enterText(field, z.substring(1));
75 await t.enterText(field, '$z\n');
76 });
77 expect(e, ['kd Backspace', 'ku Backspace', 'kd Enter', 'ku Enter']);
78 });
79
80 testWidgets('ctrl on the bar applies to the next key, then lets go', (
81 t,
82 ) async {
83 final e = await run(t, () async {
84 await t.tap(find.text('ctrl'));
85 await t.pump();
86 await t.enterText(field, '${z}c');
87 await t.enterText(field, '${z}v');
88 });
89 expect(e, [
90 'kd ControlLeft',
91 'kd KeyC',
92 'ku KeyC',
93 'ku ControlLeft',
94 'kd KeyV',
95 'ku KeyV',
96 ]);
97 });
98
99 testWidgets('holding ctrl keeps it on until tapped again', (t) async {
100 final e = await run(t, () async {
101 await t.longPress(find.text('ctrl'));
102 await t.pump();
103 await t.enterText(field, '${z}a');
104 await t.enterText(field, '${z}c');
105 await t.tap(find.text('ctrl'));
106 });
107 expect(e, [
108 'kd ControlLeft',
109 'kd KeyA',
110 'ku KeyA',
111 'kd KeyC',
112 'ku KeyC',
113 'ku ControlLeft',
114 ]);
115 });
116
117 testWidgets('keys on the bar: esc, arrows, and F keys behind fn', (t) async {
118 final e = await run(t, () async {
119 await t.tap(find.text('esc'));
120 await t.tap(find.text('↑'));
121 expect(find.text('F5'), findsNothing);
122 await t.tap(find.text('fn'));
123 await t.pump();
124 await t.tap(find.text('F5'));
125 });
126 expect(e, [
127 'kd Escape',
128 'ku Escape',
129 'kd ArrowUp',
130 'ku ArrowUp',
131 'kd F5',
132 'ku F5',
133 ]);
134 });
135
136 testWidgets('ctrl on the bar also lets go after a key on a real keyboard', (
137 t,
138 ) async {
139 final e = await run(t, () async {
140 await t.tap(find.text('ctrl'));
141 await t.pump();
142 await t.sendKeyEvent(LogicalKeyboardKey.keyA);
143 });
144 expect(e, ['kd ControlLeft', 'ku ControlLeft']);
145 });
146}