3b0f9a054c
Keep the floating chat header regression test aligned with the split action pills introduced by the lone More island layout.
213 lines
7.2 KiB
Dart
213 lines
7.2 KiB
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.dart'
|
|
show segmentedMoreKey;
|
|
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) => 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, {
|
|
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: () {},
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
return gateway;
|
|
}
|
|
|
|
void main() {
|
|
// The mode control is Material only.
|
|
testWidgets('transcript viewport ends at the composer top', (tester) async {
|
|
_size(tester, const Size(560, 800));
|
|
await _pump(tester);
|
|
|
|
final pill = find.byKey(const Key('chat-composer-pill'));
|
|
expect(tester.widget(pill), isA<GlassPill>());
|
|
Rect list() => tester.getRect(find.byKey(const ValueKey('chat-thread-s')));
|
|
Rect composer() => tester.getRect(find.byKey(const Key('chat-composer')));
|
|
Rect header() =>
|
|
tester.getRect(find.byKey(const Key('chat-thread-header')));
|
|
// The transcript has its own viewport below the complete header.
|
|
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
|
// Nothing renders behind the composer: the viewport stops at its top.
|
|
expect(list().bottom, composer().top);
|
|
expect(composer().bottom, lessThanOrEqualTo(800));
|
|
expect(tester.getRect(pill).top, greaterThanOrEqualTo(list().bottom));
|
|
|
|
// Following the end, the last message rests fully above the composer.
|
|
final last = find.text('Message number 29 of the transcript.');
|
|
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
|
|
|
// A multi-line draft grows the composer; the viewport shrinks with it
|
|
// and the newest message stays in view above it.
|
|
final oneLine = composer().top;
|
|
await tester.enterText(
|
|
find.byKey(const Key('chat-composer-field')),
|
|
List.generate(6, (index) => 'Draft line $index').join('\n'),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(composer().top, lessThan(oneLine));
|
|
expect(list().bottom, composer().top);
|
|
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
|
|
|
// Scrolling back up moves history down inside the shortened viewport.
|
|
final rested = tester.getRect(last).top;
|
|
await tester.drag(
|
|
find.byKey(const ValueKey('chat-thread-s')),
|
|
const Offset(0, 120),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
if (last.evaluate().isNotEmpty) {
|
|
expect(tester.getRect(last).top, greaterThan(rested));
|
|
}
|
|
expect(list().bottom, composer().top);
|
|
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('transcript and composer share a centred reading width', (
|
|
tester,
|
|
) async {
|
|
_size(tester, const Size(1200, 800));
|
|
await _pump(tester, 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('header draws no empty pill without model or mode', (
|
|
tester,
|
|
) async {
|
|
_size(tester, const Size(560, 800));
|
|
await _pump(
|
|
tester,
|
|
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);
|
|
// The round Back, the title pill, and the two action pills (including the
|
|
// More menu), so the More control is never drawn empty. A narrow bar moves
|
|
// the Files toggle into that menu.
|
|
expect(
|
|
find.descendant(of: header, matching: find.byType(SegmentedPill)),
|
|
findsNWidgets(4),
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: header,
|
|
matching: find.bySemanticsIdentifier('chat-files-toggle'),
|
|
),
|
|
findsNothing,
|
|
);
|
|
// The bar's own disabled More beside the actions' one.
|
|
expect(
|
|
find.descendant(of: header, matching: find.byKey(segmentedMoreKey)),
|
|
findsWidgets,
|
|
);
|
|
});
|
|
|
|
testWidgets('header controls keep their natural width when wide', (
|
|
tester,
|
|
) async {
|
|
_size(tester, const Size(1200, 800));
|
|
await _pump(
|
|
tester,
|
|
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.
|
|
final button = tester.widget<TextButton>(mode);
|
|
final theme = Theme.of(tester.element(mode));
|
|
expect(
|
|
button.style!.foregroundColor!.resolve({}),
|
|
theme.colorScheme.onSurfaceVariant,
|
|
);
|
|
});
|
|
}
|