import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshport_lab/features/proxy_source_pages.dart'; import 'package:meshport_lab/features/detail_pages.dart'; import 'package:meshport_lab/features/configuration_pages.dart'; import 'package:meshport_client_core/meshport_client_core.dart'; void main() { const channel = MethodChannel('meshport/system_vpn'); tearDown( () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, null), ); testWidgets('file import fills draft and requires explicit node preview', ( tester, ) async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( channel, (call) async => call.method == 'import_file' ? 'socks://127.0.0.1:1001' : null, ); await tester.pumpWidget(const MaterialApp(home: ProxyImportPage())); await tester.tap(find.text('文件导入')); await tester.pumpAndSettle(); expect(find.text('确认导入'), findsNothing); await tester.tap(find.text('解析并预览')); await tester.pumpAndSettle(); expect(find.text('确认导入'), findsOneWidget); }); testWidgets('subscription options and metadata survive save', (tester) async { Map? result; await tester.pumpWidget( MaterialApp( home: Builder( builder: (context) => TextButton( onPressed: () async { result = await Navigator.push>( context, MaterialPageRoute( builder: (_) => const SubscriptionEditor( subscription: { 'id': 's', 'name': 'Test', 'url': 'https://example.test/sub', 'updated': '2026-10-10T00:00:00Z', 'auto_update': true, 'interval_minutes': 360, }, ), ), ); }, child: const Text('open'), ), ), ), ); await tester.tap(find.text('open')); await tester.pumpAndSettle(); await tester.tap(find.text('自动更新订阅')); await tester.tap(find.text('保存草稿')); await tester.pumpAndSettle(); expect(result?['auto_update'], false); expect(result?['updated'], '2026-10-10T00:00:00Z'); }); testWidgets( 'startup screen reads actual status without registering login item', (tester) async { final calls = []; TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, (call) async { calls.add(call.method); return {'login_status': 'requires_approval', 'auto_connect': false}; }); await tester.pumpWidget( const MaterialApp( home: Scaffold(body: StartupPageBody(channel: channel)), ), ); await tester.pumpAndSettle(); expect(find.text('打开系统登录项,允许 MeshPort'), findsOneWidget); expect(calls, ['startup_status']); }, ); testWidgets('DoT default port is accepted and saved', (tester) async { final p = ProxyProfile(); await tester.pumpWidget( MaterialApp( home: DnsPage(profile: p, changed: () {}), ), ); await tester.enterText(find.byType(TextField).at(1), 'tls://dns.example'); await tester.tap(find.text('保存草稿')); await tester.pumpAndSettle(); expect(p.directDnsServer, 'tls://dns.example'); }); }