61c7eee2b0
"Open in new window" sits beside Float: the chat pane and chat list row menus, a floating chat window's title bar, the terminal options menu and the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in the shortcut help). Once the window opens the item leaves the main window as Float takes a pane out of the tiling. The window is its own app instance at /window/chat/<id>, /window/terminal?tab=<key> or /window/diff/<token>: only that item, named after it, with "Bring back to main window". It has its own connection and writes no shared layout (no open-chat workspace, window store or terminal layout) and posts no notifications, so they stay the main window's. Web opens a popup window (a blocked popup offers a tab); Linux and macOS start a second process with --detached (Flutter's multi-window API is still experimental); Android and iOS hide the action. The capture kit gains a follow step for windows a page opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.0 KiB
Dart
107 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/application/detached/detached_app.dart';
|
|
import 'package:pipelines_app/application/detached/detached_route.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/terminal/terminal_layout.dart';
|
|
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
|
import '../chat_registration_test.dart' show webServer;
|
|
import 'detached_fixtures.dart';
|
|
|
|
Future<void> _run(WidgetTester tester, ChatServer server, Duration d) async {
|
|
for (var t = 0; t < d.inMilliseconds; t += 16) {
|
|
server.answer();
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
server.answer();
|
|
}
|
|
|
|
void main() {
|
|
late FakeDetachedPlatform platform;
|
|
late ChatServer server;
|
|
|
|
Future<void> pumpChat(WidgetTester tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
tester.view.physicalSize = const Size(720, 860);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
addTearDown(() => TerminalLayout.instance.persist = true);
|
|
platform = FakeDetachedPlatform();
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
server = ChatServer(channel);
|
|
await tester.pumpWidget(
|
|
DetachedWindowApp(
|
|
route: DetachedRoute.chat('a')!,
|
|
server: webServer(),
|
|
client: PipelinesClient(channelFactory: (_) => channel),
|
|
platform: platform,
|
|
),
|
|
);
|
|
await _run(tester, server, const Duration(milliseconds: 900));
|
|
}
|
|
|
|
testWidgets('a detached chat is the chat pane alone, named after it', (
|
|
tester,
|
|
) async {
|
|
await pumpChat(tester);
|
|
expect(find.byType(ChatThreadView), findsOneWidget);
|
|
expect(find.text('Hello from chat'), findsOneWidget);
|
|
// No shell: no navigation, no chat list, no other chat.
|
|
expect(find.byType(NavigationRail), findsNothing);
|
|
expect(find.byType(NavigationBar), findsNothing);
|
|
expect(find.text('Chat b'), findsNothing);
|
|
final app = tester.widget<MaterialApp>(find.byType(MaterialApp));
|
|
expect(app.title, 'Chat a · Pipelines');
|
|
// Inside a detached window there is nothing to send to another one.
|
|
final context = tester.element(find.byType(ChatThreadView));
|
|
expect(DetachedWindowScope.maybeOf(context), isNull);
|
|
});
|
|
|
|
testWidgets('a detached window writes no shared layout', (tester) async {
|
|
await pumpChat(tester);
|
|
expect(server.workspaceWrites, isEmpty);
|
|
expect(
|
|
server.requests.where((r) => r['type'] == 'chat_open_workspace'),
|
|
isEmpty,
|
|
reason: 'the open-chat workspace is the main window\'s',
|
|
);
|
|
expect(TerminalLayout.instance.persist, isFalse);
|
|
final prefs = await SharedPreferences.getInstance();
|
|
expect(prefs.getKeys().where((k) => k.contains('window')), isEmpty);
|
|
expect(prefs.getString(terminalLayoutKey), isNull);
|
|
});
|
|
|
|
testWidgets('Bring back hands the chat to the main window and closes', (
|
|
tester,
|
|
) async {
|
|
await pumpChat(tester);
|
|
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Bring back to main window'));
|
|
await tester.pumpAndSettle();
|
|
expect(platform.sent.single, {
|
|
'type': 'bring-back',
|
|
'kind': 'chat',
|
|
'id': 'a',
|
|
});
|
|
expect(platform.closed, isTrue);
|
|
});
|
|
|
|
testWidgets('with no main window, Bring back opens the full app here', (
|
|
tester,
|
|
) async {
|
|
await pumpChat(tester);
|
|
platform.mainOpen = false;
|
|
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Bring back to main window'));
|
|
await tester.pumpAndSettle();
|
|
expect(platform.sent, isEmpty);
|
|
expect(platform.becameMain, '/chat/a');
|
|
});
|
|
}
|