82af7b250f
A shared RelativeTimeLabel refreshes at the next minute/hour/day boundary, pauses while the app is hidden and catches up on resume. It keeps the row's time style (an unread chat's accent). Continues run #218.
72 lines
2.5 KiB
Dart
72 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/text/relative_time_label.dart';
|
|
|
|
void main() {
|
|
testWidgets('updates at the next relative-time boundary', (tester) async {
|
|
final instant = DateTime.now().subtract(const Duration(minutes: 4));
|
|
await tester.pumpWidget(
|
|
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
|
);
|
|
expect(find.text('4m'), findsOneWidget);
|
|
|
|
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
|
expect(find.text('5m'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('future labels schedule their next boundary', (tester) async {
|
|
final instant = DateTime.now().add(const Duration(minutes: 4));
|
|
await tester.pumpWidget(
|
|
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
|
);
|
|
expect(find.text('in 3m'), findsOneWidget);
|
|
|
|
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
|
expect(find.text('in 2m'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('cancels its timer when disposed', (tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: RelativeTimeLabel(
|
|
instant: DateTime.now().subtract(const Duration(minutes: 4)),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
|
|
await tester.pump(const Duration(hours: 1));
|
|
});
|
|
|
|
testWidgets('keeps ticking while inactive, pauses while hidden and '
|
|
'refreshes on resume', (tester) async {
|
|
final instant = DateTime.now().subtract(const Duration(minutes: 4));
|
|
await tester.pumpWidget(
|
|
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
|
);
|
|
expect(find.text('4m'), findsOneWidget);
|
|
|
|
// A desktop window that lost focus is still on screen: keep ticking.
|
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
|
AppLifecycleState.inactive,
|
|
);
|
|
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
|
expect(find.text('5m'), findsOneWidget);
|
|
|
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
|
AppLifecycleState.hidden,
|
|
);
|
|
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
|
expect(find.text('5m'), findsOneWidget);
|
|
|
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
|
AppLifecycleState.inactive,
|
|
);
|
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
|
AppLifecycleState.resumed,
|
|
);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
|
expect(find.text('5m'), findsOneWidget);
|
|
});
|
|
}
|