Open selected chats from search
Re-apply explicit chat routes after workspace restoration and repeated route notifications so search results and chat notifications open the requested session. Add regression coverage for route, registration, and workspace restore behavior.
This commit is contained in:
@@ -50,6 +50,17 @@ void main() {
|
||||
expect(router.route, AppRoute.settings);
|
||||
},
|
||||
);
|
||||
test('repeated chat deep links notify the mounted destination', () {
|
||||
final router = delegate(AppRoute.chatSession('target'));
|
||||
addTearDown(router.dispose);
|
||||
var notifications = 0;
|
||||
router.addListener(() => notifications++);
|
||||
|
||||
router.goTo(AppRoute.chatSession('target'));
|
||||
|
||||
expect(notifications, 1);
|
||||
expect(router.route, AppRoute.chatSession('target'));
|
||||
});
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('with nothing pushed the router leaves Back to the platform', () async {
|
||||
for (final route in [
|
||||
|
||||
@@ -381,6 +381,75 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'a mounted chat notification route activates a different chat',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(900, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/old')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: client,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await replyChatSessions(tester, channel, ['old', 'target']);
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
text: 'The retained chat.',
|
||||
);
|
||||
expect(find.text('The retained chat.'), findsOneWidget);
|
||||
|
||||
// This is the route delivered by a native chat notification, not a
|
||||
// direct ChatScreen replacement.
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/chat/target')),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/chat/target');
|
||||
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 1,
|
||||
historyIndex: 1,
|
||||
text: 'The notified chat.',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(requestOf(channel, 'chat_subscribe', index: 1)!['chat_subscribe'], {
|
||||
'session_id': 'target',
|
||||
});
|
||||
expect(requestOf(channel, 'chat_messages', index: 1)!['chat_query'], {
|
||||
'session_id': 'target',
|
||||
'limit': 200,
|
||||
'cursor': '',
|
||||
});
|
||||
expect(find.text('The notified chat.'), findsOneWidget);
|
||||
expect(find.text('The retained chat.'), findsNothing);
|
||||
expect(provider.value.uri.path, '/chat/target');
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'mobile Chats retap reopens the retained multi-pane workspace after tabs',
|
||||
(tester) async {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/search/search_screen.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
@@ -98,6 +99,14 @@ void main() {
|
||||
expect(find.byType(SearchScreen), findsNothing);
|
||||
final screen = tester.widget<ChatScreen>(find.byType(ChatScreen));
|
||||
expect(screen.initialSessionId, _session);
|
||||
expect(
|
||||
tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||
.controller
|
||||
.activePane
|
||||
?.sessionId,
|
||||
_session,
|
||||
);
|
||||
|
||||
await reply(
|
||||
tester,
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../native_back.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
|
||||
show segmentedMoreKey;
|
||||
|
||||
@@ -188,4 +189,79 @@ void main() {
|
||||
expect(gateway.count('chat_models'), 0);
|
||||
},
|
||||
);
|
||||
|
||||
for (final width in [390.0, 1200.0]) {
|
||||
testWidgets(
|
||||
'a new route opens the target after Chat is already mounted on $width px',
|
||||
(tester) async {
|
||||
final gateway = _ScreenGateway()
|
||||
..sessions = [
|
||||
{'id': 'old', 'title': 'Old chat'},
|
||||
{'id': 'target', 'title': 'Target chat'},
|
||||
];
|
||||
tester.view.physicalSize = Size(width, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(gateway: gateway, initialSessionId: 'old'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(gateway: gateway, initialSessionId: 'target'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final workspace = tester.widget<ChatWorkspace>(
|
||||
find.byType(ChatWorkspace),
|
||||
);
|
||||
expect(workspace.controller.activePane?.sessionId, 'target');
|
||||
expect(
|
||||
find.byKey(const ValueKey('chat-session-target')),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'a repeated route reactivates its chat after another pane became active',
|
||||
(tester) async {
|
||||
final gateway = _ScreenGateway()
|
||||
..sessions = [
|
||||
{'id': 'a', 'title': 'Chat a'},
|
||||
{'id': 'b', 'title': 'Chat b'},
|
||||
];
|
||||
await _pumpScreen(tester, gateway, initialSessionId: 'a');
|
||||
final workspace = tester.widget<ChatWorkspace>(
|
||||
find.byType(ChatWorkspace),
|
||||
);
|
||||
workspace.controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final b = workspace.controller.panes.firstWhere(
|
||||
(pane) => pane.sessionId == 'b',
|
||||
);
|
||||
workspace.controller.activate(b.id);
|
||||
await tester.pump();
|
||||
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(gateway: gateway, initialSessionId: 'a'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(workspace.controller.activePane?.sessionId, 'a');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -179,4 +179,32 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('repeated deep link reactivates the routed pane after restore', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1800, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final saved = ChatWorkspaceController()..open('a');
|
||||
saved.splitActive('b', ChatSplitAxis.vertical);
|
||||
SharedPreferences.setMockInitialValues({
|
||||
chatWorkspacePreferenceKey: saved.snapshot()!.encode(),
|
||||
});
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await _mount(tester, gateway, route: 'a');
|
||||
final controller = _workspace(tester);
|
||||
final other = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
|
||||
controller.activate(other.id);
|
||||
await tester.pump();
|
||||
expect(controller.activePane?.sessionId, 'b');
|
||||
|
||||
await _mount(tester, gateway, route: 'a');
|
||||
expect(_workspace(tester).activePane?.sessionId, 'a');
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user