Files
shenandshen c7cc2aa865 Fix VPN internet connectivity and simplify client setup
Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
2026-10-12 06:51:25 -07:00

110 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshport_lab/features/lab_screen.dart';
void main() {
testWidgets('connection explains missing node and clears stale errors', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: LabScreen(initializeNative: false)),
);
await tester.tap(find.text('代理').last);
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('连接').last);
await tester.tap(find.text('连接').last);
await tester.pumpAndSettle();
expect(find.textContaining('请先添加代理节点'), findsOneWidget);
await tester.ensureVisible(find.text('诊断与日志'));
await tester.tap(find.text('诊断与日志'));
await tester.pumpAndSettle();
expect(find.textContaining('[校验代理配置] 失败'), findsOneWidget);
expect(find.textContaining('入口=unified_vpn'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('全局代理').last);
await tester.tap(find.text('全局代理').last);
await tester.pumpAndSettle();
await tester.tap(find.text('直连').last);
await tester.pumpAndSettle();
expect(find.textContaining('请先添加代理节点'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('China bypass can be selected and switched to global', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: LabScreen(initializeNative: false)),
);
await tester.tap(find.text('代理').last);
await tester.pumpAndSettle();
final mode = find.byWidgetPredicate(
(w) =>
w is DropdownButtonFormField<String> &&
w.decoration.labelText == '上网模式',
);
await tester.ensureVisible(mode);
await tester.tap(mode);
await tester.pumpAndSettle();
await tester.tap(find.text('绕过中国大陆').last);
await tester.pumpAndSettle();
expect(find.textContaining('中国大陆 IP 和普通私网直连'), findsOneWidget);
await tester.tap(mode);
await tester.pumpAndSettle();
await tester.tap(find.text('全局代理').last);
await tester.pumpAndSettle();
expect(find.textContaining('中国大陆 IP 和普通私网直连'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('Starts disconnected and exposes networking configuration', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: LabScreen(initializeNative: false)),
);
expect(find.text('尚未连接'), findsOneWidget);
await tester.tap(find.text('组网').last);
await tester.pumpAndSettle();
await tester.tap(find.text('基础配置'));
await tester.pumpAndSettle();
expect(find.text('网络密钥'), findsOneWidget);
expect(find.text('保存草稿'), findsOneWidget);
});
testWidgets('proxy import requires preview and preserves draft separation', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: LabScreen(initializeNative: false)),
);
await tester.tap(find.text('代理').last);
await tester.pumpAndSettle();
expect(find.text('上网模式'), findsOneWidget);
await tester.ensureVisible(find.text('导入与预览'));
await tester.tap(find.text('导入与预览'));
await tester.pumpAndSettle();
await tester.enterText(
find.byType(TextField).last,
'socks5://127.0.0.1:1080#Preview',
);
await tester.tap(find.text('解析并预览'));
await tester.pumpAndSettle();
expect(find.text('导入预览'), findsOneWidget);
expect(find.text('Preview'), findsOneWidget);
await tester.tap(find.text('确认导入'));
await tester.pumpAndSettle();
expect(find.text('Preview'), findsOneWidget);
expect(find.byIcon(Icons.radio_button_checked), findsOneWidget);
expect(find.text('网络入口'), findsNothing);
expect(find.text('编辑 DNS'), findsNothing);
await tester.ensureVisible(find.text('高级设置'));
await tester.tap(find.text('高级设置'));
await tester.pumpAndSettle();
expect(find.text('网络入口'), findsOneWidget);
expect(find.text('编辑 DNS'), findsOneWidget);
});
}