Narrow chat tests to Material hosts
Remove Cupertino-only composer test variants and keep the remaining coverage focused on the app's Material-only runtime.
This commit is contained in:
@@ -21,16 +21,9 @@ void main() {
|
||||
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
Future<void> pumpComposer(
|
||||
WidgetTester tester, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
Future<void> pumpComposer(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
newOperationId: nextOperation,
|
||||
),
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
@@ -430,29 +423,6 @@ void main() {
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets(
|
||||
'the Cupertino host reports an unknown command with its controls',
|
||||
(tester) async {
|
||||
await pumpComposer(tester, cupertino: true);
|
||||
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(tester.takeException(), isNull);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-command-send-as-message')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.promptBodies.single['text'], '/nope');
|
||||
expect(fieldText(tester), '');
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
|
||||
testWidgets('Escape dismisses the local command report', (tester) async {
|
||||
await pumpComposer(tester);
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
@@ -473,23 +443,6 @@ void main() {
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('the Cupertino host shows the same palette', (tester) async {
|
||||
await pumpComposer(tester, cupertino: true);
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
|
||||
await tester.enterText(field, '/re');
|
||||
await tester.pump();
|
||||
|
||||
expect(palette(), findsOneWidget);
|
||||
expect(row('rename'), findsOneWidget);
|
||||
expect(find.text('/rename'), findsOneWidget);
|
||||
expect(find.text('Rename this session'), findsOneWidget);
|
||||
|
||||
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);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
@@ -498,7 +451,7 @@ void main() {
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
await pumpComposer(tester, cupertino: true);
|
||||
await pumpComposer(tester);
|
||||
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
|
||||
await tester.pump();
|
||||
|
||||
|
||||
@@ -111,181 +111,162 @@ void main() {
|
||||
expect(after.controller.selection.baseOffset, 5);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('reasoning first arriving after a queued follow-up stays live '
|
||||
'($cupertino)', (tester) async {
|
||||
gateway.prompt = (_, _) async => {'chat_queued': true};
|
||||
testWidgets('reasoning first arriving after a queued follow-up stays live', (
|
||||
tester,
|
||||
) async {
|
||||
gateway.prompt = (_, _) async => {'chat_queued': true};
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'live',
|
||||
'kind': 'text',
|
||||
'part': {'id': 'live-text-0', 'type': 'text'},
|
||||
'delta': 'Working answer',
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'Continue',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
final activity = find.byKey(const Key('chat-stable-turn-activity'));
|
||||
final activityElement = tester.element(activity);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'live',
|
||||
'kind': 'reasoning',
|
||||
'part': {'id': 'live-reasoning-0', 'type': 'reasoning'},
|
||||
'delta': 'Provided reasoning after the follow-up',
|
||||
});
|
||||
// The combined activity control remains keyed to the live turn while
|
||||
// the queued follow-up is a separate user row.
|
||||
Future<void> frames() async {
|
||||
for (var frame = 0; frame < 8; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
await frames();
|
||||
expect(tester.element(activity), same(activityElement));
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await frames();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await frames();
|
||||
expect(find.text('Provided reasoning after the follow-up'), findsOneWidget);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'running send waits only for its acknowledgement and keeps newer draft',
|
||||
(tester) async {
|
||||
final reply = Completer<Map<String, dynamic>>();
|
||||
gateway.prompt = (_, _) => reply.future;
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
newOperationId: nextOperation,
|
||||
),
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'live',
|
||||
'kind': 'text',
|
||||
'part': {'id': 'live-text-0', 'type': 'text'},
|
||||
'delta': 'Working answer',
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'Continue',
|
||||
);
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
await tester.enterText(field, 'Queue this');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
final activity = find.byKey(const Key('chat-stable-turn-activity'));
|
||||
final activityElement = tester.element(activity);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'live',
|
||||
'kind': 'reasoning',
|
||||
'part': {'id': 'live-reasoning-0', 'type': 'reasoning'},
|
||||
'delta': 'Provided reasoning after the follow-up',
|
||||
});
|
||||
// The combined activity control remains keyed to the live turn while
|
||||
// the queued follow-up is a separate user row.
|
||||
Future<void> frames() async {
|
||||
for (var frame = 0; frame < 8; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
await frames();
|
||||
expect(tester.element(activity), same(activityElement));
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await frames();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await frames();
|
||||
expect(
|
||||
find.text('Provided reasoning after the follow-up'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'running send waits only for its acknowledgement and keeps newer draft '
|
||||
'(${cupertino ? 'cupertino' : 'material'})',
|
||||
(tester) async {
|
||||
final reply = Completer<Map<String, dynamic>>();
|
||||
gateway.prompt = (_, _) => reply.future;
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
newOperationId: nextOperation,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
await tester.enterText(field, 'Queue this');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pump();
|
||||
await tester.enterText(field, 'Newer draft');
|
||||
await tester.pump();
|
||||
// Keyboard submit shares the sending guard: no duplicate in flight.
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pump();
|
||||
expect(gateway.promptBodies, hasLength(1));
|
||||
reply.complete({'chat_queued': true});
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), 'Newer draft');
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('send follow-ups during a running turn without interrupting '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
gateway.prompt = (_, _) async => {'chat_queued': true};
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
newOperationId: nextOperation,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.enterText(field, 'Newer draft');
|
||||
await tester.pump();
|
||||
|
||||
for (final text in ['First follow-up', 'Second follow-up']) {
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
text,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), '');
|
||||
expect(find.text(chatQueuedNotice), findsOneWidget);
|
||||
}
|
||||
expect(gateway.promptBodies.map((body) => body['text']), [
|
||||
'First follow-up',
|
||||
'Second follow-up',
|
||||
]);
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/2',
|
||||
]);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
// Keyboard submit shares the sending guard: no duplicate in flight.
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pump();
|
||||
expect(gateway.promptBodies, hasLength(1));
|
||||
reply.complete({'chat_queued': true});
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), 'Newer draft');
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
});
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('the composer wraps at 320 logical px with 2x text '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
gateway.page = fixtureTurn(
|
||||
user:
|
||||
'A stored question long enough to wrap onto several lines at a '
|
||||
'narrow phone width without clipping any of its words.',
|
||||
answer:
|
||||
'A stored answer that also wraps so the transcript has real '
|
||||
'content above the composer.',
|
||||
);
|
||||
testWidgets('send follow-ups during a running turn without interrupting', (
|
||||
tester,
|
||||
) async {
|
||||
gateway.prompt = (_, _) async => {'chat_queued': true};
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
newOperationId: nextOperation,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (final text in ['First follow-up', 'Second follow-up']) {
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'A draft with enough words to wrap inside the composer field on a '
|
||||
'narrow screen while the host text is scaled up.',
|
||||
text,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('chat-composer')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), '');
|
||||
expect(find.text(chatQueuedNotice), findsOneWidget);
|
||||
}
|
||||
expect(gateway.promptBodies.map((body) => body['text']), [
|
||||
'First follow-up',
|
||||
'Second follow-up',
|
||||
]);
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/2',
|
||||
]);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the composer wraps at 320 logical px with 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
gateway.page = fixtureTurn(
|
||||
user:
|
||||
'A stored question long enough to wrap onto several lines at a '
|
||||
'narrow phone width without clipping any of its words.',
|
||||
answer:
|
||||
'A stored answer that also wraps so the transcript has real '
|
||||
'content above the composer.',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'A draft with enough words to wrap inside the composer field on a '
|
||||
'narrow screen while the host text is scaled up.',
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('chat-composer')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,23 +120,6 @@ void main() {
|
||||
expect(gateway.promptBodies.single['text'], 'line one');
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('Cmd+Enter sends on the Cupertino host', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, cupertino: true, newOperationId: nextOperation),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
await tester.enterText(field, 'mac line');
|
||||
await tester.pump();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.promptBodies.single['text'], 'mac line');
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets('Send is disabled for a blank draft and while sending', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -11,112 +11,104 @@ import 'chat_composer_bar_fixtures.dart';
|
||||
final _desktop = TargetPlatformVariant.only(TargetPlatform.linux);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final shortcut in ['enter', 'numpad', 'control', 'meta', 'software']) {
|
||||
testWidgets(
|
||||
'$shortcut sends on ${cupertino ? 'Cupertino' : 'Material'}',
|
||||
(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'));
|
||||
await tester.enterText(field, ' message ');
|
||||
await tester.pump();
|
||||
final modifier = switch (shortcut) {
|
||||
'control' => LogicalKeyboardKey.controlLeft,
|
||||
'meta' => LogicalKeyboardKey.metaLeft,
|
||||
_ => null,
|
||||
};
|
||||
if (modifier != null) await tester.sendKeyDownEvent(modifier);
|
||||
if (shortcut == 'software') {
|
||||
await tester.testTextInput.receiveAction(TextInputAction.send);
|
||||
} else {
|
||||
await tester.sendKeyEvent(
|
||||
shortcut == 'numpad'
|
||||
? LogicalKeyboardKey.numpadEnter
|
||||
: LogicalKeyboardKey.enter,
|
||||
);
|
||||
}
|
||||
if (modifier != null) await tester.sendKeyUpEvent(modifier);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], 'message');
|
||||
expect(fieldText(tester), isEmpty);
|
||||
final editor = tester.widget<EditableText>(
|
||||
find.descendant(of: field, matching: find.byType(EditableText)),
|
||||
);
|
||||
expect(editor.focusNode.hasFocus, isTrue);
|
||||
expect(editor.textInputAction, TextInputAction.send);
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('Shift+Enter replaces only selected text ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
for (final shortcut in ['enter', 'numpad', 'control', 'meta', 'software']) {
|
||||
testWidgets('$shortcut sends on Material', (tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
await tester.enterText(field, 'abcd');
|
||||
await tester.enterText(field, ' message ');
|
||||
await tester.pump();
|
||||
final modifier = switch (shortcut) {
|
||||
'control' => LogicalKeyboardKey.controlLeft,
|
||||
'meta' => LogicalKeyboardKey.metaLeft,
|
||||
_ => null,
|
||||
};
|
||||
if (modifier != null) await tester.sendKeyDownEvent(modifier);
|
||||
if (shortcut == 'software') {
|
||||
await tester.testTextInput.receiveAction(TextInputAction.send);
|
||||
} else {
|
||||
await tester.sendKeyEvent(
|
||||
shortcut == 'numpad'
|
||||
? LogicalKeyboardKey.numpadEnter
|
||||
: LogicalKeyboardKey.enter,
|
||||
);
|
||||
}
|
||||
if (modifier != null) await tester.sendKeyUpEvent(modifier);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], 'message');
|
||||
expect(fieldText(tester), isEmpty);
|
||||
final editor = tester.widget<EditableText>(
|
||||
find.descendant(of: field, matching: find.byType(EditableText)),
|
||||
);
|
||||
editor.controller.selection = const TextSelection(
|
||||
baseOffset: 1,
|
||||
extentOffset: 3,
|
||||
);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.pump();
|
||||
expect(fieldText(tester), 'a\nd');
|
||||
expect(
|
||||
editor.controller.selection,
|
||||
const TextSelection.collapsed(offset: 2),
|
||||
);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
expect(editor.focusNode.hasFocus, isTrue);
|
||||
expect(editor.textInputAction, TextInputAction.send);
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets(
|
||||
'Enter confirms IME composition without submitting ($cupertino)',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.showKeyboard(find.byKey(const Key('chat-composer-field')));
|
||||
tester.testTextInput.updateEditingValue(
|
||||
const TextEditingValue(
|
||||
text: '仮',
|
||||
selection: TextSelection.collapsed(offset: 1),
|
||||
composing: TextRange(start: 0, end: 1),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
tester.testTextInput.updateEditingValue(
|
||||
const TextEditingValue(
|
||||
text: '仮',
|
||||
selection: TextSelection.collapsed(offset: 1),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], '仮');
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('Shift+Enter replaces only selected text (Material)', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
await tester.enterText(field, 'abcd');
|
||||
await tester.pump();
|
||||
final editor = tester.widget<EditableText>(
|
||||
find.descendant(of: field, matching: find.byType(EditableText)),
|
||||
);
|
||||
editor.controller.selection = const TextSelection(
|
||||
baseOffset: 1,
|
||||
extentOffset: 3,
|
||||
);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.pump();
|
||||
expect(fieldText(tester), 'a\nd');
|
||||
expect(
|
||||
editor.controller.selection,
|
||||
const TextSelection.collapsed(offset: 2),
|
||||
);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
}, variant: _desktop);
|
||||
|
||||
testWidgets(
|
||||
'Enter confirms IME composition without submitting (Material)',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.showKeyboard(find.byKey(const Key('chat-composer-field')));
|
||||
tester.testTextInput.updateEditingValue(
|
||||
const TextEditingValue(
|
||||
text: '仮',
|
||||
selection: TextSelection.collapsed(offset: 1),
|
||||
composing: TextRange(start: 0, end: 1),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
tester.testTextInput.updateEditingValue(
|
||||
const TextEditingValue(
|
||||
text: '仮',
|
||||
selection: TextSelection.collapsed(offset: 1),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.promptBodies.single['text'], '仮');
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'empty Enter, repeat and duplicate software submit send nothing extra',
|
||||
(tester) async {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -7,64 +6,55 @@ import 'chat_composer_bar_fixtures.dart';
|
||||
/// The composer grows to 12 lines before it scrolls, but never past about
|
||||
/// 40% of the visible height (the keyboard excluded).
|
||||
void main() {
|
||||
int? maxLinesOf(WidgetTester tester, bool cupertino) {
|
||||
int? maxLinesOf(WidgetTester tester) {
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
return cupertino
|
||||
? tester.widget<CupertinoTextField>(field).maxLines
|
||||
: tester.widget<TextField>(field).maxLines;
|
||||
return tester.widget<TextField>(field).maxLines;
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('$host: a tall window allows 12 lines; a phone with its '
|
||||
'keyboard open fewer', (tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
testWidgets('Material: a tall window allows 12 lines; a phone with its '
|
||||
'keyboard open fewer', (tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pump();
|
||||
// A non-empty field (the Cupertino placeholder sizing only applies
|
||||
// while empty).
|
||||
await tester.enterText(find.byKey(const Key('chat-composer-field')), 'x');
|
||||
await tester.pump();
|
||||
expect(maxLinesOf(tester, cupertino), 12);
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pump();
|
||||
// A non-empty field, so the placeholder sizing does not apply.
|
||||
await tester.enterText(find.byKey(const Key('chat-composer-field')), 'x');
|
||||
await tester.pump();
|
||||
expect(maxLinesOf(tester), 12);
|
||||
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 340);
|
||||
await tester.pump();
|
||||
final phone = maxLinesOf(tester, cupertino)!;
|
||||
expect(phone, lessThan(12));
|
||||
expect(phone, greaterThan(6));
|
||||
});
|
||||
}
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 340);
|
||||
await tester.pump();
|
||||
final phone = maxLinesOf(tester)!;
|
||||
expect(phone, lessThan(12));
|
||||
expect(phone, greaterThan(6));
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('$host: a newline at the line limit scrolls to the new '
|
||||
'empty line at once', (tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pump();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
// Past the 12-line limit, then a newline at the end: no character
|
||||
// typed on the new line yet.
|
||||
final text = List.generate(14, (i) => 'line $i').join('\n');
|
||||
await tester.enterText(field, '$text\n');
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final scrollable = tester.state<ScrollableState>(
|
||||
find.descendant(of: field, matching: find.byType(Scrollable)).first,
|
||||
);
|
||||
final position = scrollable.position;
|
||||
expect(position.maxScrollExtent, greaterThan(0));
|
||||
expect(position.pixels, moreOrLessEquals(position.maxScrollExtent));
|
||||
});
|
||||
}
|
||||
testWidgets('Material: a newline at the line limit scrolls to the new '
|
||||
'empty line at once', (tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pump();
|
||||
final field = find.byKey(const Key('chat-composer-field'));
|
||||
// Past the 12-line limit, then a newline at the end: no character
|
||||
// typed on the new line yet.
|
||||
final text = List.generate(14, (i) => 'line $i').join('\n');
|
||||
await tester.enterText(field, '$text\n');
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final scrollable = tester.state<ScrollableState>(
|
||||
find.descendant(of: field, matching: find.byType(Scrollable)).first,
|
||||
);
|
||||
final position = scrollable.position;
|
||||
expect(position.maxScrollExtent, greaterThan(0));
|
||||
expect(position.pixels, moreOrLessEquals(position.maxScrollExtent));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,55 +24,51 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('a phone keyboard breaks lines and Send sends (Material)', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
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);
|
||||
|
||||
testWidgets('a phone keyboard breaks lines and Send sends ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
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 (Material)',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
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)),
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'message',
|
||||
);
|
||||
expect(editor.textInputAction, TextInputAction.newline);
|
||||
|
||||
await tester.enterText(field, 'line one');
|
||||
await tester.pump();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
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),
|
||||
);
|
||||
}
|
||||
expect(gateway.promptBodies.single['text'], 'message');
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user