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>
120 lines
3.6 KiB
Dart
120 lines
3.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/application/detached/detached_platform.dart';
|
|
import 'package:pipelines_app/application/detached/detached_route.dart';
|
|
import 'package:pipelines_app/application/detached/detached_windows.dart';
|
|
|
|
import 'detached_fixtures.dart';
|
|
|
|
void main() {
|
|
late FakeDetachedPlatform platform;
|
|
late List<DetachedReturn> returned;
|
|
late GlobalKey<ScaffoldMessengerState> messenger;
|
|
late DetachedWindows windows;
|
|
|
|
setUp(() {
|
|
platform = FakeDetachedPlatform();
|
|
returned = [];
|
|
messenger = GlobalKey<ScaffoldMessengerState>();
|
|
windows = DetachedWindows(
|
|
platform: platform,
|
|
onReturn: returned.add,
|
|
messenger: messenger,
|
|
)..start();
|
|
});
|
|
tearDown(() => windows.dispose());
|
|
|
|
Future<void> host(WidgetTester tester) => tester.pumpWidget(
|
|
MaterialApp(
|
|
scaffoldMessengerKey: messenger,
|
|
home: const Scaffold(body: SizedBox()),
|
|
),
|
|
);
|
|
|
|
testWidgets('an opened window runs onOpened; the item leaves after', (
|
|
tester,
|
|
) async {
|
|
await host(tester);
|
|
var opened = 0;
|
|
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
|
await tester.pump();
|
|
expect(platform.launches.single.route, DetachedRoute.chat('a'));
|
|
expect(platform.launches.single.title, 'Chat a');
|
|
expect(opened, 1);
|
|
|
|
windows.openTerminal(tabKey: 's/1', title: 'Terminal: zsh');
|
|
await tester.pump();
|
|
expect(platform.launches.last.route, DetachedRoute.terminal('s/1'));
|
|
});
|
|
|
|
testWidgets('a blocked popup says so and offers a tab, which opens it', (
|
|
tester,
|
|
) async {
|
|
await host(tester);
|
|
platform.result = DetachedLaunch.blocked;
|
|
var opened = 0;
|
|
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
|
await tester.pumpAndSettle();
|
|
expect(opened, 0, reason: 'nothing leaves the main window yet');
|
|
expect(find.textContaining('blocked the new window'), findsOneWidget);
|
|
await tester.tap(find.text('Open in tab'));
|
|
await tester.pumpAndSettle();
|
|
expect(platform.launches.last.tab, isTrue);
|
|
expect(opened, 1);
|
|
});
|
|
|
|
testWidgets('a failure is reported and the item stays', (tester) async {
|
|
await host(tester);
|
|
platform.result = DetachedLaunch.failed;
|
|
var opened = 0;
|
|
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Could not open a new window.'), findsOneWidget);
|
|
expect(opened, 0);
|
|
});
|
|
|
|
testWidgets('a diff is handed over under its token before it opens', (
|
|
tester,
|
|
) async {
|
|
await host(tester);
|
|
windows.openDiff(
|
|
[
|
|
{'path': 'lib/a.dart', 'kind': 'modified'},
|
|
],
|
|
initialIndex: 0,
|
|
title: 'a.dart',
|
|
);
|
|
await tester.pump();
|
|
final route = platform.launches.single.route;
|
|
expect(route.kind, DetachedKind.diff);
|
|
final stored = jsonDecode(platform.stored[route.id]!) as Map;
|
|
expect((stored['files'] as List).single['path'], 'lib/a.dart');
|
|
});
|
|
|
|
testWidgets('items a detached window gives back reach the main window', (
|
|
tester,
|
|
) async {
|
|
await host(tester);
|
|
const diff = DetachedReturn(
|
|
DetachedKind.diff,
|
|
'tok',
|
|
files: [
|
|
{'path': 'a', 'kind': 'added'},
|
|
],
|
|
initialIndex: 0,
|
|
);
|
|
platform.incoming
|
|
..add(const DetachedReturn(DetachedKind.chat, 'a').toMessage())
|
|
..add(diff.toMessage())
|
|
..add({'type': 'something else'});
|
|
await tester.pump();
|
|
expect(returned.map((r) => (r.kind, r.id)), [
|
|
(DetachedKind.chat, 'a'),
|
|
(DetachedKind.diff, 'tok'),
|
|
]);
|
|
expect(returned.last.files.single['path'], 'a');
|
|
});
|
|
}
|