Open the on-screen keyboard for terminals on phones
On Android and iOS a tap on a terminal (a chat command card or the terminal panel) now opens the soft keyboard and typing goes to the process, with no autocorrect. Desktop keeps raw key events. Desktop keyboard tests now run as macOS, since tests default to Android.
This commit is contained in:
@@ -117,10 +117,13 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
|||||||
textStyle: style,
|
textStyle: style,
|
||||||
padding: padding,
|
padding: padding,
|
||||||
readOnly: !live,
|
readOnly: !live,
|
||||||
// Keys go straight to the process as key events (a focused text
|
// Desktop keys go straight to the process as key events (a focused
|
||||||
// input would stay closed on the web); touch typing goes through the
|
// text input stays closed in desktop browsers). On phones and tablets
|
||||||
// key toolbar's field instead.
|
// a tap opens the on-screen keyboard and typing goes to the terminal;
|
||||||
hardwareKeyboardOnly: true,
|
// the key toolbar's field stays as an alternative.
|
||||||
|
hardwareKeyboardOnly: !chatShellTouchFirst(),
|
||||||
|
// No autocorrect or suggestions rewriting what is sent to a shell.
|
||||||
|
keyboardType: TextInputType.visiblePassword,
|
||||||
shortcuts: chatShellTerminalShortcuts(),
|
shortcuts: chatShellTerminalShortcuts(),
|
||||||
cursorType: TerminalCursorType.block,
|
cursorType: TerminalCursorType.block,
|
||||||
onTapUp: _tapped,
|
onTapUp: _tapped,
|
||||||
|
|||||||
@@ -122,6 +122,29 @@ void main() {
|
|||||||
expect(tester.widget<TextField>(field).controller!.text, isEmpty);
|
expect(tester.widget<TextField>(field).controller!.text, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'tapping the terminal on a phone opens the keyboard and typing reaches '
|
||||||
|
'the process',
|
||||||
|
(tester) async {
|
||||||
|
await openRunning(tester, output: 'Paste your token: ');
|
||||||
|
expect(tester.testTextInput.isVisible, isFalse);
|
||||||
|
await tester.tap(find.byType(TerminalView));
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.testTextInput.isVisible, isTrue);
|
||||||
|
expect(tester.testTextInput.hasAnyClients, isTrue);
|
||||||
|
gateway.calls.clear();
|
||||||
|
tester.testTextInput.enterText('tok');
|
||||||
|
await tester.pump();
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.newline);
|
||||||
|
await tester.pump();
|
||||||
|
expect(typed(), startsWith('tok'));
|
||||||
|
// Close the keyboard connection before the tree goes away.
|
||||||
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
|
await tester.pump(const Duration(seconds: 1));
|
||||||
|
},
|
||||||
|
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('a running terminal is resized to its view; a finished one is '
|
testWidgets('a running terminal is resized to its view; a finished one is '
|
||||||
'read-only', (tester) async {
|
'read-only', (tester) async {
|
||||||
await openRunning(tester, output: 'working\r\n');
|
await openRunning(tester, output: 'working\r\n');
|
||||||
|
|||||||
@@ -41,28 +41,33 @@ void main() {
|
|||||||
for (final mode in TerminalMode.values) {
|
for (final mode in TerminalMode.values) {
|
||||||
for (final MapEntry(key: name, value: (letter, modifier))
|
for (final MapEntry(key: name, value: (letter, modifier))
|
||||||
in toggles.entries) {
|
in toggles.entries) {
|
||||||
testWidgets('$name toggles the ${mode.label.toLowerCase()} from a text '
|
desktopTestWidgets(
|
||||||
'field and from inside the terminal', (tester) async {
|
'$name toggles the ${mode.label.toLowerCase()} from a text '
|
||||||
layout.setMode(mode);
|
'field and from inside the terminal',
|
||||||
final surface = mode == TerminalMode.panel ? panelFinder : floatFinder;
|
(tester) async {
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
layout.setMode(mode);
|
||||||
await tester.tap(find.byKey(appField));
|
final surface = mode == TerminalMode.panel
|
||||||
await tester.pump();
|
? panelFinder
|
||||||
await chord(tester, letter, [modifier]);
|
: floatFinder;
|
||||||
expect(surface, findsOneWidget);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
expect(layout.visible, isTrue);
|
await tester.tap(find.byKey(appField));
|
||||||
// The shortcut never types into the field it was pressed in.
|
await tester.pump();
|
||||||
expect(find.text('t'), findsNothing);
|
await chord(tester, letter, [modifier]);
|
||||||
expect(terminalFocused(key('term_a')), isTrue);
|
expect(surface, findsOneWidget);
|
||||||
// Inside the terminal the same keys hide it instead of reaching the
|
expect(layout.visible, isTrue);
|
||||||
// shell (Ctrl+T would be transpose-chars there).
|
// The shortcut never types into the field it was pressed in.
|
||||||
final typed = mac.bodies('terminal_input').length;
|
expect(find.text('t'), findsNothing);
|
||||||
await chord(tester, letter, [modifier]);
|
expect(terminalFocused(key('term_a')), isTrue);
|
||||||
expect(surface, findsNothing);
|
// Inside the terminal the same keys hide it instead of reaching the
|
||||||
expect(layout.visible, isFalse);
|
// shell (Ctrl+T would be transpose-chars there).
|
||||||
expect(mac.bodies('terminal_input'), hasLength(typed));
|
final typed = mac.bodies('terminal_input').length;
|
||||||
expect(hub.tabs, hasLength(3));
|
await chord(tester, letter, [modifier]);
|
||||||
});
|
expect(surface, findsNothing);
|
||||||
|
expect(layout.visible, isFalse);
|
||||||
|
expect(mac.bodies('terminal_input'), hasLength(typed));
|
||||||
|
expect(hub.tabs, hasLength(3));
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +81,7 @@ void main() {
|
|||||||
expect(terminalToggleShortcut(event, _AltHeld()), isTrue);
|
expect(terminalToggleShortcut(event, _AltHeld()), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('holding the chord toggles once and types nothing', (
|
desktopTestWidgets('holding the chord toggles once and types nothing', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
@@ -93,7 +98,9 @@ void main() {
|
|||||||
expect(mac.bodies('terminal_input'), isEmpty);
|
expect(mac.bodies('terminal_input'), isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Shift or a second modifier leaves T alone', (tester) async {
|
desktopTestWidgets('Shift or a second modifier leaves T alone', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
for (final modifiers in [
|
for (final modifiers in [
|
||||||
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
|
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
|
||||||
@@ -105,28 +112,31 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('showing focuses the terminal; hiding gives the keyboard back '
|
desktopTestWidgets(
|
||||||
'to the field that had it', (tester) async {
|
'showing focuses the terminal; hiding gives the keyboard back '
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
'to the field that had it',
|
||||||
await tester.tap(find.byKey(appField));
|
(tester) async {
|
||||||
await tester.pump();
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
expect(appFieldFocused(tester), isTrue);
|
await tester.tap(find.byKey(appField));
|
||||||
await altT(tester);
|
await tester.pump();
|
||||||
expect(terminalFocused(key('term_a')), isTrue);
|
expect(appFieldFocused(tester), isTrue);
|
||||||
expect(appFieldFocused(tester), isFalse);
|
await altT(tester);
|
||||||
// Typing goes straight to the shell.
|
expect(terminalFocused(key('term_a')), isTrue);
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
expect(appFieldFocused(tester), isFalse);
|
||||||
await tester.pump();
|
// Typing goes straight to the shell.
|
||||||
expect(mac.bodies('terminal_input').last['data'], 'x');
|
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||||
await altT(tester);
|
await tester.pump();
|
||||||
expect(appFieldFocused(tester), isTrue);
|
expect(mac.bodies('terminal_input').last['data'], 'x');
|
||||||
// The bar button focuses it as well.
|
await altT(tester);
|
||||||
await tester.tap(find.byIcon(Icons.terminal));
|
expect(appFieldFocused(tester), isTrue);
|
||||||
await tester.pumpAndSettle();
|
// The bar button focuses it as well.
|
||||||
expect(terminalFocused(key('term_a')), isTrue);
|
await tester.tap(find.byIcon(Icons.terminal));
|
||||||
});
|
await tester.pumpAndSettle();
|
||||||
|
expect(terminalFocused(key('term_a')), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('a terminal left shown before a reload is focused once it '
|
desktopTestWidgets('a terminal left shown before a reload is focused once it '
|
||||||
'lists', (tester) async {
|
'lists', (tester) async {
|
||||||
layout.show();
|
layout.show();
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
@@ -137,7 +147,7 @@ void main() {
|
|||||||
await tester.pump(const Duration(milliseconds: 300));
|
await tester.pump(const Duration(milliseconds: 300));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Ctrl+Tab and Ctrl+Shift+Tab move between terminal tabs, '
|
desktopTestWidgets('Ctrl+Tab and Ctrl+Shift+Tab move between terminal tabs, '
|
||||||
'wrapping, and focus each; hidden, they do nothing here', (tester) async {
|
'wrapping, and focus each; hidden, they do nothing here', (tester) async {
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
await ctrlTab(tester);
|
await ctrlTab(tester);
|
||||||
@@ -165,7 +175,9 @@ void main() {
|
|||||||
expect(hub.selected!.info.id, 'term_a');
|
expect(hub.selected!.info.id, 'term_a');
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('a tab picked by pointer takes the keyboard', (tester) async {
|
desktopTestWidgets('a tab picked by pointer takes the keyboard', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
layout.show();
|
layout.show();
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -174,7 +186,7 @@ void main() {
|
|||||||
expect(terminalFocused(key('term_c')), isTrue);
|
expect(terminalFocused(key('term_c')), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('opening with no terminal starts one', (tester) async {
|
desktopTestWidgets('opening with no terminal starts one', (tester) async {
|
||||||
final empty = TerminalGateway();
|
final empty = TerminalGateway();
|
||||||
final bare = TerminalHub(TestMachines([machine('mac', empty)]));
|
final bare = TerminalHub(TestMachines([machine('mac', empty)]));
|
||||||
addTearDown(bare.dispose);
|
addTearDown(bare.dispose);
|
||||||
@@ -188,31 +200,34 @@ void main() {
|
|||||||
expect(empty.bodies('terminal_open'), hasLength(1));
|
expect(empty.bodies('terminal_open'), hasLength(1));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('on a narrow window the keys open and close the full-screen '
|
desktopTestWidgets(
|
||||||
'page, focused, and Ctrl+Tab moves between its tabs', (tester) async {
|
'on a narrow window the keys open and close the full-screen '
|
||||||
await pumpTerminalApp(
|
'page, focused, and Ctrl+Tab moves between its tabs',
|
||||||
tester,
|
(tester) async {
|
||||||
hub: hub,
|
await pumpTerminalApp(
|
||||||
layout: layout,
|
tester,
|
||||||
size: const Size(390, 800),
|
hub: hub,
|
||||||
);
|
layout: layout,
|
||||||
await tester.tap(find.byKey(appField));
|
size: const Size(390, 800),
|
||||||
await tester.pump();
|
);
|
||||||
await chord(tester, LogicalKeyboardKey.keyT, [
|
await tester.tap(find.byKey(appField));
|
||||||
LogicalKeyboardKey.controlLeft,
|
await tester.pump();
|
||||||
]);
|
await chord(tester, LogicalKeyboardKey.keyT, [
|
||||||
expect(find.widgetWithText(AppBar, 'Terminal'), findsOneWidget);
|
LogicalKeyboardKey.controlLeft,
|
||||||
expect(terminalFocused(key('term_a')), isTrue);
|
]);
|
||||||
await ctrlTab(tester, reverse: true);
|
expect(find.widgetWithText(AppBar, 'Terminal'), findsOneWidget);
|
||||||
expect(hub.selected!.info.id, 'term_c');
|
expect(terminalFocused(key('term_a')), isTrue);
|
||||||
expect(terminalFocused(key('term_c')), isTrue);
|
await ctrlTab(tester, reverse: true);
|
||||||
await chord(tester, LogicalKeyboardKey.keyT, [
|
expect(hub.selected!.info.id, 'term_c');
|
||||||
LogicalKeyboardKey.controlLeft,
|
expect(terminalFocused(key('term_c')), isTrue);
|
||||||
]);
|
await chord(tester, LogicalKeyboardKey.keyT, [
|
||||||
expect(find.widgetWithText(AppBar, 'Terminal'), findsNothing);
|
LogicalKeyboardKey.controlLeft,
|
||||||
expect(find.byType(TerminalView), findsNothing);
|
]);
|
||||||
expect(appFieldFocused(tester), isTrue);
|
expect(find.widgetWithText(AppBar, 'Terminal'), findsNothing);
|
||||||
});
|
expect(find.byType(TerminalView), findsNothing);
|
||||||
|
expect(appFieldFocused(tester), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('the listed shortcuts are the ones the platform delivers', () {
|
test('the listed shortcuts are the ones the platform delivers', () {
|
||||||
const mac = TerminalShortcutLabels(
|
const mac = TerminalShortcutLabels(
|
||||||
@@ -241,7 +256,9 @@ void main() {
|
|||||||
expect(windowsWeb.button, 'Terminal (Alt+T)');
|
expect(windowsWeb.button, 'Terminal (Alt+T)');
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('typing / in the terminal stays in the terminal', (tester) async {
|
desktopTestWidgets('typing / in the terminal stays in the terminal', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
layout.setMode(TerminalMode.panel);
|
layout.setMode(TerminalMode.panel);
|
||||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||||
await tester.tap(find.byKey(appField));
|
await tester.tap(find.byKey(appField));
|
||||||
@@ -277,3 +294,12 @@ class _AltHeld extends HardwareKeyboard {
|
|||||||
@override
|
@override
|
||||||
bool get isShiftPressed => false;
|
bool get isShiftPressed => false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hardware keys reach the terminal on desktop; phones type through the
|
||||||
|
/// on-screen keyboard instead. These tests drive desktop key events.
|
||||||
|
void desktopTestWidgets(String description, WidgetTesterCallback callback) =>
|
||||||
|
testWidgets(
|
||||||
|
description,
|
||||||
|
callback,
|
||||||
|
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||||
|
);
|
||||||
|
|||||||
@@ -69,129 +69,135 @@ void main() {
|
|||||||
Map<String, dynamic> saved() =>
|
Map<String, dynamic> saved() =>
|
||||||
jsonDecode(store.saved!) as Map<String, dynamic>;
|
jsonDecode(store.saved!) as Map<String, dynamic>;
|
||||||
|
|
||||||
testWidgets('Ctrl+` and the bar button toggle the bottom panel; hiding '
|
desktopTestWidgets(
|
||||||
'keeps every shell', (tester) async {
|
'Ctrl+` and the bar button toggle the bottom panel; hiding '
|
||||||
await pumpApp(tester);
|
'keeps every shell',
|
||||||
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
(tester) async {
|
||||||
await ctrlBacktick(tester);
|
await pumpApp(tester);
|
||||||
expect(find.byKey(const ValueKey('terminal-panel')), findsOneWidget);
|
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
||||||
expect(find.text('src'), findsOneWidget);
|
await ctrlBacktick(tester);
|
||||||
expect(find.text('docs'), findsOneWidget);
|
expect(find.byKey(const ValueKey('terminal-panel')), findsOneWidget);
|
||||||
expect(saved()['visible'], isTrue);
|
expect(find.text('src'), findsOneWidget);
|
||||||
// The terminal has the keyboard, yet the shortcut still hides it.
|
expect(find.text('docs'), findsOneWidget);
|
||||||
await tester.tap(find.byType(TerminalView));
|
expect(saved()['visible'], isTrue);
|
||||||
await tester.pump();
|
// The terminal has the keyboard, yet the shortcut still hides it.
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
await tester.tap(find.byType(TerminalView));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(mac.bodies('terminal_input').last['data'], 'x');
|
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||||
await ctrlBacktick(tester);
|
await tester.pump();
|
||||||
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
expect(mac.bodies('terminal_input').last['data'], 'x');
|
||||||
expect(hub.tabs, hasLength(2));
|
await ctrlBacktick(tester);
|
||||||
expect(mac.bodies('terminal_close'), isEmpty);
|
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
||||||
await tester.tap(find.byTooltip(TerminalToggleButton.label));
|
expect(hub.tabs, hasLength(2));
|
||||||
await tester.pumpAndSettle();
|
expect(mac.bodies('terminal_close'), isEmpty);
|
||||||
expect(find.byKey(const ValueKey('terminal-panel')), findsOneWidget);
|
await tester.tap(find.byTooltip(TerminalToggleButton.label));
|
||||||
// Reopening draws the same emulator, output and all.
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(TerminalView), findsOneWidget);
|
expect(find.byKey(const ValueKey('terminal-panel')), findsOneWidget);
|
||||||
});
|
// Reopening draws the same emulator, output and all.
|
||||||
|
expect(find.byType(TerminalView), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('the panel resizes from its top edge and remembers its height', (
|
desktopTestWidgets(
|
||||||
tester,
|
'the panel resizes from its top edge and remembers its height',
|
||||||
) async {
|
(tester) async {
|
||||||
await pumpApp(tester);
|
await pumpApp(tester);
|
||||||
await ctrlBacktick(tester);
|
await ctrlBacktick(tester);
|
||||||
final before = tester
|
final before = tester
|
||||||
.getSize(find.byKey(const ValueKey('terminal-panel')))
|
.getSize(find.byKey(const ValueKey('terminal-panel')))
|
||||||
.height;
|
.height;
|
||||||
expect(before, terminalPanelDefaultHeight);
|
expect(before, terminalPanelDefaultHeight);
|
||||||
await tester.drag(
|
await tester.drag(
|
||||||
find.byKey(const ValueKey('terminal-panel-resize')),
|
find.byKey(const ValueKey('terminal-panel-resize')),
|
||||||
const Offset(0, -120),
|
const Offset(0, -120),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
final after = tester
|
final after = tester
|
||||||
.getSize(find.byKey(const ValueKey('terminal-panel')))
|
.getSize(find.byKey(const ValueKey('terminal-panel')))
|
||||||
.height;
|
.height;
|
||||||
expect(after, closeTo(before + 120, 1));
|
expect(after, closeTo(before + 120, 1));
|
||||||
expect(saved()['panel_height'], closeTo(after, 1));
|
expect(saved()['panel_height'], closeTo(after, 1));
|
||||||
// The app above shrinks rather than hiding under it.
|
// The app above shrinks rather than hiding under it.
|
||||||
final field = tester.getRect(find.byType(Scaffold).first);
|
final field = tester.getRect(find.byType(Scaffold).first);
|
||||||
expect(field.bottom, closeTo(800 - after, 1));
|
expect(field.bottom, closeTo(800 - after, 1));
|
||||||
final restored = TerminalLayout(store: store);
|
final restored = TerminalLayout(store: store);
|
||||||
await restored.restore();
|
await restored.restore();
|
||||||
expect(restored.panelHeight, closeTo(after, 1));
|
expect(restored.panelHeight, closeTo(after, 1));
|
||||||
expect(restored.visible, isTrue);
|
expect(restored.visible, isTrue);
|
||||||
// The resized terminal tells the server its new size.
|
// The resized terminal tells the server its new size.
|
||||||
await tester.pump(const Duration(milliseconds: 200));
|
await tester.pump(const Duration(milliseconds: 200));
|
||||||
expect(mac.bodies('terminal_resize'), isNotEmpty);
|
expect(mac.bodies('terminal_resize'), isNotEmpty);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('the floating window moves, resizes, minimises and maximises', (
|
desktopTestWidgets(
|
||||||
tester,
|
'the floating window moves, resizes, minimises and maximises',
|
||||||
) async {
|
(tester) async {
|
||||||
layout
|
layout
|
||||||
..setMode(TerminalMode.float)
|
..setMode(TerminalMode.float)
|
||||||
..show();
|
..show();
|
||||||
await pumpApp(tester);
|
await pumpApp(tester);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
final window = find.byKey(const ValueKey('terminal-float'));
|
final window = find.byKey(const ValueKey('terminal-float'));
|
||||||
expect(window, findsOneWidget);
|
expect(window, findsOneWidget);
|
||||||
final start = layout.floatRect;
|
final start = layout.floatRect;
|
||||||
await tester.drag(
|
await tester.drag(
|
||||||
find.byKey(const ValueKey('terminal-float-title')),
|
find.byKey(const ValueKey('terminal-float-title')),
|
||||||
const Offset(60, 40),
|
const Offset(60, 40),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(layout.floatRect.topLeft, start.topLeft + const Offset(60, 40));
|
expect(layout.floatRect.topLeft, start.topLeft + const Offset(60, 40));
|
||||||
await tester.drag(
|
await tester.drag(
|
||||||
find.byKey(const ValueKey('terminal-float-resize')),
|
find.byKey(const ValueKey('terminal-float-resize')),
|
||||||
const Offset(80, 50),
|
const Offset(80, 50),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(layout.floatRect.size, start.size + const Offset(80, 50));
|
expect(layout.floatRect.size, start.size + const Offset(80, 50));
|
||||||
expect(saved()['float'][2], closeTo(start.width + 80, 1));
|
expect(saved()['float'][2], closeTo(start.width + 80, 1));
|
||||||
await tester.tap(find.byTooltip('Minimise'));
|
await tester.tap(find.byTooltip('Minimise'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(TerminalView), findsNothing);
|
expect(find.byType(TerminalView), findsNothing);
|
||||||
expect(hub.tabs, hasLength(2));
|
expect(hub.tabs, hasLength(2));
|
||||||
await tester.tap(find.byTooltip('Restore'));
|
await tester.tap(find.byTooltip('Restore'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(TerminalView), findsOneWidget);
|
expect(find.byType(TerminalView), findsOneWidget);
|
||||||
await tester.tap(find.byTooltip('Maximise'));
|
await tester.tap(find.byTooltip('Maximise'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(
|
expect(
|
||||||
tester.getRect(
|
tester.getRect(
|
||||||
find.descendant(of: window, matching: find.byType(Material)).first,
|
find.descendant(of: window, matching: find.byType(Material)).first,
|
||||||
),
|
),
|
||||||
const Rect.fromLTWH(0, 0, 1200, 800).deflate(terminalFloatMargin),
|
const Rect.fromLTWH(0, 0, 1200, 800).deflate(terminalFloatMargin),
|
||||||
);
|
);
|
||||||
await tester.tap(find.byTooltip('Restore size'));
|
await tester.tap(find.byTooltip('Restore size'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(layout.maximized, isFalse);
|
expect(layout.maximized, isFalse);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('tabs select and close their terminals; New terminal opens one', (
|
desktopTestWidgets(
|
||||||
tester,
|
'tabs select and close their terminals; New terminal opens one',
|
||||||
) async {
|
(tester) async {
|
||||||
layout.show();
|
layout.show();
|
||||||
await pumpApp(tester);
|
await pumpApp(tester);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(hub.selected!.info.id, 'term_a');
|
expect(hub.selected!.info.id, 'term_a');
|
||||||
await tester.tap(find.text('docs'));
|
await tester.tap(find.text('docs'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(hub.selected!.info.id, 'term_b');
|
expect(hub.selected!.info.id, 'term_b');
|
||||||
await tester.tap(find.byTooltip('New terminal'));
|
await tester.tap(find.byTooltip('New terminal'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(mac.bodies('terminal_open'), hasLength(1));
|
expect(mac.bodies('terminal_open'), hasLength(1));
|
||||||
expect(hub.tabs, hasLength(3));
|
expect(hub.tabs, hasLength(3));
|
||||||
expect(hub.selected!.info.id, 'term_1');
|
expect(hub.selected!.info.id, 'term_1');
|
||||||
await tester.tap(find.byTooltip('Close terminal').first);
|
await tester.tap(find.byTooltip('Close terminal').first);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(mac.bodies('terminal_close').single['terminal_id'], 'term_a');
|
expect(mac.bodies('terminal_close').single['terminal_id'], 'term_a');
|
||||||
expect(find.text('src'), findsNothing);
|
expect(find.text('src'), findsNothing);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('the options menu switches between panel and window', (
|
desktopTestWidgets('the options menu switches between panel and window', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
layout.show();
|
layout.show();
|
||||||
@@ -211,7 +217,7 @@ void main() {
|
|||||||
expect(find.byKey(const ValueKey('terminal-float')), findsNothing);
|
expect(find.byKey(const ValueKey('terminal-float')), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Settings chooses the mode', (tester) async {
|
desktopTestWidgets('Settings chooses the mode', (tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
@@ -230,23 +236,35 @@ void main() {
|
|||||||
expect(layout.mode, TerminalMode.panel);
|
expect(layout.mode, TerminalMode.panel);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('a narrow window opens the terminal full screen with the key '
|
desktopTestWidgets(
|
||||||
'toolbar', (tester) async {
|
'a narrow window opens the terminal full screen with the key '
|
||||||
layout.show();
|
'toolbar',
|
||||||
await pumpApp(tester, size: const Size(390, 800));
|
(tester) async {
|
||||||
// The panel is not drawn on a phone even when left shown.
|
layout.show();
|
||||||
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
await pumpApp(tester, size: const Size(390, 800));
|
||||||
await tester.tap(find.byTooltip(TerminalToggleButton.label));
|
// The panel is not drawn on a phone even when left shown.
|
||||||
await tester.pumpAndSettle();
|
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
||||||
expect(find.widgetWithText(AppBar, 'Terminal'), findsOneWidget);
|
await tester.tap(find.byTooltip(TerminalToggleButton.label));
|
||||||
expect(find.byType(TerminalView), findsOneWidget);
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(ChatShellTerminalKeys), findsOneWidget);
|
expect(find.widgetWithText(AppBar, 'Terminal'), findsOneWidget);
|
||||||
await tester.tap(find.byKey(const Key('chat-shell-key-ctrl-c')));
|
expect(find.byType(TerminalView), findsOneWidget);
|
||||||
await tester.pump();
|
expect(find.byType(ChatShellTerminalKeys), findsOneWidget);
|
||||||
expect(mac.bodies('terminal_input').last['data'], '\x03');
|
await tester.tap(find.byKey(const Key('chat-shell-key-ctrl-c')));
|
||||||
await tester.pageBack();
|
await tester.pump();
|
||||||
await tester.pumpAndSettle();
|
expect(mac.bodies('terminal_input').last['data'], '\x03');
|
||||||
expect(find.byType(TerminalView), findsNothing);
|
await tester.pageBack();
|
||||||
expect(hub.tabs, hasLength(2));
|
await tester.pumpAndSettle();
|
||||||
});
|
expect(find.byType(TerminalView), findsNothing);
|
||||||
|
expect(hub.tabs, hasLength(2));
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hardware keys reach the terminal on desktop; phones type through the
|
||||||
|
/// on-screen keyboard instead. These tests drive desktop key events.
|
||||||
|
void desktopTestWidgets(String description, WidgetTesterCallback callback) =>
|
||||||
|
testWidgets(
|
||||||
|
description,
|
||||||
|
callback,
|
||||||
|
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user