import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshport_client_core/meshport_client_core.dart'; import 'package:meshport_lab/features/configuration_pages.dart'; void main() { testWidgets('DNS saves FakeIP draft and keeps mesh exclusions', ( tester, ) async { final p = ProxyProfile() ..meshDns = [ {'suffix': 'mesh.test', 'server': '10.77.0.2'}, ]; bool changed = false; await tester.pumpWidget( MaterialApp( home: DnsPage(profile: p, changed: () => changed = true), ), ); await tester.tap(find.text('FakeIP')); await tester.pumpAndSettle(); expect(p.fakeIP, isFalse); await tester.tap(find.text('保存草稿')); await tester.pumpAndSettle(); expect(p.fakeIP, isTrue); expect(changed, isTrue); expect(p.runtime()['mesh_dns'], isNotEmpty); p.feature = 'proxy'; expect(p.runtime()['mesh_dns'], isEmpty); }); testWidgets('P2P disable pauses punching without losing values', ( tester, ) async { await tester.pumpWidget( MaterialApp( home: NetworkConfigPage( section: '连接与打洞', initial: { 'flags': {'disable_p2p': true, 'disable_udp_hole_punching': true}, }, save: (_) async {}, ), ), ); final switches = tester .widgetList(find.byType(SwitchListTile)) .toList(); expect(switches[1].onChanged, isNull); expect(switches[1].value, isTrue); await tester.tap(find.text('禁用 P2P')); await tester.pumpAndSettle(); final next = tester .widgetList(find.byType(SwitchListTile)) .toList(); expect(next[1].onChanged, isNotNull); expect(next[1].value, isTrue); }); testWidgets('rule editor rejects wildcard domains', (tester) async { await tester.pumpWidget(const MaterialApp(home: RuleEditor())); await tester.enterText(find.byType(TextField), '*.example.com'); await tester.tap(find.text('保存规则')); await tester.pumpAndSettle(); expect(find.text('请输入有效域名或 CIDR,不接受星号语法'), findsOneWidget); }); test( 'network draft preserves supported options and forces encrypted single-stack host', () { final draft = NetworkProfile({ 'runtime_mode': 'unified_vpn', 'ipv4': '10.77.0.11/24', 'network_name': 'test', 'network_secret': 'test-only', 'flags': {'disable_p2p': true}, 'listeners': ['udp://0.0.0.0:11010'], 'stun_servers': [], 'optimization': {'mode': 'direct'}, }); expect(draft.toToml(), contains('no_tun = true')); expect(draft.toToml(), contains('disable_p2p = true')); expect(draft.toToml(), contains('enable_encryption = true')); expect(draft.toToml(), contains('stun_servers = []')); }, ); }