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.
This commit is contained in:
@@ -11,125 +11,58 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('exposes bootstrap H5 URL as Flutter shell lines', () {
|
||||
final lines = AppConfig.h5Lines;
|
||||
test('creates one wildcard H5 line with a numeric 16 digit label', () {
|
||||
final line = AppConfig.h5Line;
|
||||
|
||||
expect(lines, isNotEmpty);
|
||||
expect(lines.first.label, '线路1');
|
||||
expect(Uri.parse(lines.first.url).scheme, 'https');
|
||||
expect(Uri.parse(lines.first.url).path, '/');
|
||||
});
|
||||
|
||||
test('uses current non-local service origin as default H5 line', () {
|
||||
final urls = AppConfig.defaultH5LineUrlsForBaseUri(
|
||||
Uri.parse('https://app.example.com/shell/index.html?from=local#hash'),
|
||||
);
|
||||
|
||||
expect(urls, ['https://app.example.com/']);
|
||||
});
|
||||
|
||||
test('preserves current service port when building default H5 line', () {
|
||||
final urls = AppConfig.defaultH5LineUrlsForBaseUri(
|
||||
Uri.parse('https://chat.example.com:8443/app/'),
|
||||
);
|
||||
|
||||
expect(urls, ['https://chat.example.com:8443/']);
|
||||
});
|
||||
|
||||
test('keeps fixed bootstrap H5 line for local browser access', () {
|
||||
final urls = AppConfig.defaultH5LineUrlsForBaseUri(
|
||||
Uri.parse('http://localhost:3000/'),
|
||||
);
|
||||
|
||||
expect(urls, ['https://h5-test.imharry.work/']);
|
||||
});
|
||||
|
||||
test('keeps fixed bootstrap H5 line for loopback browser access', () {
|
||||
final urls = AppConfig.defaultH5LineUrlsForBaseUri(
|
||||
Uri.parse('http://127.0.0.1:3000/'),
|
||||
);
|
||||
|
||||
expect(urls, ['https://h5-test.imharry.work/']);
|
||||
});
|
||||
|
||||
test('keeps fixed bootstrap H5 line for native app access', () {
|
||||
final urls = AppConfig.defaultH5LineUrlsForBaseUri(
|
||||
Uri.parse('file:///android_asset/flutter_assets/'),
|
||||
);
|
||||
|
||||
expect(urls, ['https://h5-test.imharry.work/']);
|
||||
});
|
||||
|
||||
test('uses fixed client config query parameters', () {
|
||||
expect(AppConfig.clientConfigQueryPayload, {
|
||||
'device': 'h5',
|
||||
'serialNo': 'h5-domain',
|
||||
});
|
||||
expect(line.label, '线路1');
|
||||
expect(
|
||||
AppConfig.clientConfigQueryUris.first.path,
|
||||
'/client_config/query',
|
||||
line.uri.host,
|
||||
matches(RegExp(r'^[1-9][0-9]{15}\.(albzyuxq|zdyswvnt|gxifpxcr)\.vip$')),
|
||||
);
|
||||
});
|
||||
|
||||
test('builds client config query APIs from current service origin', () {
|
||||
final uris = AppConfig.clientConfigQueryUrisForHomeUri(
|
||||
Uri.parse('https://app.example.com/app/index.html?from=local#hash'),
|
||||
);
|
||||
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(
|
||||
uris.map((uri) => uri.toString()),
|
||||
[
|
||||
'https://app.example.com/client_config/query',
|
||||
'https://app.example.com/api/user/client_config/query',
|
||||
],
|
||||
uri.queryParameters[AppConfig.flutterShellUrlQueryKey],
|
||||
'https://1234567890123456.albzyuxq.vip',
|
||||
);
|
||||
expect(
|
||||
AppConfig.originForUrl(line.url),
|
||||
'https://1234567890123456.albzyuxq.vip',
|
||||
);
|
||||
});
|
||||
|
||||
test('splits client config resourceUrl into indexed H5 lines', () {
|
||||
final lines = AppConfig.h5LinesFromResourceUrl(
|
||||
'line-one.example\nhttps://line-two.example/app\n\nline-three.example',
|
||||
test('restores a cached H5 line URL with the single line label', () {
|
||||
final line = AppConfig.h5LineFromUrl(
|
||||
'https://1234567890123456.albzyuxq.vip/?flutter_shell=1',
|
||||
);
|
||||
|
||||
expect(lines.map((line) => line.label), ['线路1', '线路2', '线路3']);
|
||||
expect(Uri.parse(lines[0].url).host, 'line-one.example');
|
||||
expect(Uri.parse(lines[1].url).host, 'line-two.example');
|
||||
expect(Uri.parse(lines[1].url).path, '/app');
|
||||
expect(Uri.parse(lines[2].url).host, 'line-three.example');
|
||||
});
|
||||
|
||||
test('splits literal backslash-n resourceUrl values', () {
|
||||
final lines = AppConfig.h5LinesFromResourceUrl(
|
||||
r'line-one.example\n*.line-two.example\nline-three.example',
|
||||
wildcardFactory: () => 'abcdefghijklmnop',
|
||||
);
|
||||
|
||||
expect(lines.map((line) => line.label), ['线路1', '线路2', '线路3']);
|
||||
expect(Uri.parse(lines[0].url).host, 'line-one.example');
|
||||
expect(Uri.parse(lines[1].url).host, 'abcdefghijklmnop.line-two.example');
|
||||
expect(Uri.parse(lines[2].url).host, 'line-three.example');
|
||||
});
|
||||
|
||||
test('expands wildcard H5 domains with a 16 character label', () {
|
||||
final lines = AppConfig.h5LinesFromResourceUrl(
|
||||
'*.albzyuxq.vip',
|
||||
wildcardFactory: () => 'abcdefghijklmnop',
|
||||
);
|
||||
|
||||
final host = Uri.parse(lines.single.url).host;
|
||||
expect(host, 'abcdefghijklmnop.albzyuxq.vip');
|
||||
expect(host.split('.').first.length, 16);
|
||||
});
|
||||
|
||||
test('detects only H5 login routes for shell line switch display', () {
|
||||
expect(AppConfig.isLoginPageUrl('https://line-one.example/login'), isTrue);
|
||||
expect(
|
||||
AppConfig.isLoginPageUrl('https://line-one.example/app/login'), isTrue);
|
||||
expect(
|
||||
AppConfig.isLoginPageUrl('https://line-one.example/#/login'), isTrue);
|
||||
expect(AppConfig.isLoginPageUrl('https://line-one.example/'), isFalse);
|
||||
expect(
|
||||
AppConfig.isLoginPageUrl('https://line-one.example/contact'), isFalse);
|
||||
expect(
|
||||
AppConfig.isLoginPageUrl('https://line-one.example/getCode'), isFalse);
|
||||
expect(line.label, '线路1');
|
||||
expect(line.uri.host, '1234567890123456.albzyuxq.vip');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user