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:
@@ -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