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(), ); }); test('exposes bootstrap H5 URL as Flutter shell lines', () { final lines = AppConfig.h5Lines; 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 fixed client config query parameters', () { expect(AppConfig.clientConfigQueryPayload, { 'device': 'h5', 'serialNo': 'h5-domain', }); expect( AppConfig.clientConfigQueryUris.first.path, '/client_config/query', ); }); 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', ); 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); }); }