Files

57 lines
2.0 KiB
Dart

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('bypass mode edits custom rules and retains preset fallback', (
tester,
) async {
final profile = ProxyProfile()
..feature = 'proxy'
..mode = 'bypass_cn'
..defaultAction = 'reject';
var saved = false;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) {
return TextButton(
onPressed: () => Navigator.push<void>(
context,
MaterialPageRoute(
builder: (_) =>
RulesPage(profile: profile, changed: () => saved = true),
),
),
child: const Text('open'),
);
},
),
),
);
await tester.tap(find.text('open'));
await tester.pumpAndSettle();
expect(find.textContaining('自定义规则和规则集优先'), findsOneWidget);
expect(find.text('当前模式暂停普通规则'), findsNothing);
expect(find.text('固定默认出口'), findsNothing);
expect(find.textContaining('预设默认出口:所选代理'), findsOneWidget);
await tester.tap(find.text('添加规则'));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'example.com');
await tester.tap(find.text('保存规则'));
await tester.pumpAndSettle();
await tester.tap(find.text('保存草稿'));
await tester.pumpAndSettle();
expect(saved, true);
expect(profile.rules.single, {
'type': 'domain_suffix',
'value': 'example.com',
'action': 'proxy',
});
// Keep the custom-mode fallback draft; the engine owns bypass mode's proxy fallback.
expect(profile.defaultAction, 'reject');
expect(profile.mode, 'bypass_cn');
});
}