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:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'chat_stop_icon.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -30,6 +31,16 @@ String chatComposerPlaceholderFor(String directory) {
|
||||
return name.isEmpty ? chatComposerPlaceholder : 'Work on $name';
|
||||
}
|
||||
|
||||
/// Whether Enter sends on [platform] (the running host by default).
|
||||
///
|
||||
/// On a phone the on-screen keyboard's Return breaks the line and the Send
|
||||
/// button sends, as in other chat apps; a desktop keyboard's Enter sends and
|
||||
/// Shift+Enter breaks the line. Ctrl/Cmd+Enter sends everywhere.
|
||||
bool chatEnterSends([TargetPlatform? platform]) {
|
||||
final target = platform ?? defaultTargetPlatform;
|
||||
return target != TargetPlatform.android && target != TargetPlatform.iOS;
|
||||
}
|
||||
|
||||
/// The single primary control's words while a turn is and is not running.
|
||||
const String chatSendLabel = 'Send';
|
||||
const String chatStopLabel = 'Stop';
|
||||
@@ -82,8 +93,12 @@ class ChatComposerBar extends StatefulWidget {
|
||||
this.paste,
|
||||
this.backgroundTasks,
|
||||
this.placeholder = chatComposerPlaceholder,
|
||||
this.enterSends,
|
||||
});
|
||||
|
||||
/// Overrides [chatEnterSends] for this composer; null follows the host.
|
||||
final bool? enterSends;
|
||||
|
||||
final ChatComposerController composer;
|
||||
|
||||
/// The empty field's hint; see [chatComposerPlaceholderFor].
|
||||
@@ -270,6 +285,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
if (_text.value.composing.isValid && !_text.value.composing.isCollapsed) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
// A phone keyboard's Return is the field's own newline; only the
|
||||
// modifier shortcut sends from the keyboard there.
|
||||
if (!sendShortcut && !_enterSends) return KeyEventResult.ignored;
|
||||
if (!sendShortcut && keyboard.isShiftPressed) {
|
||||
if (event is KeyDownEvent) {
|
||||
final selection = _text.selection;
|
||||
@@ -292,6 +310,8 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
bool get _enterSends => widget.enterSends ?? chatEnterSends();
|
||||
|
||||
/// Hardware Enter, the keyboard's Send action and modifier shortcuts share
|
||||
/// the same command/prompt path. An active IME candidate is never submitted.
|
||||
void _submitDraft() {
|
||||
@@ -939,7 +959,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
// strips Shift+Enter's newline on the next text edit.
|
||||
maxLines: empty && lines > 1 ? lines : 6,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.send,
|
||||
textInputAction: _enterSends
|
||||
? TextInputAction.send
|
||||
: TextInputAction.newline,
|
||||
onEditingComplete: () {},
|
||||
onSubmitted: (_) => _submitDraft(),
|
||||
onChanged: _onDraftEdited,
|
||||
@@ -954,7 +976,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
minLines: 1,
|
||||
maxLines: 6,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.send,
|
||||
textInputAction: _enterSends
|
||||
? TextInputAction.send
|
||||
: TextInputAction.newline,
|
||||
onEditingComplete: () {},
|
||||
onSubmitted: (_) => _submitDraft(),
|
||||
onChanged: _onDraftEdited,
|
||||
|
||||
@@ -186,6 +186,12 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
)
|
||||
: TextButton(
|
||||
key: const Key('chat-turn-activity'),
|
||||
// No inset of its own: the line starts at the answer's edge,
|
||||
// which no longer sits inside a padded bubble.
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
),
|
||||
|
||||
@@ -30,3 +30,12 @@ Branch `chat/chatgpt-look`.
|
||||
expand for details" activity label) fail on checks that predate this change.
|
||||
The message probe's semantics dump does show the new `Copy` control.
|
||||
- Not verified on a device.
|
||||
|
||||
## Follow-up: phone newline and activity alignment
|
||||
|
||||
- On Android and iOS (`chatEnterSends`), the keyboard's Return inserts a line
|
||||
break (`TextInputAction.newline`) and Send sends; Ctrl/Cmd+Enter still sends.
|
||||
Desktop keeps Enter to send and Shift+Enter for a newline. Desktop keyboard
|
||||
tests run under `TargetPlatformVariant.only(TargetPlatform.linux)`.
|
||||
- The Material activity line ("Ran 1 command ›") had TextButton's 12px inset,
|
||||
which used to match the bubble padding; it now starts at the answer's edge.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import 'package:pipelines_app/features/chat/conversation/chat_transcript_cache.d
|
||||
|
||||
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);
|
||||
|
||||
/// Answers the session commands' create, close and rename requests.
|
||||
class _SessionGateway extends ComposerBarGateway {
|
||||
String? refuse;
|
||||
@@ -104,7 +108,7 @@ void main() {
|
||||
expect(created?['id'], 'n1');
|
||||
expect(createdNotice, 'Started a new session “New chat” in /w.');
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('/new without a directory sends nothing and reports it', (
|
||||
tester,
|
||||
@@ -120,7 +124,7 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('/rename sends the trimmed title and reports it', (tester) async {
|
||||
await pump(tester);
|
||||
@@ -130,7 +134,7 @@ void main() {
|
||||
expect(body, {'session_id': 's', 'title': 'Fresh title'});
|
||||
expect(renamed, 'Fresh title');
|
||||
expect(find.text('Renamed this session to “Fresh title”.'), findsOneWidget);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('/rename without a title reports usage and sends nothing', (
|
||||
tester,
|
||||
@@ -143,7 +147,7 @@ void main() {
|
||||
find.text('Usage: /rename <title> — renames this session.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('/close confirms, closes and a refusal keeps the reason', (
|
||||
tester,
|
||||
@@ -164,7 +168,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(closed, 1);
|
||||
expect(find.text('chat is locked'), findsOneWidget);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('/close forgets the cached transcript, also after leaving', (
|
||||
tester,
|
||||
@@ -182,5 +186,5 @@ void main() {
|
||||
// Leaving the closed conversation does not write it back.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(transcripts.sessionIds, ['other']);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
import 'chat_thread_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;
|
||||
@@ -89,6 +93,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('hello'), findsOneWidget);
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
|
||||
testWidgets('Shift+Enter inserts a newline; Enter sends', (tester) async {
|
||||
@@ -113,7 +118,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.promptBodies.single['text'], 'line one');
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('Cmd+Enter sends on the Cupertino host', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
@@ -130,7 +135,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.promptBodies.single['text'], 'mac line');
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('Send is disabled for a blank draft and while sending', (
|
||||
tester,
|
||||
@@ -174,53 +179,55 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(primary().onPressed, isNotNull);
|
||||
expect(gateway.promptBodies, hasLength(1));
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('a refusal restores the draft visibly and reuses its intent', (
|
||||
tester,
|
||||
) async {
|
||||
var attempts = 0;
|
||||
gateway.prompt = (_, _) async {
|
||||
if (++attempts == 1) throw StateError('response lost');
|
||||
return const {};
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets(
|
||||
'a refusal restores the draft visibly and reuses its intent',
|
||||
(tester) async {
|
||||
var attempts = 0;
|
||||
gateway.prompt = (_, _) async {
|
||||
if (++attempts == 1) throw StateError('response lost');
|
||||
return const {};
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
' keep me ',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
' keep me ',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(fieldText(tester), ' keep me ');
|
||||
expect(find.byKey(const Key('chat-composer-error')), findsOneWidget);
|
||||
expect(find.textContaining('response lost'), findsOneWidget);
|
||||
expect(gateway.promptBodies.single['operation_id'], 'op/1');
|
||||
// The refused optimistic turn is withdrawn, not left as a fake message.
|
||||
expect(find.text('keep me'), findsNothing);
|
||||
expect(fieldText(tester), ' keep me ');
|
||||
expect(find.byKey(const Key('chat-composer-error')), findsOneWidget);
|
||||
expect(find.textContaining('response lost'), findsOneWidget);
|
||||
expect(gateway.promptBodies.single['operation_id'], 'op/1');
|
||||
// The refused optimistic turn is withdrawn, not left as a fake message.
|
||||
expect(find.text('keep me'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/1',
|
||||
]);
|
||||
expect(fieldText(tester), '');
|
||||
expect(find.byKey(const Key('chat-composer-error')), findsNothing);
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/1',
|
||||
]);
|
||||
expect(fieldText(tester), '');
|
||||
expect(find.byKey(const Key('chat-composer-error')), findsNothing);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'different',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.last['operation_id'], 'op/2');
|
||||
});
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'different',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.last['operation_id'], 'op/2');
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,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() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final shortcut in ['enter', 'numpad', 'control', 'meta', 'software']) {
|
||||
@@ -46,6 +50,7 @@ void main() {
|
||||
expect(editor.focusNode.hasFocus, isTrue);
|
||||
expect(editor.textInputAction, TextInputAction.send);
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,7 +81,7 @@ void main() {
|
||||
const TextSelection.collapsed(offset: 2),
|
||||
);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
});
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets(
|
||||
'Enter confirms IME composition without submitting ($cupertino)',
|
||||
@@ -108,6 +113,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], '仮');
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,5 +143,6 @@ void main() {
|
||||
reply.complete({});
|
||||
await tester.pumpAndSettle();
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
final _phones = TargetPlatformVariant(const {
|
||||
TargetPlatform.android,
|
||||
TargetPlatform.iOS,
|
||||
});
|
||||
|
||||
void main() {
|
||||
test('Enter sends only on a desktop host', () {
|
||||
expect(chatEnterSends(TargetPlatform.android), isFalse);
|
||||
expect(chatEnterSends(TargetPlatform.iOS), isFalse);
|
||||
for (final desktop in [
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.fuchsia,
|
||||
]) {
|
||||
expect(chatEnterSends(desktop), isTrue);
|
||||
}
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('a phone keyboard breaks lines and Send sends ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
final editor = tester.widget<EditableText>(
|
||||
find.descendant(of: field, matching: find.byType(EditableText)),
|
||||
);
|
||||
expect(editor.textInputAction, TextInputAction.newline);
|
||||
|
||||
await tester.enterText(field, 'line one');
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
expect(fieldText(tester), startsWith('line one'));
|
||||
|
||||
await tester.enterText(field, 'line one\nline two');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], 'line one\nline two');
|
||||
}, variant: _phones);
|
||||
|
||||
testWidgets(
|
||||
'Ctrl+Enter still sends from a phone keyboard ($style)',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'message',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], 'message');
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,21 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the activity line starts at the answer\'s edge ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host([_answer], cupertino: cupertino));
|
||||
|
||||
final activity = find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
expect(
|
||||
tester.getTopLeft(activity.first).dx,
|
||||
tester.getTopLeft(find.text('First paragraph.')).dx,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a finished reply copies its answer text ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user