Expose horizontal chat overflow with native scrollbars and keyboard controls

This commit is contained in:
2026-11-07 20:35:13 +00:00
parent 5ddd52f817
commit 004979ccd0
6 changed files with 432 additions and 4 deletions
@@ -0,0 +1,201 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_horizontal_viewport.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
Widget _host({
bool cupertino = false,
Brightness brightness = Brightness.dark,
TextDirection direction = TextDirection.ltr,
double contentWidth = 900,
double width = 260,
ScrollController? vertical,
Widget? child,
}) {
final body = Directionality(
textDirection: direction,
child: MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: SingleChildScrollView(
controller: vertical,
child: Column(
children: [
SizedBox(
width: width,
child:
child ??
ChatHorizontalViewport(
child: SizedBox(
width: contentWidth,
height: 80,
child: const Text('Readable content'),
),
),
),
const SizedBox(height: 1200),
],
),
),
),
);
return cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: CupertinoPageScaffold(child: body),
)
: MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(body: body),
);
}
ScrollController _controller(WidgetTester tester, bool cupertino) => cupertino
? tester
.widget<CupertinoScrollbar>(find.byType(CupertinoScrollbar))
.controller!
: tester.widget<Scrollbar>(find.byType(Scrollbar)).controller!;
void main() {
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'native overflow affordance, endpoints and keyboard $cupertino $brightness',
(tester) async {
await tester.pumpWidget(
_host(cupertino: cupertino, brightness: brightness),
);
await tester.pumpAndSettle();
expect(find.text('Scroll horizontally'), findsOneWidget);
final controller = _controller(tester, cupertino);
expect(controller.position.maxScrollExtent, 640);
expect(
cupertino
? tester
.widget<CupertinoScrollbar>(
find.byType(CupertinoScrollbar),
)
.thumbVisibility
: tester
.widget<Scrollbar>(find.byType(Scrollbar))
.thumbVisibility,
isTrue,
);
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
final focus = tester
.widgetList<Focus>(find.byType(Focus))
.firstWhere(
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
);
focus.focusNode!.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(controller.offset, 80);
expect(find.byIcon(Icons.swap_horiz), findsOneWidget);
controller.jumpTo(controller.position.maxScrollExtent);
await tester.pumpAndSettle();
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
await tester.pumpWidget(
_host(
cupertino: cupertino,
brightness: brightness,
contentWidth: 120,
),
);
await tester.pumpAndSettle();
expect(find.text('Scroll horizontally'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
}
testWidgets(
'RTL arrows describe physical direction and offset survives rebuild',
(tester) async {
await tester.pumpWidget(_host(direction: TextDirection.rtl));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
expect(
tester.widget<Icon>(find.byIcon(Icons.arrow_back)).textDirection,
TextDirection.ltr,
);
final controller = _controller(tester, false);
final focus = tester
.widgetList<Focus>(find.byType(Focus))
.firstWhere(
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
);
focus.focusNode!.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.pumpAndSettle();
expect(controller.offset, 80);
await tester.pumpWidget(
_host(direction: TextDirection.rtl, brightness: Brightness.light),
);
await tester.pumpAndSettle();
expect(_controller(tester, false).offset, 80);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'vertical wheel over overflowing content reaches parent and touch scrolls sideways',
(tester) async {
final vertical = ScrollController();
await tester.pumpWidget(_host(vertical: vertical));
await tester.pumpAndSettle();
final controller = _controller(tester, false);
await tester.sendEventToBinding(
PointerScrollEvent(
position:
tester.getTopLeft(find.byType(ChatHorizontalViewport)) +
const Offset(80, 30),
scrollDelta: const Offset(0, 120),
kind: PointerDeviceKind.mouse,
),
);
await tester.pumpAndSettle();
expect(vertical.offset, greaterThan(0));
vertical.jumpTo(0);
await tester.pump();
await tester.dragFrom(
tester.getTopLeft(find.byType(ChatHorizontalViewport)) +
const Offset(180, 30),
const Offset(-120, 0),
);
await tester.pumpAndSettle();
expect(controller.offset, greaterThan(0));
await tester.pumpWidget(const SizedBox());
vertical.dispose();
},
);
testWidgets('code and table labels identify the scrollable region', (
tester,
) async {
await tester.pumpWidget(
_host(
child: const ChatMarkdownView(
text:
'```\nvery_long_identifier_very_long_identifier_very_long_identifier\n```\n\n| Heading one | Heading two | Heading three |\n| --- | --- | --- |\n| alpha alpha alpha | beta beta beta | gamma gamma gamma |',
),
),
);
await tester.pumpAndSettle();
expect(
find.bySemanticsLabel('Horizontally scrollable code block'),
findsOneWidget,
);
expect(
find.bySemanticsLabel('Horizontally scrollable table'),
findsOneWidget,
);
expect(find.text('Scroll horizontally'), findsNWidgets(2));
expect(tester.takeException(), isNull);
});
}