Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

test(ui): use each platform's keys in quick paste tests

baiyuzed3ab73cef420
diff --git a/ui/test/i18n_test.dart b/ui/test/i18n_test.dart
index f795a1e..c0ff622 100644
--- a/ui/test/i18n_test.dart
+++ b/ui/test/i18n_test.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+
import 'package:fixnum/fixnum.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -187,7 +189,10 @@ void main() {
await tester.tap(find.text(l.navSettings).first);
await tester.pump();
await tester.dragUntilVisible(find.text(l.language), find.byType(ListView), const Offset(0, -100));
- await tester.dragUntilVisible(find.text(l.quickPasteAccessibility), find.byType(ListView), const Offset(0, -100));
+ // 辅助功能授权只有 Mac 上有
+ if (Platform.isMacOS) {
+ await tester.dragUntilVisible(find.text(l.quickPasteAccessibility), find.byType(ListView), const Offset(0, -100));
+ }
await tester.dragUntilVisible(find.text(l.favoritesUsage), find.byType(ListView), const Offset(0, -100));
await tester.dragUntilVisible(find.text(l.about), find.byType(ListView), const Offset(0, -200));
});
diff --git a/ui/test/picker_test.dart b/ui/test/picker_test.dart
index f4a8604..dae5dcb 100644
--- a/ui/test/picker_test.dart
+++ b/ui/test/picker_test.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+
import 'package:fixnum/fixnum.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -10,6 +12,10 @@ import 'package:pasteferry_ui/picker/picker_view.dart';
const _channel = MethodChannel('pasteferry/picker');
+// 快捷窗口的按键跟着平台走:Mac 上是 ⌘,Windows 与 Linux 上是 Ctrl(序号是 Alt+数字)
+final _mac = Platform.isMacOS;
+final _cmdKey = _mac ? LogicalKeyboardKey.metaLeft : LogicalKeyboardKey.controlLeft;
+
/// 不连后台服务:放进剪贴板、下载、收藏都记下来。
class _TestPicker extends PickerState {
_TestPicker() : super(host: PickerHost(_channel));
@@ -128,7 +134,7 @@ void main() {
expect(s.applied, isEmpty);
await tester.enterText(find.byType(TextField), 'docker');
await tester.pump();
- expect(find.text('⌘1'), findsOneWidget);
+ expect(find.text(_mac ? '⌘1' : 'Alt+1'), findsOneWidget);
expect(find.textContaining('docker compose'), findsOneWidget);
expect(find.textContaining('会议'), findsNothing);
// 停顿后在当前页签里搜全部历史
@@ -154,9 +160,9 @@ void main() {
await tester.pump();
expect(s.applied.last, ('a', true));
- await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyDownEvent(_cmdKey);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
- await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyUpEvent(_cmdKey);
await tester.pump();
expect(commits().last.arguments, {'paste': false});
});
@@ -180,9 +186,9 @@ void main() {
expect(find.textContaining('收货地址'), findsOneWidget);
expect(find.textContaining('取消收藏(放回复制记录)'), findsOneWidget);
- await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyDownEvent(_cmdKey);
await tester.sendKeyEvent(LogicalKeyboardKey.keyD);
- await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyUpEvent(_cmdKey);
await tester.pump();
expect(s.favorited, [('f1', false)]);
});
@@ -202,7 +208,7 @@ void main() {
testWidgets('设置里选了只复制:选中后不模拟粘贴,底栏写明要按 ⌘V', (tester) async {
final s = await open(tester, config: Config(language: 'zh-Hans', quickPasteCopyOnly: true));
- expect(find.text('选中后按 ⌘V 粘贴'), findsOneWidget);
+ expect(find.text('选中后按 ${_mac ? '⌘V' : 'Ctrl+V'} 粘贴'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.digit1);
await tester.pump();
expect(s.applied.single.$1, 'a');