Files
Flutter_Shell/test/widget_test.dart
Booker 15d767100a Refactor widget tests for H5 line generation and validation
- Simplified tests for H5 line creation, focusing on single line generation with a numeric 16-digit label.
- Updated assertions to validate the generated H5 line's label and URI structure.
- Removed redundant tests related to default H5 line URLs and local access, consolidating functionality into fewer tests.
- Added new tests to ensure correct URL generation from configured fallback order and query parameter handling.
- Enhanced test coverage for restoring cached H5 line URLs and validating their structure.
2026-06-06 03:48:20 +07:00

69 lines
2.1 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:im_webview_app/config/app_config.dart';
import 'package:im_webview_app/main.dart';
void main() {
test('creates the WebView shell app widget', () {
expect(
const ImWebViewApp(shellBranding: ShellBranding.fallback),
isA<Widget>(),
);
});
test('creates one wildcard H5 line with a numeric 16 digit label', () {
final line = AppConfig.h5Line;
expect(line.label, '线路1');
expect(
line.uri.host,
matches(RegExp(r'^[1-9][0-9]{15}\.(albzyuxq|zdyswvnt|gxifpxcr)\.vip$')),
);
});
test('generates the next single URL from the configured fallback order', () {
var index = 0;
const labels = [
'1234567890123456',
'2234567890123456',
'3234567890123456',
];
final first = AppConfig.createRandomH5Line(
attempt: 0, wildcardFactory: () => labels[index++]);
final second = AppConfig.createRandomH5Line(
attempt: 1, wildcardFactory: () => labels[index++]);
final third = AppConfig.createRandomH5Line(
attempt: 2, wildcardFactory: () => labels[index++]);
expect(first.uri.host, '1234567890123456.albzyuxq.vip');
expect(second.uri.host, '2234567890123456.zdyswvnt.vip');
expect(third.uri.host, '3234567890123456.gxifpxcr.vip');
});
test('passes Flutter shell request URL to H5 through query parameters', () {
final line = AppConfig.createRandomH5Line(
wildcardFactory: () => '1234567890123456',
);
final uri = line.uri;
expect(uri.queryParameters[AppConfig.flutterShellMarkerQueryKey], '1');
expect(
uri.queryParameters[AppConfig.flutterShellUrlQueryKey],
'https://1234567890123456.albzyuxq.vip',
);
expect(
AppConfig.originForUrl(line.url),
'https://1234567890123456.albzyuxq.vip',
);
});
test('restores a cached H5 line URL with the single line label', () {
final line = AppConfig.h5LineFromUrl(
'https://1234567890123456.albzyuxq.vip/?flutter_shell=1',
);
expect(line.label, '线路1');
expect(line.uri.host, '1234567890123456.albzyuxq.vip');
});
}