Skip to content

Commit bb1c54f

Browse files
committed
fix 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 945066c commit bb1c54f

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
@@ -106,6 +106,9 @@ abstract class ZulipBinding {
106106
/// This wraps [url_launcher.closeInAppWebView].
107107
Future<void> closeInAppWebView();
108108

109+
/// Provides access to a new stopwatch.
110+
Stopwatch stopwatch();
111+
109112
/// Provides device and operating system information,
110113
/// via package:device_info_plus.
111114
///
@@ -349,6 +352,11 @@ class LiveZulipBinding extends ZulipBinding {
349352
return url_launcher.closeInAppWebView();
350353
}
351354

355+
@override
356+
Stopwatch stopwatch() {
357+
return Stopwatch();
358+
}
359+
352360
@override
353361
Future<BaseDeviceInfo?> get deviceInfo => _deviceInfo;
354362
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';
@@ -207,6 +208,11 @@ class TestZulipBinding extends ZulipBinding {
207208
_closeInAppWebViewCallCount++;
208209
}
209210

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

0 commit comments

Comments
 (0)