// routing_profile_model_test.dart — RoutingProfile/RoutingRule JSON 无损往返。 import 'package:flutter_test/flutter_test.dart'; import 'package:pangolin_vpn/models/routing_profile.dart'; void main() { test('RoutingProfile round-trips json', () { const j = { 'mode': 'rule', 'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true}, 'rules': [ {'type': 'domain_suffix', 'value': 'x.com', 'action': 'direct', 'note': 'ci', 'enabled': true} ], 'final': 'proxy', }; final p = RoutingProfile.fromJson(j); expect(p.mode, 'rule'); expect(p.rules.single.value, 'x.com'); expect(p.toJson(), j); // 无损往返 }); test('RoutingRule enabled 缺省容错默认 true', () { final r = RoutingRule.fromJson({'type': 'domain', 'value': 'a.com', 'action': 'proxy'}); expect(r.enabled, isTrue); }); test('RoutingRule 构造默认 enabled=true 且 toJson 恒输出 enabled 字段', () { const r = RoutingRule(type: 'domain', value: 'a.com', action: 'proxy'); expect(r.enabled, isTrue); expect(r.toJson().containsKey('enabled'), isTrue); expect(r.toJson()['enabled'], isTrue); }); test('RoutingProfile.fromJson 无档案默认(builtin 缺省)容错', () { final p = RoutingProfile.fromJson({'mode': 'global', 'rules': [], 'final': 'direct'}); expect(p.builtin.chinaDirect, isTrue); expect(p.builtin.lanDirect, isTrue); expect(p.builtin.privateViaTunnel, isTrue); }); }