Restore mobile Chats workspace on tab retap
This commit is contained in:
@@ -253,4 +253,33 @@ void main() {
|
||||
// Unknown deeper paths still resolve to the default list.
|
||||
expect(AppRoute.parse('/schedules/1'), AppRoute.pipelines);
|
||||
});
|
||||
|
||||
test('retapping Chats reopens only a retained workspace from its list', () {
|
||||
final workspace = AppRoute.chatSession('active');
|
||||
expect(chatRouteForRetap(AppRoute.chat, workspace), workspace);
|
||||
expect(
|
||||
chatRouteForRetap(
|
||||
AppRoute.chat,
|
||||
workspace,
|
||||
isValidSession: (id) => id == 'active',
|
||||
),
|
||||
workspace,
|
||||
);
|
||||
expect(
|
||||
chatRouteForRetap(
|
||||
AppRoute.chat,
|
||||
workspace,
|
||||
isValidSession: (id) => id == 'other',
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(chatRouteForRetap(AppRoute.chat, null), isNull);
|
||||
expect(chatRouteForRetap(AppRoute.chat, AppRoute.chat), isNull);
|
||||
});
|
||||
|
||||
test('retapping Chats while a chat is open does not return to the list', () {
|
||||
final current = AppRoute.chatSession('active');
|
||||
expect(chatRouteForRetap(current, AppRoute.chatSession('older')), current);
|
||||
expect(chatRouteForRetap(AppRoute.pipelines, current), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ import 'dart:convert';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
@@ -154,6 +157,46 @@ Future<void> replyHistory(
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> replyChatSessions(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
List<String> ids, {
|
||||
int index = 0,
|
||||
}) async {
|
||||
final request = await waitForRequest(
|
||||
tester,
|
||||
channel,
|
||||
'chat_sessions',
|
||||
index: index,
|
||||
);
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': request['id'],
|
||||
'type': 'chat_sessions',
|
||||
'chat_sessions': [
|
||||
for (final id in ids) {'id': id, 'title': 'Chat $id'},
|
||||
],
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> replyChatHistory(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel, {
|
||||
required int subscribeIndex,
|
||||
required int historyIndex,
|
||||
String? text,
|
||||
}) async {
|
||||
await replySubscribe(tester, channel, index: subscribeIndex);
|
||||
await replyHistory(
|
||||
tester,
|
||||
channel,
|
||||
index: historyIndex,
|
||||
text: text ?? 'History for chat ${subscribeIndex + 1}',
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
@@ -272,4 +315,263 @@ void main() {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'mobile Chats retap reopens the retained multi-pane workspace after tabs',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
server: webServer(),
|
||||
client: client,
|
||||
cupertino: false,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a', 'b']);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-a')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
'Draft retained in pane a',
|
||||
);
|
||||
|
||||
final addPane = find.byTooltip('Add chat pane').hitTestable();
|
||||
if (addPane.evaluate().isEmpty) {
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Add chat pane'));
|
||||
} else {
|
||||
await tester.tap(addPane);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat b').last);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 1,
|
||||
historyIndex: 1,
|
||||
text: List.generate(80, (i) => 'History line $i').join('\n\n'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
'Draft retained in pane b',
|
||||
);
|
||||
|
||||
expect(
|
||||
tester
|
||||
.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
)
|
||||
.controller
|
||||
.text,
|
||||
'Draft retained in pane b',
|
||||
);
|
||||
|
||||
final workspace = tester.widget<ChatWorkspace>(
|
||||
find.byType(ChatWorkspace),
|
||||
);
|
||||
expect(workspace.controller.paneCount, 2);
|
||||
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||
expect(provider.value.uri.path, '/chat/b');
|
||||
final paneOrder = workspace.controller.panes
|
||||
.map((p) => p.sessionId)
|
||||
.toList();
|
||||
await tester.drag(
|
||||
find.byType(ChatMobilePeekDivider),
|
||||
const Offset(0, 60),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final peekFraction = workspace.controller.mobilePeekFraction;
|
||||
expect(peekFraction, lessThan(.2));
|
||||
await tester.tap(find.bySemanticsLabel('Expand Chat a'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.controller.activePane?.sessionId, 'a');
|
||||
expect(workspace.controller.panes.map((p) => p.sessionId), paneOrder);
|
||||
await tester.tap(find.bySemanticsLabel('Expand Chat b'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||
final transcript = find.byKey(const ValueKey('chat-thread-b'));
|
||||
ScrollPosition historyPosition() => tester
|
||||
.state<ScrollableState>(
|
||||
find
|
||||
.descendant(of: transcript, matching: find.byType(Scrollable))
|
||||
.first,
|
||||
)
|
||||
.position;
|
||||
final atEnd = historyPosition().pixels;
|
||||
await tester.drag(transcript, const Offset(0, 250));
|
||||
await tester.pumpAndSettle();
|
||||
final historyOffset = historyPosition().pixels;
|
||||
expect(historyOffset, isNot(closeTo(atEnd, 1)));
|
||||
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
|
||||
// The selected Chats destination is already showing its list: the
|
||||
// second tap reuses the mounted workspace instead of opening a new one.
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/b');
|
||||
final restored = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
|
||||
expect(restored.controller, same(workspace.controller));
|
||||
expect(restored.controller.paneCount, 2);
|
||||
expect(restored.controller.activePane?.sessionId, 'b');
|
||||
expect(restored.controller.panes.map((p) => p.sessionId), paneOrder);
|
||||
expect(restored.controller.mobilePeekFraction, peekFraction);
|
||||
expect(historyPosition().pixels, closeTo(historyOffset, 1));
|
||||
expect(find.byType(ChatThreadView), findsNWidgets(2));
|
||||
expect(
|
||||
tester
|
||||
.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
)
|
||||
.controller
|
||||
.text,
|
||||
'Draft retained in pane b',
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(
|
||||
const ValueKey('chat-composer-a'),
|
||||
skipOffstage: false,
|
||||
),
|
||||
matching: find.byType(EditableText, skipOffstage: false),
|
||||
skipOffstage: false,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(
|
||||
const ValueKey('chat-composer-a'),
|
||||
skipOffstage: false,
|
||||
),
|
||||
matching: find.byType(EditableText, skipOffstage: false),
|
||||
skipOffstage: false,
|
||||
),
|
||||
)
|
||||
.controller
|
||||
.text,
|
||||
'Draft retained in pane a',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
testWidgets(
|
||||
'mobile Chats retap stays on list with no history or a removed chat',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
server: webServer(),
|
||||
client: client,
|
||||
cupertino: false,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await tester.pumpAndSettle();
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
// The cached transcript renders immediately, but answer the restored
|
||||
// thread's network read before refreshing the serialized session list.
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 1,
|
||||
historyIndex: 1,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')).hitTestable());
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, [], index: 1);
|
||||
await tester.pumpAndSettle();
|
||||
for (var attempt = 0; attempt < 2; attempt++) {
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user