feat(app): compact chat session rows and thread header
Follow the web chat layout on both hosts without changing request shapes or
bubble/composer behaviour.
- Session rows (Material and Cupertino): title with trailing relative
recency, muted `directory · model` line with the `New`/`Closed` word at
the trailing edge. Shared row content keeps one arrangement; native tiles
keep their own padding, separators and subtitle size. The state word keeps
its intrinsic width and the metadata ellipsises first, so it is never
clipped at 320px/2x.
- Thread header: one row of compact icon-only Back, ellipsised title,
bounded model control and Chat information. Back keeps the destination as
its accessible name and both hosts share `Key('chat-back')`.
- Share the epoch-millis parser as `chatSessionMillis`, and match the web's
relative-time words, including `Sept`.
- Cover the row content, status word at narrow widths, header layout and
Back accessibility in widget tests; update existing tests for the
separate trailing status word.
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
const _title = 'A conversation title long enough to need an ellipsis at 320px';
|
||||
const _session = <String, dynamic>{
|
||||
'id': 's',
|
||||
'backend': 'opencode',
|
||||
'model': 'provider/an-extremely-long-recorded-model-id',
|
||||
'model_provider': 'p1',
|
||||
};
|
||||
|
||||
Widget _host(Widget child, {required bool cupertino}) => cupertino
|
||||
? CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void _useNarrowText(WidgetTester tester) {
|
||||
tester.view.physicalSize = const Size(320, 640);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host header keeps back, title, model and actions on one row', (
|
||||
tester,
|
||||
) async {
|
||||
_useNarrowText(tester);
|
||||
final semantics = tester.ensureSemantics();
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
gateway.subscribe = () async => const {};
|
||||
var backed = 0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
title: _title,
|
||||
session: _session,
|
||||
onBack: () => backed++,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final title = find.text(_title);
|
||||
final model = find.byKey(const Key('chat-model'));
|
||||
final info = find.byKey(const Key('chat-info'));
|
||||
final back = find.byKey(const Key('chat-back'));
|
||||
expect(title, findsOneWidget);
|
||||
expect(model, findsOneWidget);
|
||||
expect(info, findsOneWidget);
|
||||
expect(back, findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
// The icon-only control still states its destination for assistive use.
|
||||
if (cupertino) {
|
||||
expect(find.bySemanticsLabel('Back to chats'), findsOneWidget);
|
||||
} else {
|
||||
expect(find.byTooltip('Back to chats'), findsOneWidget);
|
||||
}
|
||||
|
||||
// One row, in the web's order: back, title, model, information. A wrapped
|
||||
// header would put the controls on a different line from the title.
|
||||
double centerY(Finder finder) => tester.getCenter(finder).dy;
|
||||
expect((centerY(back) - centerY(title)).abs(), lessThan(16));
|
||||
expect((centerY(model) - centerY(title)).abs(), lessThan(16));
|
||||
expect((centerY(info) - centerY(title)).abs(), lessThan(16));
|
||||
double right(Finder finder) => tester.getTopRight(finder).dx;
|
||||
expect(right(back), lessThanOrEqualTo(tester.getTopLeft(title).dx));
|
||||
expect(right(title), lessThanOrEqualTo(tester.getTopLeft(model).dx));
|
||||
expect(right(model), lessThanOrEqualTo(tester.getTopLeft(info).dx));
|
||||
|
||||
await tester.tap(back);
|
||||
await tester.pump();
|
||||
expect(backed, 1);
|
||||
semantics.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a conversation without a model keeps the same compact row', (
|
||||
tester,
|
||||
) async {
|
||||
_useNarrowText(tester);
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
gateway.subscribe = () async => const {};
|
||||
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
title: _title,
|
||||
session: {..._session, 'backend': 'claude'},
|
||||
onBack: () {},
|
||||
),
|
||||
cupertino: false,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(_title), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-model')), findsNothing);
|
||||
expect(
|
||||
(tester.getCenter(find.byKey(const Key('chat-info'))).dy -
|
||||
tester.getCenter(find.text(_title)).dy)
|
||||
.abs(),
|
||||
lessThan(16),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user