fix(chat): Return breaks lines on phones and align the activity line

On Android and iOS the keyboard's Return now inserts a newline and the
Send button sends; desktop keeps Enter to send. The Material activity
line drops TextButton's inset so it starts at the answer's edge now that
replies have no bubble.
This commit is contained in:
2026-10-30 20:07:27 +00:00
parent 027c2f800e
commit 44b2cff347
9 changed files with 349 additions and 174 deletions
@@ -4,6 +4,10 @@ import 'package:flutter_test/flutter_test.dart';
import 'chat_composer_bar_fixtures.dart';
/// These tests drive a desktop keyboard, where Enter sends; on a phone the
/// on-screen keyboard's Return breaks the line instead.
final _desktop = TargetPlatformVariant.only(TargetPlatform.linux);
void main() {
late ComposerBarGateway gateway;
late int sequence;
@@ -34,52 +38,60 @@ void main() {
Finder palette() => find.byKey(const Key('chat-command-palette'));
Finder row(String name) => find.byKey(ValueKey<String>('chat-command-$name'));
testWidgets('a leading slash opens the filtered recorded command palette', (
tester,
) async {
await pumpComposer(tester);
testWidgets(
'a leading slash opens the filtered recorded command palette',
(tester) async {
await pumpComposer(tester);
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
await tester.pump();
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
await tester.pump();
expect(palette(), findsOneWidget);
for (final name in ['new', 'close', 'rename', 'stop', 'help']) {
expect(row(name), findsOneWidget);
}
expect(find.text('/new'), findsOneWidget);
expect(
find.text('Start a fresh session in this directory'),
findsOneWidget,
);
expect(palette(), findsOneWidget);
for (final name in ['new', 'close', 'rename', 'stop', 'help']) {
expect(row(name), findsOneWidget);
}
expect(find.text('/new'), findsOneWidget);
expect(
find.text('Start a fresh session in this directory'),
findsOneWidget,
);
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/cl');
await tester.pump();
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/cl',
);
await tester.pump();
expect(row('close'), findsOneWidget);
expect(row('new'), findsNothing);
expect(row('rename'), findsNothing);
expect(row('stop'), findsNothing);
expect(row('help'), findsNothing);
expect(row('close'), findsOneWidget);
expect(row('new'), findsNothing);
expect(row('rename'), findsNothing);
expect(row('stop'), findsNothing);
expect(row('help'), findsNothing);
// Recognition is case-insensitive, and an argument or plain text hides it.
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/CL');
await tester.pump();
expect(row('close'), findsOneWidget);
// Recognition is case-insensitive, and an argument or plain text hides it.
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/CL',
);
await tester.pump();
expect(row('close'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/close now',
);
await tester.pump();
expect(palette(), findsNothing);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/close now',
);
await tester.pump();
expect(palette(), findsNothing);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'plain text',
);
await tester.pump();
expect(palette(), findsNothing);
});
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'plain text',
);
await tester.pump();
expect(palette(), findsNothing);
},
variant: _desktop,
);
testWidgets('Escape closes the palette until the draft is edited again', (
tester,
@@ -112,7 +124,7 @@ void main() {
await tester.enterText(field, '/he');
await tester.pump();
expect(palette(), findsOneWidget);
});
}, variant: _desktop);
testWidgets('an unknown command reports locally and never prompts', (
tester,
@@ -160,27 +172,32 @@ void main() {
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets('Send as message is the only route an unknown command takes', (
tester,
) async {
await pumpComposer(tester);
final field = find.byKey(const Key('chat-composer-field'));
testWidgets(
'Send as message is the only route an unknown command takes',
(tester) async {
await pumpComposer(tester);
final field = find.byKey(const Key('chat-composer-field'));
await tester.enterText(field, '/nope');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(gateway.promptBodies, isEmpty);
await tester.enterText(field, '/nope');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(gateway.promptBodies, isEmpty);
await tester.tap(find.byKey(const Key('chat-command-send-as-message')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-command-send-as-message')));
await tester.pumpAndSettle();
expect(gateway.promptBodies.single['text'], '/nope');
expect(fieldText(tester), '');
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
});
expect(gateway.promptBodies.single['text'], '/nope');
expect(fieldText(tester), '');
expect(
find.byKey(const Key('chat-composer-command-notice')),
findsNothing,
);
},
variant: _desktop,
);
testWidgets('a completed command never becomes a prompt', (tester) async {
await pumpComposer(tester);
@@ -215,65 +232,72 @@ void main() {
expect(gateway.promptBodies, isEmpty);
expect(fieldText(tester), '');
expect(find.text('/close does not take an argument.'), findsOneWidget);
});
}, variant: _desktop);
testWidgets('/help consumes the draft and lists commands in recorded order', (
tester,
) async {
await pumpComposer(tester);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/help',
);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
testWidgets(
'/help consumes the draft and lists commands in recorded order',
(tester) async {
await pumpComposer(tester);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'/help',
);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(gateway.promptBodies, isEmpty);
expect(
find.text(
'/new — Start a fresh session in this directory\n'
'/close — Finish this session for every client, keeping its history\n'
'/rename <title> — Rename this session\n'
'/stop — Stop the turn that is running\n'
'/help — List every command',
),
findsOneWidget,
);
expect(find.text('Command'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-command-dismiss')));
await tester.pump();
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
});
expect(fieldText(tester), '');
expect(gateway.promptBodies, isEmpty);
expect(
find.text(
'/new — Start a fresh session in this directory\n'
'/close — Finish this session for every client, keeping its history\n'
'/rename <title> — Rename this session\n'
'/stop — Stop the turn that is running\n'
'/help — List every command',
),
findsOneWidget,
);
expect(find.text('Command'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-command-dismiss')));
await tester.pump();
expect(
find.byKey(const Key('chat-composer-command-notice')),
findsNothing,
);
},
variant: _desktop,
);
testWidgets('/stop without a running turn and extra arguments fail locally', (
tester,
) async {
await pumpComposer(tester);
final field = find.byKey(const Key('chat-composer-field'));
testWidgets(
'/stop without a running turn and extra arguments fail locally',
(tester) async {
await pumpComposer(tester);
final field = find.byKey(const Key('chat-composer-field'));
await tester.enterText(field, '/stop');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(gateway.interruptBodies, isEmpty);
expect(find.text('Command failed'), findsOneWidget);
expect(find.text('No turn is running in this chat.'), findsOneWidget);
await tester.enterText(field, '/stop');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(gateway.interruptBodies, isEmpty);
expect(find.text('Command failed'), findsOneWidget);
expect(find.text('No turn is running in this chat.'), findsOneWidget);
await tester.enterText(field, '/help x');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(find.text('/help does not take an argument.'), findsOneWidget);
expect(gateway.promptBodies, isEmpty);
});
await tester.enterText(field, '/help x');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(find.text('/help does not take an argument.'), findsOneWidget);
expect(gateway.promptBodies, isEmpty);
},
variant: _desktop,
);
testWidgets('/stop interrupts the current session through the composer', (
tester,
@@ -301,7 +325,7 @@ void main() {
expect(fieldText(tester), '');
expect(gateway.promptBodies, isEmpty);
expect(find.text('Stopping the running turn…'), findsOneWidget);
});
}, variant: _desktop);
testWidgets('a command picked from the palette is never sent either', (
tester,
@@ -324,7 +348,7 @@ void main() {
expect(fieldText(tester), '');
expect(find.text('Command'), findsOneWidget);
expect(find.textContaining('/help — List every command'), findsOneWidget);
});
}, variant: _desktop);
testWidgets('a row completes the command and never prompts', (tester) async {
await pumpComposer(tester);
@@ -338,7 +362,7 @@ void main() {
expect(fieldText(tester), '/close');
expect(palette(), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets('Up/Down move the highlight and Enter completes it', (
tester,
@@ -357,7 +381,7 @@ void main() {
expect(fieldText(tester), '/close');
expect(palette(), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets('ArrowUp wraps the highlight to the last command', (
tester,
@@ -376,7 +400,7 @@ void main() {
expect(fieldText(tester), '/help');
expect(palette(), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets('the highlight resets when the filtered list shrinks', (
tester,
@@ -402,7 +426,7 @@ void main() {
expect(fieldText(tester), '/new');
expect(palette(), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets(
'the Cupertino host reports an unknown command with its controls',
@@ -424,6 +448,7 @@ void main() {
expect(gateway.promptBodies.single['text'], '/nope');
expect(fieldText(tester), '');
},
variant: _desktop,
);
testWidgets('Escape dismisses the local command report', (tester) async {
@@ -444,7 +469,7 @@ void main() {
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
expect(gateway.promptBodies, isEmpty);
});
}, variant: _desktop);
testWidgets('the Cupertino host shows the same palette', (tester) async {
await pumpComposer(tester, cupertino: true);
@@ -461,7 +486,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
expect(palette(), findsNothing);
});
}, variant: _desktop);
testWidgets('the palette fits a 320px phone at 2x text', (tester) async {
tester.view.physicalSize = const Size(640, 1200);
@@ -479,5 +504,5 @@ void main() {
expect(palette(), findsOneWidget);
expect(row('new'), findsOneWidget);
expect(row('help'), findsOneWidget);
});
}, variant: _desktop);
}