fix(flutter): 修复 iOS 启动网络加载
This commit is contained in:
1 parent
23059578d2
commit
a63334f5a5
3 files changed
+129
-26
No files matched your search
@@ -60,6 +60,59 @@ void main() {
|
||||
expect(AppConfig.devHostBaseUrl, 'http://192.168.31.187:8081');
|
||||
});
|
||||
|
||||
test('should_keep_loopback_priority_when_probe_succeeds', () async {
|
||||
final attempts = <String>[];
|
||||
|
||||
await AppConfig.probeAndApplyBaseUrl(
|
||||
fallbackBaseUrl: AppConfig.devHostBaseUrl,
|
||||
probe: (baseUrl) async {
|
||||
attempts.add(baseUrl);
|
||||
return baseUrl == AppConfig.lanBaseUrl;
|
||||
},
|
||||
);
|
||||
|
||||
expect(attempts, [AppConfig.lanBaseUrl]);
|
||||
expect(AppConfig.apiBaseUrl, AppConfig.lanBaseUrl);
|
||||
});
|
||||
|
||||
test('should_probe_loopback_dev_host_then_public_in_order', () async {
|
||||
final attempts = <String>[];
|
||||
|
||||
await AppConfig.probeAndApplyBaseUrl(
|
||||
fallbackBaseUrl: AppConfig.devHostBaseUrl,
|
||||
probe: (baseUrl) async {
|
||||
attempts.add(baseUrl);
|
||||
return baseUrl == AppConfig.publicBaseUrl;
|
||||
},
|
||||
);
|
||||
|
||||
expect(attempts, [
|
||||
AppConfig.lanBaseUrl,
|
||||
AppConfig.devHostBaseUrl,
|
||||
AppConfig.publicBaseUrl,
|
||||
]);
|
||||
expect(AppConfig.apiBaseUrl, AppConfig.publicBaseUrl);
|
||||
});
|
||||
|
||||
test('should_use_platform_default_when_all_probes_fail', () async {
|
||||
final attempts = <String>[];
|
||||
|
||||
await AppConfig.probeAndApplyBaseUrl(
|
||||
fallbackBaseUrl: AppConfig.devHostBaseUrl,
|
||||
probe: (baseUrl) async {
|
||||
attempts.add(baseUrl);
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
expect(attempts, [
|
||||
AppConfig.lanBaseUrl,
|
||||
AppConfig.devHostBaseUrl,
|
||||
AppConfig.publicBaseUrl,
|
||||
]);
|
||||
expect(AppConfig.apiBaseUrl, AppConfig.devHostBaseUrl);
|
||||
});
|
||||
|
||||
test('should_apply_stored_url_only_when_debug_is_enabled', () async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({
|
||||
@@ -81,10 +134,7 @@ void main() {
|
||||
isNull,
|
||||
);
|
||||
|
||||
expect(
|
||||
await ServerEndpoint.save(' http://192.168.31.187:8081/ '),
|
||||
isTrue,
|
||||
);
|
||||
expect(await ServerEndpoint.save(' http://192.168.31.187:8081/ '), isTrue);
|
||||
expect(
|
||||
await SharedPreferencesAsync().getString(ServerEndpoint.preferenceKey),
|
||||
'http://192.168.31.187:8081',
|
||||
|
||||
Reference in new issue
Block a user