Files
pipelines/app/test/features/chat/conversation/chat_wheel_fixtures.dart
T
alan d02d5ea11d Chat transcript: wheel and trackpad scrolling always reaches the transcript
Root causes found in release web captures (1280x800 and 560x900):
- Follow mode undid small wheel/trackpad ticks at the end: each tick is its
  own scroll, re-judged as following within 32 px and jumped back. A user
  scroll toward older rows now releases the end however small; the jump
  control appears once streamed content moves the end beyond the threshold.
- The end-of-scroll jump ran inside the position's activity switch, so a
  touch or scrollbar drag released near the end recursed without end (stack
  overflow during the gesture). The jump now runs after the notification.
- Horizontally scrolling code blocks and tables claimed diagonal trackpad
  gestures whole. HorizontalScrollView gives mostly vertical gestures to the
  enclosing list; sideways and Shift + wheel still scroll the block.
- The wheel over the floating chat bar, composer and jump control moved
  nothing. VerticalWheelForwarder scrolls the transcript from them unless
  something under the pointer claims the event.

Adds widget tests per content kind and scroll mode, follow/touch/Load older
tests, a capture-kit check (tool/capture/examples/chat-wheel-scroll.json)
with eval/expect steps, wheel dx/repeat, --params and eval: targets, a
transcript scroll probe and fixture options, and fixes the kit ignoring a
script's size. Notes in notes/chat-wheel-scroll.md.
2026-11-02 20:37:36 +00:00

143 lines
4.6 KiB
Dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_attachment_gallery.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_injected_rows.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
import 'chat_thread_fixtures.dart';
import 'chat_thread_scroll_test.dart' show host;
/// The transcript content kinds a wheel can land on.
enum ChatWheelKind { text, code, wide, table, agent, notice, image }
const _png =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlE'
'QVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
const _wideLine = 'go test ./internal/server/... -run TestWheel && ';
String _table() =>
'| ${[for (var c = 0; c < 16; c++) 'Column $c'].join(' | ')} |\n'
'| ${List.filled(16, '---').join(' | ')} |\n'
'| ${[for (var c = 0; c < 16; c++) 'value $c'].join(' | ')} |';
/// One message drawing [kind], with id [id].
JsonMap chatWheelMessage(ChatWheelKind kind, String id) {
JsonMap text(String role, String body, {String? messageKind}) => {
...chatMessage(
id,
role,
parts: [
{'type': 'text', 'name': 'reviewer', 'text': body},
],
),
'kind': ?messageKind,
};
return switch (kind) {
ChatWheelKind.text => text('assistant', 'A plain answer paragraph. ' * 4),
ChatWheelKind.code => text(
'assistant',
'```dart\n${List.generate(4, (l) => 'final v$l = $l;').join('\n')}\n```',
),
ChatWheelKind.wide => text(
'assistant',
'```sh\n${List.filled(12, _wideLine).join()}true\n```',
),
ChatWheelKind.table => text('assistant', _table()),
ChatWheelKind.agent => text(
'user',
'## Review\n\nAll checks passed.',
messageKind: 'agent_report',
),
ChatWheelKind.notice => text(
'user',
'Background task finished.',
messageKind: 'notice',
),
ChatWheelKind.image => chatMessage(
id,
'user',
parts: [
{'type': 'file', 'mime': 'image/png', 'name': 'a.png', 'uri': _png},
{'type': 'text', 'text': 'With an image'},
],
),
};
}
/// The widget that draws [kind] in the transcript.
Finder chatWheelTarget(ChatWheelKind kind) {
Finder code(String text) => find.ancestor(
of: find.textContaining(text),
matching: find.byType(SingleChildScrollView),
);
return switch (kind) {
ChatWheelKind.text => find.byWidgetPredicate(
(widget) =>
widget is ChatMessageView &&
(widget.row['messageIds'] as List?)?.contains('target') == true,
),
ChatWheelKind.code => code('final v0'),
ChatWheelKind.wide => code('go test'),
ChatWheelKind.table => find.byType(Table),
ChatWheelKind.agent => find.byType(ChatAgentReportCard),
ChatWheelKind.notice => find.byType(ChatSystemNoticeLine),
ChatWheelKind.image => find.byType(ChatAttachmentGallery),
};
}
List<JsonMap> chatWheelFillers(int count) => [
for (var index = 0; index < count; index++)
chatMessage(
'f$index',
index.isEven ? 'user' : 'assistant',
parts: [
{
'type': 'text',
'text':
'Filler $index. ${List.filled(5, 'A sentence that wraps across the transcript width.').join(' ')}',
},
],
),
];
Finder get chatWheelThread => find.byKey(const Key('chat-thread-s'));
Future<void> openChatWheelThread(
WidgetTester tester,
FakeChatGateway gateway,
) async {
await tester.pumpWidget(
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
}
/// The centre of [finder]'s part between the floating bar and the composer.
Offset chatWheelPoint(WidgetTester tester, Finder finder) {
final top = tester.getRect(find.byKey(const Key('chat-info'))).bottom + 4;
final bottom =
tester.getRect(find.byKey(const Key('chat-composer-pill'))).top - 4;
final shown = tester
.getRect(finder.first)
.intersect(Rect.fromLTRB(0, top, 800, bottom));
expect(shown.height, greaterThan(8), reason: '$finder is not in view');
return shown.center;
}
/// One wheel or trackpad tick of [delta] at [at].
Future<void> wheel(
WidgetTester tester,
Offset at,
Offset delta, {
PointerDeviceKind kind = PointerDeviceKind.mouse,
}) async {
final pointer = TestPointer(1, kind);
await tester.sendEventToBinding(pointer.hover(at));
await tester.sendEventToBinding(pointer.scroll(delta));
await tester.pump();
}