Skip to content

Commit 0e4c81d

Browse files
committed
FIXME LINK binding: Add stopwatch.
The stopwatch gets replaced with a testable stopwatch from clock/clock in tests. We need to for testability of stopwatches with fake async. The "normal" stopwatch gets used when not testing. This implementation was inspired by: https://github.com/flutter/flutter/pull/137381/commits/ bbdeabf74b8e9443f0156b4631d460f022ac598c Signed-off-by: Zixuan James Li <[email protected]>
1 parent 8335423 commit 0e4c81d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/model/binding.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ abstract class ZulipBinding {
105105
/// This wraps [url_launcher.closeInAppWebView].
106106
Future<void> closeInAppWebView();
107107

108+
/// Provides access to a new stopwatch.
109+
Stopwatch stopwatch();
110+
108111
/// Provides device and operating system information,
109112
/// via package:device_info_plus.
110113
///
@@ -335,6 +338,11 @@ class LiveZulipBinding extends ZulipBinding {
335338
return url_launcher.closeInAppWebView();
336339
}
337340

341+
@override
342+
Stopwatch stopwatch() {
343+
return Stopwatch();
344+
}
345+
338346
@override
339347
Future<BaseDeviceInfo?> get deviceInfo => _deviceInfo;
340348
late Future<BaseDeviceInfo?> _deviceInfo;

test/model/binding.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22

3+
import 'package:clock/clock.dart';
34
import 'package:firebase_core/firebase_core.dart';
45
import 'package:firebase_messaging/firebase_messaging.dart';
56
import 'package:flutter/foundation.dart';
@@ -206,6 +207,11 @@ class TestZulipBinding extends ZulipBinding {
206207
_closeInAppWebViewCallCount++;
207208
}
208209

210+
@override
211+
Stopwatch stopwatch() {
212+
return clock.stopwatch();
213+
}
214+
209215
/// The value that `ZulipBinding.instance.deviceInfo` should return.
210216
BaseDeviceInfo deviceInfoResult = _defaultDeviceInfoResult;
211217
static const _defaultDeviceInfoResult = AndroidDeviceInfo(sdkInt: 33, release: '13');

0 commit comments

Comments
 (0)