Files
ReelShort/test/platform/wireless_data_prompt_test.dart
T
Zhou Weidong b5e9deb4bd feat(ios): 首次启动询问无线数据权限
iOS 在首个接口请求前等待系统无线数据选择,避免未授权时请求被静默拒绝。
2026-10-25 21:23:25 +08:00

55 lines
1.2 KiB
Dart

// Author: fruit.com.cn
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/platform/wireless_data_prompt.dart';
void main() {
setUp(WirelessDataPrompt.resetForTest);
tearDown(WirelessDataPrompt.resetForTest);
test('should_return_immediately_when_disabled', () async {
var calls = 0;
await WirelessDataPrompt.awaitDecision(
enabled: false,
ask: () async {
calls++;
},
);
expect(calls, 0);
});
test('should_ask_once_when_enabled', () async {
var calls = 0;
Future<void> ask() async {
calls++;
}
await WirelessDataPrompt.awaitDecision(enabled: true, ask: ask);
await WirelessDataPrompt.awaitDecision(enabled: true, ask: ask);
expect(calls, 1);
});
test('should_continue_when_decision_times_out', () async {
await WirelessDataPrompt.awaitDecision(
enabled: true,
ask: () => Completer<void>().future,
timeout: const Duration(milliseconds: 20),
);
});
test('should_continue_when_ask_fails', () async {
await WirelessDataPrompt.awaitDecision(
enabled: true,
ask: () async {
throw StateError('channel missing');
},
);
});
}