fix(app): float the chat composer as glass, cap the reading width, tidy chat chrome
This commit is contained in:
@@ -94,7 +94,12 @@ void main() {
|
||||
find.byKey(const Key('chat-background-tasks-modal')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.text('0 tasks'), findsOneWidget);
|
||||
// The other session runs nothing: no control, never a "0 tasks".
|
||||
expect(find.text('0 tasks'), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('chat-background-tasks-button')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.text('old session output'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
@@ -104,7 +109,10 @@ void main() {
|
||||
testWidgets(
|
||||
'owner disposal removes only its modal, not an unrelated top route',
|
||||
(tester) async {
|
||||
final gateway = TasksGateway();
|
||||
final gateway = TasksGateway()
|
||||
..shells = (_) async => {
|
||||
'chat_shells': [task('a')],
|
||||
};
|
||||
addTearDown(gateway.close);
|
||||
var visible = true;
|
||||
late StateSetter rebuild;
|
||||
|
||||
@@ -156,7 +156,7 @@ void main() {
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('an empty snapshot shows zero tasks and an honest empty modal', (
|
||||
testWidgets('an empty snapshot shows no task control, never "0 tasks"', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _TasksGateway();
|
||||
@@ -165,11 +165,10 @@ void main() {
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('0 tasks'), findsOneWidget);
|
||||
expect(find.text('Background tasks'), findsNothing);
|
||||
expect(find.text('0 tasks'), findsNothing);
|
||||
expect(find.textContaining('task'), findsNothing);
|
||||
expect(find.byKey(const Key('chat-background-tasks-button')), findsNothing);
|
||||
expect(gateway.fieldsFor('chat_shells'), hasLength(1));
|
||||
await _openTasks(tester);
|
||||
expect(find.text('No background tasks running.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('pushed shell frames add and remove this session tasks', (
|
||||
@@ -612,7 +611,7 @@ void main() {
|
||||
expect(find.text('go test ./...'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the task badge sits above Send, outside the transcript', (
|
||||
testWidgets('the task control sits inside the composer pill beside Send', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _TasksGateway();
|
||||
@@ -622,19 +621,39 @@ void main() {
|
||||
await tester.pumpWidget(_thread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final tasks = tester.getRect(
|
||||
find.byKey(const Key('chat-background-tasks-button')),
|
||||
);
|
||||
final list = tester.getRect(
|
||||
find.byKey(const ValueKey<String>('chat-thread-s')),
|
||||
final button = find.byKey(const Key('chat-background-tasks-button'));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-composer-pill')),
|
||||
matching: button,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final tasks = tester.getRect(button);
|
||||
final send = tester.getRect(find.byKey(const Key('chat-composer-primary')));
|
||||
final composer = tester.getRect(
|
||||
find.byKey(const ValueKey('chat-composer-s')),
|
||||
expect(tasks.right, lessThanOrEqualTo(send.left));
|
||||
expect(tasks.bottom, greaterThan(send.top));
|
||||
expect(tasks.top, lessThan(send.bottom));
|
||||
// Neutral, not the primary tint.
|
||||
final style = tester.widget<TextButton>(button).style!;
|
||||
final theme = Theme.of(tester.element(button));
|
||||
expect(
|
||||
style.foregroundColor!.resolve({}),
|
||||
theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
expect(tasks.bottom, lessThanOrEqualTo(send.top));
|
||||
expect(send.center.dx, inInclusiveRange(tasks.left, tasks.right));
|
||||
expect(tasks.top, greaterThanOrEqualTo(composer.top));
|
||||
expect(list.bottom, lessThanOrEqualTo(composer.top));
|
||||
});
|
||||
|
||||
testWidgets('a conversation without tasks shows no task caption', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _TasksGateway();
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('0 tasks'), findsNothing);
|
||||
expect(find.byKey(const Key('chat-background-tasks-button')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_reading_width.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
/// Floating composer, reading width and header controls of a conversation.
|
||||
|
||||
Widget _host(Widget child, {required bool cupertino}) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void _size(WidgetTester tester, Size size) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _messages(int count) => [
|
||||
for (var index = 0; index < count; index++)
|
||||
chatMessage(
|
||||
'm$index',
|
||||
index.isEven ? 'user' : 'assistant',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Message number $index of the transcript.'},
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
Future<FakeChatGateway> _pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
int messages = 30,
|
||||
Map<String, dynamic>? session,
|
||||
}) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(_messages(messages));
|
||||
gateway.subscribe = () async => const {};
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
title: 'Floating chrome',
|
||||
session: session,
|
||||
onBack: () {},
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host composer floats as glass with the transcript behind', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(tester, cupertino: cupertino);
|
||||
|
||||
final pill = find.byKey(const Key('chat-composer-pill'));
|
||||
expect(tester.widget(pill), isA<GlassPill>());
|
||||
// The transcript fills the page: it runs under the composer.
|
||||
final list = tester.getRect(find.byKey(const ValueKey('chat-thread-s')));
|
||||
final composer = tester.getRect(pill);
|
||||
expect(list.bottom, 800);
|
||||
expect(composer.bottom, lessThanOrEqualTo(800));
|
||||
expect(composer.top, greaterThan(list.top));
|
||||
expect(list.bottom, greaterThanOrEqualTo(composer.bottom));
|
||||
|
||||
// Following the end, the last message rests fully above the composer.
|
||||
final last = tester.getRect(
|
||||
find.text('Message number 29 of the transcript.'),
|
||||
);
|
||||
expect(last.bottom, lessThanOrEqualTo(composer.top));
|
||||
|
||||
// Scrolling back up passes history behind the floating composer.
|
||||
await tester.drag(
|
||||
find.byKey(const ValueKey('chat-thread-s')),
|
||||
const Offset(0, 120),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final behind = find.text('Message number 29 of the transcript.');
|
||||
if (behind.evaluate().isNotEmpty) {
|
||||
expect(tester.getRect(behind).top, greaterThan(last.top));
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('$host transcript and composer share a centred reading width', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(tester, cupertino: cupertino, messages: 4);
|
||||
|
||||
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
|
||||
expect(pill.width, lessThanOrEqualTo(kChatReadingWidth));
|
||||
expect(pill.center.dx, closeTo(600, 1));
|
||||
final message = tester.getRect(
|
||||
find.text('Message number 0 of the transcript.'),
|
||||
);
|
||||
final inset = chatReadingInset(1200);
|
||||
expect(message.left, greaterThanOrEqualTo(inset));
|
||||
expect(message.right, lessThanOrEqualTo(1200 - inset));
|
||||
// The list itself still spans the window, so its margins scroll it.
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('chat-thread-s'))).width,
|
||||
1200,
|
||||
);
|
||||
|
||||
// Narrow, the column fills the width less the usual margins.
|
||||
_size(tester, const Size(560, 800));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('chat-composer-pill'))).width,
|
||||
560 - 32,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host header draws no empty pill without model or mode', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
messages: 1,
|
||||
session: const {'id': 's', 'backend': 'pi', 'directory': '/srv'},
|
||||
);
|
||||
final header = find.byKey(const Key('chat-thread-header'));
|
||||
expect(find.byKey(const Key('chat-mode')), findsNothing);
|
||||
// Only the round Back and the title pill: no (empty) actions pill.
|
||||
expect(
|
||||
find.descendant(of: header, matching: find.byType(SegmentedPill)),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host header controls keep their natural width when wide', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
messages: 1,
|
||||
session: const {
|
||||
'id': 's',
|
||||
'backend': 'opencode',
|
||||
'model': 'p/sonnet-4-5',
|
||||
'mode': 'default',
|
||||
'mode_name': 'Ask for permission',
|
||||
},
|
||||
);
|
||||
final mode = find.byKey(const Key('chat-mode'));
|
||||
final model = find.byKey(const Key('chat-model'));
|
||||
expect(mode, findsOneWidget);
|
||||
expect(model, findsOneWidget);
|
||||
for (final control in [mode, model]) {
|
||||
final texts = find.descendant(of: control, matching: find.byType(Text));
|
||||
for (final element in texts.evaluate()) {
|
||||
final paragraph = element.renderObject! as RenderParagraph;
|
||||
expect(
|
||||
paragraph.didExceedMaxLines,
|
||||
isFalse,
|
||||
reason: 'truncated at 1200',
|
||||
);
|
||||
}
|
||||
}
|
||||
// Neutral like the bar's other actions, not the primary tint.
|
||||
if (!cupertino) {
|
||||
final button = tester.widget<TextButton>(mode);
|
||||
final theme = Theme.of(tester.element(mode));
|
||||
expect(
|
||||
button.style!.foregroundColor!.resolve({}),
|
||||
theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
} else {
|
||||
final label = tester.widget<RichText>(
|
||||
find.descendant(
|
||||
of: mode,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is RichText &&
|
||||
widget.text.toPlainText() == 'Ask for permission',
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
label.text.style?.color,
|
||||
CupertinoColors.label.resolveFrom(tester.element(mode)),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user