55 lines
1.2 KiB
Dart
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');
|
|
},
|
|
);
|
|
});
|
|
}
|