Files
pangolin/client/test/widget/routing_screen_test.dart
T
wangjia d73b6da110 feat(routing): 分流规则子屏 UI(模式/内置/我的规则/添加/冲突提示)
- 新增 RoutingScreen(ConsumerWidget):代理模式段选(全局/智能/直连)→setMode、
  内置规则卡(国内直连开关 + LAN 强制锁定行)、我的规则 ReorderableListView
  (拖动排序→reorder、删除→removeRule)、添加规则弹层(类型 chip + 目标输入 +
  动作段选→addRule)、FINAL 兜底行。非智能分流模式「我的规则」区灰化+忽略提示。
- 冲突提示:①同 type+value 被更靠前规则遮蔽 →「已被上面规则覆盖」(纯本地计算);
  ②自定义 ip_cidr 规则落在私网/回环地址段 → 系统锁定提示(启发式,详见文件头注释
  ——真正的私有服务域名清单未经 API 下发给客户端,是已知缺口)。
- l10n 新增 9 个 key(routingTypeDomain/DomainKeyword/IpCidr/Geoip、
  routingRuleShadowed、routingModeNote、routingRuleValueHint、routingNoRules),
  经 design/i18n/strings.json 单源 + gen_l10n_dart.mjs 生成六语。
- 补生成 pangolin_icons.dart 的 plus 图标(design/prototype/icons.js 已有,
  codegen 之前未跑过)。
- 新增 widget 测试 test/widget/routing_screen_test.dart:模式段选/规则行/添加
  按钮可见、非智能模式灰化、重复规则遮蔽提示,共 3 例。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 08:51:40 +08:00

114 lines
3.9 KiB
Dart

// routing_screen_test.dart — 分流规则子屏冒烟测试:模式段选 + 规则行 + 添加按钮均可见。
//
// 仿 test/widget/invite_page_test.dart 的 _FakeNotifier 范式:直接 extends
// RoutingProfileNotifier 覆写 build(),绕过真实账户 API。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pangolin_vpn/l10n/strings_zh.dart';
import 'package:pangolin_vpn/models/routing_profile.dart';
import 'package:pangolin_vpn/pangolin_theme.dart';
import 'package:pangolin_vpn/state/app_providers.dart';
import 'package:pangolin_vpn/state/routing_provider.dart';
import 'package:pangolin_vpn/widgets/routing_screen.dart';
import '../helpers/harness.dart';
void main() {
setUpAll(disableGoogleFontsFetching);
testWidgets('routing screen shows mode seg + rules + add', (tester) async {
final profile = RoutingProfile.fromJson({
'mode': 'rule',
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
'rules': [
{'type': 'domain_suffix', 'value': 'x.com', 'action': 'direct'},
],
'final': 'proxy',
});
await tester.pumpWidget(ProviderScope(
overrides: [
appTextProvider.overrideWithValue(StringsZh()),
routingProfileProvider.overrideWith(() => _FakeRoutingNotifier(profile)),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: PangolinTheme.light,
home: const RoutingScreen(),
),
));
await tester.pumpAndSettle();
// 模式段选(全局/智能分流/全部直连)存在。
expect(find.text(StringsZh().routingModeSmart), findsWidgets);
// 规则行:目标值展示。
expect(find.text('x.com'), findsOneWidget);
// 添加规则按钮存在。
expect(find.text(StringsZh().routingAddRule), findsOneWidget);
});
testWidgets('non-smart mode dims the my-rules section', (tester) async {
final profile = RoutingProfile.fromJson({
'mode': 'global',
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
'rules': [
{'type': 'domain_suffix', 'value': 'x.com', 'action': 'direct'},
],
'final': 'proxy',
});
await tester.pumpWidget(ProviderScope(
overrides: [
appTextProvider.overrideWithValue(StringsZh()),
routingProfileProvider.overrideWith(() => _FakeRoutingNotifier(profile)),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: PangolinTheme.light,
home: const RoutingScreen(),
),
));
await tester.pumpAndSettle();
final opacity = tester.widget<Opacity>(find
.ancestor(of: find.text(StringsZh().routingMyRulesOrdered), matching: find.byType(Opacity))
.first);
expect(opacity.opacity, lessThan(1));
});
testWidgets('a rule shadowed by an earlier identical rule is flagged', (tester) async {
final profile = RoutingProfile.fromJson({
'mode': 'rule',
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
'rules': [
{'type': 'domain_suffix', 'value': 'dup.com', 'action': 'direct'},
{'type': 'domain_suffix', 'value': 'dup.com', 'action': 'proxy'},
],
'final': 'proxy',
});
await tester.pumpWidget(ProviderScope(
overrides: [
appTextProvider.overrideWithValue(StringsZh()),
routingProfileProvider.overrideWith(() => _FakeRoutingNotifier(profile)),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: PangolinTheme.light,
home: const RoutingScreen(),
),
));
await tester.pumpAndSettle();
expect(find.text(StringsZh().routingRuleShadowed), findsOneWidget);
});
}
class _FakeRoutingNotifier extends RoutingProfileNotifier {
_FakeRoutingNotifier(this._v);
final RoutingProfile _v;
@override
Future<RoutingProfile> build() async => _v;
}