feat: 真实连接链路、移除虚拟数据、全量打包脚本

This commit is contained in:
tongtong committed 2026-11-26 21:39:10 +08:00
1 parent 31b9a52eb4
commit 34340f4126
16 files changed
+601 -204

No files matched your search

+50 -16
View File
@@ -1,20 +1,34 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ttstd_sender/core/bridge.dart';
import 'package:ttstd_sender/core/models.dart';
import 'package:ttstd_sender/main.dart';
const MethodChannel _methodChannel = MethodChannel('ttstd/sender');
const EventChannel _eventChannel = EventChannel('ttstd/sender/events');
void _mockChannels() {
const Duration _settleTimeout = Duration(seconds: 5);
DeviceInfo _testDevice() => const DeviceInfo(
id: 'test-device-1',
name: '测试被控端',
ip: '10.0.0.2',
mediaPort: 41000,
controlPort: 41001,
fingerprint: 'test-fingerprint',
capabilities: ['h264'],
model: 'TestModel',
resolution: '1280x720',
);
void _mockChannels({List<DeviceInfo> devices = const [], String? pairingUri}) {
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
messenger.setMockMethodCallHandler(_methodChannel, (call) async {
switch (call.method) {
case 'discover':
return SenderBridge.mockDevices.map((device) => device.toJson()).toList();
return devices.map((device) => device.toJson()).toList();
case 'pairingUri':
return 'lancast://pair?ip=192.168.1.10&port=41001&fp=sha256:ab12cd34ef567890';
return pairingUri;
default:
return null;
}
@@ -32,47 +46,67 @@ void main() {
messenger.setMockStreamHandler(_eventChannel, null);
});
testWidgets('首页展示设备列表与连接工具栏', (tester) async {
testWidgets('首页无设备时显示空态', (tester) async {
_mockChannels();
await tester.pumpWidget(const TTSTDConnectApp());
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('TTSTD Connect'), findsOneWidget);
expect(find.text('客厅 Pixel'), findsOneWidget);
expect(find.text('可连接设备'), findsOneWidget);
});
testWidgets('首页展示设备列表与连接工具栏', (tester) async {
_mockChannels(devices: [_testDevice()]);
await tester.pumpWidget(const TTSTDConnectApp());
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('测试被控端'), findsOneWidget);
expect(find.text('可连接设备'), findsOneWidget);
expect(find.byIcon(Icons.play_arrow), findsOneWidget);
await tester.tap(find.byIcon(Icons.refresh));
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('可连接设备'), findsOneWidget);
});
testWidgets('扫码配对对话框展示 pairing URI', (tester) async {
_mockChannels();
testWidgets('扫码配对对话框展示原生返回的 pairing URI', (tester) async {
const uri = 'lancast://pair?ip=10.0.0.2&port=41001&fp=test-fingerprint';
_mockChannels(pairingUri: uri);
await tester.pumpWidget(const TTSTDConnectApp());
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
await tester.tap(find.byIcon(Icons.qr_code_scanner));
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('扫码配对'), findsOneWidget);
expect(find.textContaining('lancast://pair?'), findsOneWidget);
expect(find.text(uri), findsOneWidget);
});
testWidgets('配对码不可用时提示而不展示假 URI', (tester) async {
_mockChannels();
await tester.pumpWidget(const TTSTDConnectApp());
await tester.pumpAndSettle(_settleTimeout);
await tester.tap(find.byIcon(Icons.qr_code_scanner));
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('当前平台不支持扫码配对'), findsOneWidget);
});
testWidgets('设置页可切换本机信令与外部信令', (tester) async {
_mockChannels();
await tester.pumpWidget(const TTSTDConnectApp());
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
await tester.tap(find.byIcon(Icons.settings));
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('使用本机信令服务器'), findsOneWidget);
expect(find.text('开启本机信令服务'), findsOneWidget);
expect(find.textContaining('本机地址:http://'), findsOneWidget);
await tester.tap(find.text('使用本机信令服务器'));
await tester.pumpAndSettle();
await tester.pumpAndSettle(_settleTimeout);
expect(find.text('外部信令服务器'), findsOneWidget);
});