Allow adding chats on phones and keep their native detail route

This commit is contained in:
2026-11-06 21:46:45 +00:00
parent 6bba6cf8d8
commit 2cd8003e3a
5 changed files with 152 additions and 11 deletions
@@ -79,6 +79,90 @@ Future<void> _split(WidgetTester tester, String id, String action) async {
}
void main() {
testWidgets('phone peeks fit a small keyboard viewport at large text', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(560, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(2)),
child: child!,
),
home: Scaffold(body: ChatScreen(gateway: gateway)),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pumpAndSettle();
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
controller.splitActive('b', ChatSplitAxis.vertical);
await tester.pumpAndSettle();
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_thread('b'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('phone can add a second chat without losing its first draft', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(_app(gateway));
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pumpAndSettle();
expect(find.byTooltip('Back').hitTestable(), findsOneWidget);
final stateA = tester.state(_thread('a'));
await tester.enterText(_input('a'), 'Phone draft A');
await tester.pumpAndSettle();
final add = find.byTooltip('Add chat pane').hitTestable();
if (add.evaluate().isEmpty) {
await tester.tap(find.byTooltip('More actions').first);
await tester.pumpAndSettle();
await tester.tap(find.text('Add chat pane'));
} else {
await tester.tap(add);
}
await tester.pumpAndSettle();
await tester.tap(find.text('Chat b'));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_thread('b'), findsOneWidget);
expect(tester.state(_thread('a')), same(stateA));
expect(
tester.widget<EditableText>(_input('a')).controller.text,
'Phone draft A',
);
final workspace = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
expect(workspace.controller.paneCount, 2);
expect(workspace.controller.activePane?.sessionId, 'b');
final first = workspace.controller.panes.first.id;
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
await tester.pumpAndSettle();
expect(workspace.controller.activePane?.sessionId, 'a');
expect(
tester.widget<EditableText>(_input('b')).focusNode.hasFocus,
isFalse,
);
expect(tester.state(_thread('a')), same(stateA));
expect(tester.takeException(), isNull);
});
testWidgets('compact and hidden sidebar preserve panes and drafts', (
tester,
) async {
@@ -147,12 +231,11 @@ void main() {
tester.view.physicalSize = const Size(560, 1000);
await tester.pumpAndSettle();
expect(_thread('c'), findsOneWidget);
expect(_thread('a'), findsNothing);
expect(_thread('b'), findsNothing);
expect(find.byType(ChatThreadView), findsNWidgets(2));
tester.view.physicalSize = const Size(390, 844);
await tester.pumpAndSettle();
expect(_thread('c'), findsOneWidget);
expect(_thread('a'), findsNothing);
expect(find.byType(ChatThreadView), findsNWidgets(2));
expect(tester.state(_thread('a', offstage: true)), same(stateA));
tester.view.physicalSize = const Size(1800, 1000);
await tester.pumpAndSettle();