Keep chat controls readable and expose labeled app navigation

This commit is contained in:
2026-11-07 20:46:02 +00:00
parent 68c0ad3caa
commit 4bbbe01633
20 changed files with 582 additions and 159 deletions
@@ -41,7 +41,7 @@ Widget _app(_Gateway gateway, {int sync = 0}) => MaterialApp(
body: ChatScreen(gateway: gateway, syncToken: sync),
),
);
Future<_Gateway> _setup(WidgetTester tester) async {
Future<_Gateway> _setup(WidgetTester tester, {bool inShell = false}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
@@ -60,7 +60,21 @@ Future<_Gateway> _setup(WidgetTester tester) async {
]);
};
addTearDown(gateway.close);
await tester.pumpWidget(_app(gateway));
await tester.pumpWidget(
inShell
? MaterialApp(
home: AdaptiveShell(
cupertino: false,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
AppDestination.runs: (_) =>
const Center(child: Text('Runs destination')),
},
),
)
: _app(gateway),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pumpAndSettle();
@@ -79,6 +93,35 @@ Future<void> _split(WidgetTester tester, String id, String action) async {
}
void main() {
testWidgets(
'compact navigation reaches Runs and returns without losing draft',
(tester) async {
await _setup(tester, inShell: true);
final state = tester.state(_thread('a'));
await tester.enterText(_input('a'), 'Keep compact draft');
await tester.drag(
find.byKey(const ValueKey('list-detail-divider')),
const Offset(-500, 0),
);
await tester.pumpAndSettle();
expect(find.text('Menu'), findsOneWidget);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
await tester.tap(find.text('Runs'));
await tester.pumpAndSettle();
expect(find.text('Runs destination'), findsOneWidget);
await tester.tap(find.byTooltip('Chat'));
await tester.pumpAndSettle();
expect(find.text('Menu'), findsOneWidget);
expect(tester.state(_thread('a')), same(state));
expect(
tester.widget<EditableText>(_input('a')).controller.text,
'Keep compact draft',
);
expect(tester.takeException(), isNull);
},
);
testWidgets('phone peeks fit a small keyboard viewport at large text', (
tester,
) async {
@@ -226,44 +226,47 @@ void main() {
}
});
testWidgets('Cupertino mode is icon-only below 600px', (tester) async {
if (!cupertino) return;
final semantics = tester.ensureSemantics();
_size(tester, const Size(560, 800));
await _pump(
tester,
cupertino: true,
messages: 1,
session: const {
'id': 's',
'backend': 'opencode',
'model': 'p/sonnet-4-5',
'mode': 'default',
'mode_name': 'Ask for permission',
},
);
testWidgets(
'Cupertino narrow header displays the current permission value',
(tester) async {
if (!cupertino) return;
final semantics = tester.ensureSemantics();
_size(tester, const Size(560, 800));
await _pump(
tester,
cupertino: true,
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'));
expect(mode, findsOneWidget);
expect(
find.descendant(of: mode, matching: find.text('Ask for permission')),
findsNothing,
);
expect(
tester.getSemantics(mode).label,
contains('Change mode, currently Ask for permission'),
);
await tester.tap(mode);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
// The fixture has no chat_modes catalog, but the recorded session mode
// remains visible in the sheet.
expect(
find.byKey(const ValueKey('chat-mode-option-default')),
findsOneWidget,
);
expect(find.text('Ask for permission'), findsOneWidget);
semantics.dispose();
});
final mode = find.byKey(const Key('chat-mode'));
expect(mode, findsOneWidget);
expect(
find.descendant(of: mode, matching: find.text('Ask for permission')),
findsOneWidget,
);
expect(
tester.getSemantics(mode).label,
contains('Change mode, currently Ask for permission'),
);
await tester.tap(mode);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
// The fixture has no chat_modes catalog, but the recorded session mode
// remains visible in the sheet.
expect(
find.byKey(const ValueKey('chat-mode-option-default')),
findsOneWidget,
);
expect(find.text('Ask for permission'), findsWidgets);
semantics.dispose();
},
);
}
}
@@ -65,8 +65,11 @@ void main() {
) async {
await _pump(tester, peek: false, reveal: 1);
expect(header, findsOneWidget);
expect(listTop(tester), greaterThan(8));
expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5));
expect(listTop(tester), 8);
expect(
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
closeTo(tester.getBottomLeft(header).dy, .5),
);
});
testWidgets('a resting peek keeps its bar offstage and reads from the top', (
@@ -95,8 +98,8 @@ void main() {
await _pump(tester, peek: true, reveal: .4);
expect(header, findsOneWidget);
expect(
listTop(tester),
closeTo(tester.getSize(header).height * .4 + 8, .5),
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
closeTo(tester.getSize(header).height * .4, .5),
);
final fade = tester.widget<FadeTransition>(
find.ancestor(of: header, matching: find.byType(FadeTransition)).first,
@@ -41,62 +41,69 @@ 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;
testWidgets(
'$host narrow header keeps native back/title and readable model',
(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++,
await tester.pumpWidget(
_host(
ChatThreadView(
gateway: gateway,
sessionId: 's',
title: _title,
session: _session,
onBack: () => backed++,
),
cupertino: cupertino,
),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
);
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,
);
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));
// 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(
tester.getTopLeft(model).dy,
greaterThanOrEqualTo(tester.getBottomLeft(info).dy),
);
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(
find.textContaining('an-extremely-long-recorded-model-id'),
findsOneWidget,
);
await tester.tap(back);
await tester.pump();
expect(backed, 1);
semantics.dispose();
});
await tester.tap(back);
await tester.pump();
expect(backed, 1);
semantics.dispose();
},
);
}
for (final cupertino in [false, true]) {
@@ -151,10 +158,17 @@ void main() {
final actions = find.byKey(const Key('chat-actions-island'));
expect(selectors, findsOneWidget);
expect(actions, findsOneWidget);
expect(
tester.getTopRight(selectors).dx,
lessThan(tester.getTopLeft(actions).dx),
);
if (width >= 800) {
expect(
tester.getTopRight(selectors).dx,
lessThan(tester.getTopLeft(actions).dx),
);
} else {
expect(
tester.getTopLeft(selectors).dy,
greaterThanOrEqualTo(tester.getBottomLeft(actions).dy),
);
}
expect(find.byKey(const Key('chat-next')), findsNothing);
expect(find.text('Next chat'), findsNothing);
expect(find.byKey(const Key('chat-model')), findsOneWidget);