Merge commit '72128d53685269ff1e13d2c76c80b6276f7635ba' into sticky-section-clip
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user