App: open a chat, the terminal or a diff in a new window
"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>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
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');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:pipelines_app/application/detached/detached_platform.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
|
||||
/// A platform that records what it was asked to open and send.
|
||||
class FakeDetachedPlatform extends DetachedPlatform {
|
||||
DetachedLaunch result = DetachedLaunch.opened;
|
||||
final launches = <({DetachedRoute route, String title, bool tab})>[];
|
||||
final stored = <String, String>{};
|
||||
final sent = <DetachedMessage>[];
|
||||
bool mainOpen = true;
|
||||
bool closed = false;
|
||||
String? becameMain;
|
||||
final incoming = StreamController<DetachedMessage>.broadcast();
|
||||
|
||||
@override
|
||||
bool get supported => true;
|
||||
|
||||
@override
|
||||
Future<DetachedLaunch> launch(
|
||||
DetachedRoute route, {
|
||||
required String title,
|
||||
required Size size,
|
||||
bool tab = false,
|
||||
}) async {
|
||||
launches.add((route: route, title: title, tab: tab));
|
||||
return tab ? DetachedLaunch.opened : result;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<DetachedMessage> get messages => incoming.stream;
|
||||
|
||||
@override
|
||||
Future<void> put(String token, String json) async => stored[token] = json;
|
||||
|
||||
@override
|
||||
Future<String?> take(String token) async => stored[token];
|
||||
|
||||
@override
|
||||
Future<bool> sendToMain(DetachedMessage message) async {
|
||||
if (!mainOpen) return false;
|
||||
sent.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> closeSelf() async => closed = true;
|
||||
|
||||
@override
|
||||
Future<bool> becomeMain(String appPath) async {
|
||||
becameMain = appPath;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// An opener that records the items and opens them at once.
|
||||
class FakeOpener implements DetachedWindowOpener {
|
||||
final chats = <String>[];
|
||||
final terminals = <String>[];
|
||||
final diffs = <List<Map<String, Object?>>>[];
|
||||
bool opens = true;
|
||||
|
||||
@override
|
||||
void openChat(
|
||||
String sessionId, {
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
chats.add(sessionId);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void openTerminal({
|
||||
String tabKey = '',
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
terminals.add(tabKey);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void openDiff(
|
||||
List<Map<String, Object?>> files, {
|
||||
int initialIndex = 0,
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
diffs.add(files);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
}
|
||||
|
||||
/// Answers a chat app's requests over [channel] like a server with chats
|
||||
/// a, b and c, recording each request (type and body).
|
||||
class ChatServer {
|
||||
ChatServer(this.channel, {List<Object?> openChats = const []})
|
||||
: _entries = openChats;
|
||||
|
||||
final FakeChannel channel;
|
||||
final _answered = <Object?>{};
|
||||
final requests = <Map<String, dynamic>>[];
|
||||
List<Object?> _entries;
|
||||
int _revision = 1;
|
||||
|
||||
/// The open-chat writes the app sent (`chat_open_workspace_request`).
|
||||
List<Map<String, dynamic>> get workspaceWrites => [
|
||||
for (final request in requests)
|
||||
if (request['type'] == 'chat_open_workspace' &&
|
||||
request['chat_open_workspace_request'] != null)
|
||||
request,
|
||||
];
|
||||
|
||||
void answer() {
|
||||
for (final raw in channel.outgoing.toList()) {
|
||||
final m = jsonDecode(raw as String) as Map<String, dynamic>;
|
||||
final id = m['id'];
|
||||
if (id == null || !_answered.add(id)) continue;
|
||||
requests.add(m);
|
||||
channel.incoming.add(jsonEncode(_reply('${m['type']}', id, m)));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object?> _reply(String type, Object? id, Map<String, dynamic> m) {
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'chat_sessions': [
|
||||
for (final s in const ['a', 'b', 'c'])
|
||||
{
|
||||
'id': s,
|
||||
'title': 'Chat $s',
|
||||
'directory': '/workspace/demo',
|
||||
'updated_at': '2026-11-12T10:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_messages':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_history',
|
||||
'chat_history': {
|
||||
'messages': [
|
||||
{
|
||||
'id': 'm0',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Hello from chat'},
|
||||
],
|
||||
},
|
||||
],
|
||||
'next_cursor': '',
|
||||
'has_more': false,
|
||||
},
|
||||
};
|
||||
case 'chat_open_workspace':
|
||||
final write = m['chat_open_workspace_request'] as Map?;
|
||||
if (write != null) {
|
||||
_revision++;
|
||||
_entries = write['entries'] as List<Object?>;
|
||||
}
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'chat_open_workspace': {'revision': _revision, 'entries': _entries},
|
||||
};
|
||||
default:
|
||||
return {'id': id, 'type': type};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_windows.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.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/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() {
|
||||
Future<(ChatServer, FakeDetachedPlatform)> pump(
|
||||
WidgetTester tester, {
|
||||
String route = '/chat/a',
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(1600, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final platform = FakeDetachedPlatform();
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final server = ChatServer(
|
||||
channel,
|
||||
openChats: [
|
||||
{'session_id': 'a'},
|
||||
],
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse(route)),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
routeInformationProvider: provider,
|
||||
detachedPlatform: platform,
|
||||
),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 1200));
|
||||
return (server, platform);
|
||||
}
|
||||
|
||||
testWidgets('the main window offers new windows and sends the chat out of '
|
||||
'its workspace', (tester) async {
|
||||
final (server, platform) = await pump(tester);
|
||||
final thread = find.byType(ChatThreadView);
|
||||
expect(thread, findsOneWidget);
|
||||
expect(DetachedWindowScope.maybeOf(tester.element(thread)), isNotNull);
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(of: thread, matching: find.byTooltip('More actions'))
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Open in new window (Alt+Shift+Y)'));
|
||||
await _run(tester, server, const Duration(milliseconds: 600));
|
||||
expect(platform.launches.single.route, DetachedRoute.chat('a'));
|
||||
expect(platform.launches.single.title, 'Chat a');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
// The main window's own workspace is written without the chat.
|
||||
final write = server.workspaceWrites.last['chat_open_workspace_request'];
|
||||
expect((write as Map)['entries'], isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat brought back opens in the main window', (tester) async {
|
||||
final (server, platform) = await pump(tester, route: '/runs');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
platform.incoming.add(
|
||||
const DetachedReturn(DetachedKind.chat, 'b').toMessage(),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 900));
|
||||
final thread = tester.widget<ChatThreadView>(find.byType(ChatThreadView));
|
||||
expect(thread.sessionId, 'b');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
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';
|
||||
|
||||
void main() {
|
||||
test('each kind round-trips through its path', () {
|
||||
final routes = [
|
||||
DetachedRoute.chat('sess_01-A')!,
|
||||
DetachedRoute.terminal(),
|
||||
DetachedRoute.terminal('mac/term 1'),
|
||||
DetachedRoute.diff('Tok_en-9')!,
|
||||
];
|
||||
for (final route in routes) {
|
||||
expect(DetachedRoute.parse(route.path), route, reason: route.path);
|
||||
}
|
||||
expect(DetachedRoute.chat('a')!.path, '/window/chat/a');
|
||||
expect(DetachedRoute.terminal().path, '/window/terminal');
|
||||
expect(
|
||||
DetachedRoute.terminal('server/t1').path,
|
||||
'/window/terminal?tab=server%2Ft1',
|
||||
);
|
||||
expect(DetachedRoute.diff('abc')!.path, '/window/diff/abc');
|
||||
});
|
||||
|
||||
test('a full URL with an origin and fixture parameters parses', () {
|
||||
final route = DetachedRoute.parse(
|
||||
'https://tank.example.ts.net/window/chat/perf-chat-0?chats=2&theme=dark',
|
||||
);
|
||||
expect(route, DetachedRoute.chat('perf-chat-0'));
|
||||
expect(
|
||||
DetachedRoute.parse('http://x/window/terminal?tab=s%2F7&theme=dark'),
|
||||
DetachedRoute.terminal('s/7'),
|
||||
);
|
||||
});
|
||||
|
||||
test('ordinary app locations and malformed windows are not detached', () {
|
||||
for (final location in [
|
||||
'/',
|
||||
'/chat/a',
|
||||
'/runs/7',
|
||||
'/window',
|
||||
'/window/chat',
|
||||
'/window/chat/a/b',
|
||||
'/window/chat/not%20valid',
|
||||
'/window/diff/has.dot',
|
||||
'/window/diff/${'x' * 65}',
|
||||
'/window/pipelines/3',
|
||||
'/windows/chat/a',
|
||||
'',
|
||||
]) {
|
||||
expect(DetachedRoute.parse(location), isNull, reason: location);
|
||||
}
|
||||
expect(DetachedRoute.chat('no spaces'), isNull);
|
||||
expect(DetachedRoute.diff(''), isNull);
|
||||
expect(DetachedRoute.terminal('k' * 600).id, isEmpty);
|
||||
});
|
||||
|
||||
test('a native launch names its window by argument or environment', () {
|
||||
final chat = DetachedRoute.chat('a');
|
||||
expect(DetachedRoute.fromLaunch(['--detached', '/window/chat/a']), chat);
|
||||
expect(DetachedRoute.fromLaunch(['--detached=/window/chat/a']), chat);
|
||||
expect(
|
||||
DetachedRoute.fromLaunch(const [], {
|
||||
'PIPELINES_DETACHED': '/window/terminal',
|
||||
}),
|
||||
DetachedRoute.terminal(),
|
||||
);
|
||||
expect(DetachedRoute.fromLaunch(const []), isNull);
|
||||
expect(
|
||||
DetachedRoute.fromLaunch(const [], {'PIPELINES_DETACHED': ''}),
|
||||
isNull,
|
||||
);
|
||||
expect(DetachedRoute.fromLaunch(['--detached']), isNull);
|
||||
});
|
||||
|
||||
test('messages carry a marker; anything else is ignored', () {
|
||||
final text = encodeDetachedMessage({'type': 'bring-back', 'id': 'a'});
|
||||
expect(decodeDetachedMessage(text), {'type': 'bring-back', 'id': 'a'});
|
||||
expect(decodeDetachedMessage('{"type":"bring-back"}'), isNull);
|
||||
expect(decodeDetachedMessage('not json'), isNull);
|
||||
expect(decodeDetachedMessage('[1]'), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
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');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_diff.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_window_body.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
|
||||
FileChange _file(String path) => FileChange(
|
||||
path: path,
|
||||
kind: ChangeKind.modified,
|
||||
patch: '--- a/$path\n+++ b/$path\n@@ -0,0 +1,1 @@\n+line of $path\n',
|
||||
beforeMode: '100644',
|
||||
afterMode: '100755',
|
||||
).withSteps(const ['build']);
|
||||
|
||||
void main() {
|
||||
setUp(() => diffShowsAllFiles.value = false);
|
||||
|
||||
test('a file change survives the hand-over to another window', () {
|
||||
final file = _file('lib/a.dart');
|
||||
final back = FileChange.fromHandover(
|
||||
jsonDecode(jsonEncode(file.toJson())),
|
||||
)!;
|
||||
expect(back.path, file.path);
|
||||
expect(back.kind, file.kind);
|
||||
expect(back.patch, file.patch);
|
||||
expect(back.beforeMode, '100644');
|
||||
expect(back.afterMode, '100755');
|
||||
expect(back.steps, ['build']);
|
||||
expect(back.added, 1);
|
||||
});
|
||||
|
||||
testWidgets('a diff page offers Open in new window and closes once open', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final opener = FakeOpener();
|
||||
final files = [_file('lib/a.dart'), _file('lib/b.dart')];
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowScope(
|
||||
opener: opener,
|
||||
child: MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () =>
|
||||
showFileDiffViewer(context, files[1], files: files),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileDiffPage), findsOneWidget);
|
||||
await tester.tap(find.byTooltip('Open in new window'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opener.diffs.single.map((f) => f['path']), [
|
||||
'lib/a.dart',
|
||||
'lib/b.dart',
|
||||
]);
|
||||
expect(find.byType(FileDiffPage), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the diff page has no such button', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: FileDiffPage(files: [_file('a')])),
|
||||
);
|
||||
expect(find.byTooltip('Open in new window'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a detached diff shows the handed files and gives them back', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 820);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final platform = FakeDetachedPlatform();
|
||||
platform.stored['tok'] = jsonEncode({
|
||||
'files': [_file('lib/a.dart').toJson(), _file('lib/b.dart').toJson()],
|
||||
'index': 1,
|
||||
});
|
||||
final titles = <String>[];
|
||||
final back = <(DetachedKind, String, int, int)>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedDiff(
|
||||
token: 'tok',
|
||||
platform: platform,
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: titles.add,
|
||||
close: () {},
|
||||
bringBackItem: (kind, id, files, index) =>
|
||||
back.add((kind, id, files.length, index)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileDiffPage), findsOneWidget);
|
||||
expect(titles.last, '2 files changed');
|
||||
expect(find.text('b.dart'), findsWidgets);
|
||||
// No Back in a window of its own, and no window to open from it.
|
||||
expect(find.byType(BackButton), findsNothing);
|
||||
expect(find.byTooltip('Open in new window'), findsNothing);
|
||||
await tester.tap(find.byTooltip('Bring back to main window'));
|
||||
expect(back, [(DetachedKind.diff, 'tok', 2, 1)]);
|
||||
});
|
||||
|
||||
testWidgets('a diff handed over to nobody says it is gone', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedDiff(
|
||||
token: 'missing',
|
||||
platform: FakeDetachedPlatform(),
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: (_) {},
|
||||
close: () {},
|
||||
bringBackItem: (_, _, _, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('This diff is no longer available.'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/servers/server_scope.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_frame.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_host.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final id in ['a', 'b', 'c'])
|
||||
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
const _label = 'Open in new window (Alt+Shift+Y)';
|
||||
|
||||
Finder _thread(String id) => find.byWidgetPredicate(
|
||||
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||
skipOffstage: false,
|
||||
);
|
||||
|
||||
List<String> _tiled(WidgetTester tester) => [
|
||||
for (final pane
|
||||
in tester
|
||||
.widget<ChatWorkspace>(
|
||||
find.byType(ChatWorkspace, skipOffstage: false),
|
||||
)
|
||||
.controller
|
||||
.panes)
|
||||
pane.sessionId,
|
||||
];
|
||||
|
||||
/// The Chat destination with its floating windows, as the app hosts them,
|
||||
/// with [opener] as the platform's new windows (none when null).
|
||||
class _App {
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
final opener = FakeOpener();
|
||||
late final ChatRuntime runtime;
|
||||
late final WindowManager manager;
|
||||
late final ChatWindows windows;
|
||||
|
||||
Future<void> start(WidgetTester tester, {bool detached = true}) async {
|
||||
tester.view.physicalSize = const Size(1800, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final layout = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
SharedPreferences.setMockInitialValues({
|
||||
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
|
||||
.snapshot()!
|
||||
.encode(),
|
||||
});
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
|
||||
manager = WindowManager(kinds: WindowKinds(), server: 'server-a');
|
||||
windows = ChatWindows(
|
||||
manager: manager,
|
||||
runtime: runtime,
|
||||
openInChat: (_) {},
|
||||
)..start();
|
||||
if (detached) windows.detached = opener;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
ChatScreen(
|
||||
gateway: gateway,
|
||||
persistWorkspace: true,
|
||||
runtime: runtime,
|
||||
windows: windows,
|
||||
),
|
||||
Positioned.fill(child: WindowHost(manager: manager)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
addTearDown(() async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
windows.dispose();
|
||||
runtime.dispose();
|
||||
manager.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
}
|
||||
|
||||
List<String> get floating => [for (final w in windows.windows) w.contentId];
|
||||
}
|
||||
|
||||
Future<void> _paneMenu(WidgetTester tester, String session) async {
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
of: _thread(session),
|
||||
matching: find.byTooltip('More actions'),
|
||||
)
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _rowMenu(WidgetTester tester, String id) async {
|
||||
await tester.tap(find.byTooltip('Chat actions for Chat $id').first);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('the pane menu sends a tiled chat to a new window', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
await _paneMenu(tester, 'b');
|
||||
expect(find.text('Float (Alt+Y)'), findsOneWidget);
|
||||
await tester.tap(find.text(_label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
// It left the tiling, as Float takes it out, and no floating window.
|
||||
expect(_tiled(tester), ['a']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat whose window did not open stays where it was', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
app.opener.opens = false;
|
||||
await _paneMenu(tester, 'b');
|
||||
await tester.tap(find.text(_label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the action is not offered', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester, detached: false);
|
||||
await _paneMenu(tester, 'b');
|
||||
expect(find.text('Float (Alt+Y)'), findsOneWidget);
|
||||
expect(find.textContaining('new window'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 995));
|
||||
await tester.pumpAndSettle();
|
||||
await _rowMenu(tester, 'c');
|
||||
expect(find.textContaining('new window'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the row menu offers it after Float, for any chat', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _rowMenu(tester, 'c');
|
||||
final float = tester.getTopLeft(find.text('Float (Alt+Y)').last);
|
||||
final open = tester.getTopLeft(find.text(_label).last);
|
||||
expect(open.dy, greaterThan(float.dy));
|
||||
await tester.tap(find.text(_label).last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['c']);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
});
|
||||
|
||||
testWidgets('a floating chat goes to a new window from its title bar', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _rowMenu(tester, 'c');
|
||||
await tester.tap(find.text('Float (Alt+Y)').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.floating, ['c']);
|
||||
final window = find.ancestor(
|
||||
of: find.text('Chat c'),
|
||||
matching: find.byType(WindowFrame),
|
||||
);
|
||||
await tester.tap(
|
||||
find.descendant(of: window, matching: find.byTooltip(_label)).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['c']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('Alt+Shift+Y sends the active pane; Alt+Y still floats', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
// The keyboard is in chat b's composer, the active pane.
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-b')),
|
||||
matching: find.byType(EditableText),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
expect(_tiled(tester), ['a']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat brought back from its window joins the tiling', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
app.windows.bringBack('c');
|
||||
await tester.pumpAndSettle();
|
||||
expect(_tiled(tester), ['a', 'b', 'c']);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_terminals.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_terminal.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_window_body.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_tab_strip.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
import 'terminal_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('the options menu sends the terminal to a new window', (
|
||||
tester,
|
||||
) async {
|
||||
final mac = TerminalGateway()..add('t1', text: 'hello\r\n');
|
||||
addTearDown(mac.close);
|
||||
final hub = TerminalHub(TestMachines([machine('mac', mac)]))..activate();
|
||||
addTearDown(hub.dispose);
|
||||
await tester.runAsync(hub.listed);
|
||||
final layout = TerminalLayout(store: MemoryLayoutStore())..show();
|
||||
final opener = FakeOpener();
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowScope(
|
||||
opener: opener,
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TerminalTabStrip(hub: hub, layout: layout),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('terminal-new-window')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opener.terminals, ['mac/t1']);
|
||||
expect(layout.visible, isFalse, reason: 'it leaves the main window');
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the menu has no such choice', (
|
||||
tester,
|
||||
) async {
|
||||
final hub = TerminalHub(TestMachines([]));
|
||||
addTearDown(hub.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TerminalTabStrip(
|
||||
hub: hub,
|
||||
layout: TerminalLayout(store: MemoryLayoutStore()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('terminal-new-window')), findsNothing);
|
||||
expect(find.text('Floating window'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('a layout that does not persist never saves', () async {
|
||||
final store = MemoryLayoutStore();
|
||||
final layout = TerminalLayout(store: store)..persist = false;
|
||||
layout
|
||||
..setFontSize(18)
|
||||
..show();
|
||||
await layout.save();
|
||||
expect(store.saves, 0);
|
||||
expect(layout.fontSize, 18, reason: 'the window still follows it');
|
||||
});
|
||||
|
||||
testWidgets('a detached terminal opens on its tab, without modes, and '
|
||||
'gives it back', (tester) async {
|
||||
final mac = TerminalGateway()
|
||||
..add('t1', text: 'one\r\n')
|
||||
..add('t2', text: 'two\r\n');
|
||||
addTearDown(mac.close);
|
||||
final connection = ValueNotifier(0);
|
||||
final terminals = AppTerminals(
|
||||
pool: null,
|
||||
connection: connection,
|
||||
connected: () => true,
|
||||
gateway: mac,
|
||||
machineId: 'mac',
|
||||
machineName: () => 'Mac',
|
||||
layout: TerminalLayout(store: MemoryLayoutStore()),
|
||||
);
|
||||
addTearDown(terminals.dispose);
|
||||
final back = <(DetachedKind, String)>[];
|
||||
final titles = <String>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedTerminal(
|
||||
terminals: terminals,
|
||||
tabKey: 'mac/t2',
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: titles.add,
|
||||
close: () {},
|
||||
bringBackItem: (kind, id, _, _) => back.add((kind, id)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.runAsync(terminals.hub.listed);
|
||||
await tester.pump();
|
||||
expect(terminals.hub.selected?.key, 'mac/t2');
|
||||
expect(titles.last, startsWith('Terminal'));
|
||||
// There is no panel or floating mode to choose in a window of its own.
|
||||
expect(find.byTooltip('Terminal options'), findsNothing);
|
||||
await tester.tap(find.byTooltip('Bring back to main window'));
|
||||
expect(back, [(DetachedKind.terminal, 'mac/t2')]);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_shortcut.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Alt+Shift+Y is the new-window chord, never Float', (
|
||||
tester,
|
||||
) async {
|
||||
final seen = <(bool detach, bool float)>[];
|
||||
bool handler(KeyEvent event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.keyY) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
seen.add((
|
||||
detachedWindowShortcut(event, keyboard),
|
||||
chatFloatShortcut(event, keyboard),
|
||||
));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
HardwareKeyboard.instance.addHandler(handler);
|
||||
addTearDown(() => HardwareKeyboard.instance.removeHandler(handler));
|
||||
|
||||
Future<void> chord(List<LogicalKeyboardKey> modifiers) async {
|
||||
for (final key in modifiers) {
|
||||
await tester.sendKeyDownEvent(key);
|
||||
}
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
for (final key in modifiers.reversed) {
|
||||
await tester.sendKeyUpEvent(key);
|
||||
}
|
||||
}
|
||||
|
||||
await chord([LogicalKeyboardKey.altLeft, LogicalKeyboardKey.shiftLeft]);
|
||||
await chord([LogicalKeyboardKey.altLeft]);
|
||||
await chord([LogicalKeyboardKey.shiftLeft]);
|
||||
await chord([
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.altLeft,
|
||||
LogicalKeyboardKey.shiftLeft,
|
||||
]);
|
||||
expect(seen, [
|
||||
(true, false),
|
||||
(false, true),
|
||||
(false, false),
|
||||
(false, false),
|
||||
]);
|
||||
});
|
||||
|
||||
test('the shortcut help lists it where windows exist', () {
|
||||
String? keysOn(TargetPlatform platform, {bool web = false}) =>
|
||||
KeyboardShortcutRegistry(platform: platform, web: web).entries
|
||||
.where((e) => e.action == 'Open the chat in a new window')
|
||||
.map((e) => e.keys)
|
||||
.firstOrNull;
|
||||
expect(keysOn(TargetPlatform.linux), 'Alt+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.macOS), 'Option+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.windows, web: true), 'Alt+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.android), isNull);
|
||||
expect(keysOn(TargetPlatform.iOS), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user