4a85a12cf7
The open conversation draws its own bar of separate rounded pieces: the platform Back in a circle, a title pill with the folder that opens the chat information, and a pill with the model and mode controls. Detail pages drop only their app bar for it, keeping the body mounted.
132 lines
4.3 KiB
Dart
132 lines
4.3 KiB
Dart
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 '../../../native_back.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 pill and model 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);
|
|
// Back is the platform's own control, as on every other page.
|
|
expect(
|
|
find.descendant(of: back, matching: findNativeBack()),
|
|
findsOneWidget,
|
|
);
|
|
|
|
// One floating row of separate pieces: the round Back, the title pill
|
|
// (which is the information control and holds the title), then the
|
|
// model in the trailing pill.
|
|
double centerY(Finder finder) => tester.getCenter(finder).dy;
|
|
expect((centerY(back) - centerY(info)).abs(), lessThan(16));
|
|
expect((centerY(model) - centerY(info)).abs(), lessThan(16));
|
|
expect(find.descendant(of: info, matching: title), findsOneWidget);
|
|
double right(Finder finder) => tester.getTopRight(finder).dx;
|
|
expect(right(back), lessThanOrEqualTo(tester.getTopLeft(info).dx));
|
|
expect(right(info), lessThanOrEqualTo(tester.getTopLeft(model).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': 'other'},
|
|
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);
|
|
});
|
|
}
|