feat: 添加 H5 线路切换功能;支持动态加载和切换不同线路的 URL

This commit is contained in:
Booker
2026-05-27 12:53:47 +07:00
parent e5d3c12c15
commit 8659a2e66e
4 changed files with 472 additions and 10 deletions

View File

@@ -30,6 +30,26 @@ void main() {
isFalse);
});
test('exposes configured H5 URLs as Flutter shell lines', () {
final lines = AppConfig.h5Lines;
expect(lines, isNotEmpty);
expect(lines.first.label, '线路1');
expect(lines.first.url, AppConfig.homeUrl(lineIndex: 0));
expect(Uri.parse(lines.first.url).host, 'h5-test.imharry.work');
});
test('falls back to the first H5 line for invalid line indexes', () {
expect(AppConfig.homeUrl(lineIndex: -1), AppConfig.h5Lines.first.url);
expect(AppConfig.homeUrl(lineIndex: 99), AppConfig.h5Lines.first.url);
});
test('matches runtime URLs back to their Flutter shell line', () {
final lineUrl = AppConfig.h5Lines.first.url;
expect(AppConfig.lineIndexForUrl('${lineUrl}login'), 0);
});
test('refreshes an H5 route URL without adding branding to the URL', () {
final uri = Uri.parse(
AppConfig.withFreshShellParams(
@@ -48,6 +68,22 @@ void main() {
isFalse);
});
test('keeps independent non-legacy H5 hosts when removing shell params', () {
final uri = Uri.parse(
AppConfig.canonicalizeMainFrameUrl(
'https://line-two.example/login?shell_app_name=Old'
'&flutter_shell=1#shell_app_logo=old',
),
);
expect(uri.host, 'line-two.example');
expect(uri.path, '/login');
expect(uri.queryParameters.containsKey('shell_app_name'), isFalse);
expect(uri.queryParameters.containsKey('flutter_shell'), isFalse);
expect(Uri.splitQueryString(uri.fragment).containsKey('shell_app_logo'),
isFalse);
});
test('rewrites legacy H5 host main-frame URLs to the canonical host', () {
final uri = Uri.parse(
AppConfig.canonicalizeMainFrameUrl(