home_hint_test.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:cardash_launcher/core/theme/app_theme.dart';
  2. import 'package:cardash_launcher/features/home/widgets/home_hint.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_test/flutter_test.dart';
  5. Widget _host(HomeHint hint) {
  6. return MaterialApp(
  7. theme: AppTheme.light(),
  8. home: Scaffold(body: Center(child: hint)),
  9. );
  10. }
  11. void main() {
  12. testWidgets('hint fades out ten minutes after first launch', (tester) async {
  13. final firstLaunch = DateTime(2026, 1, 1, 12);
  14. await tester.pumpWidget(
  15. _host(
  16. HomeHint(
  17. text: 'Hold a shortcut to change the app',
  18. firstLaunchAt: firstLaunch,
  19. clock: () => firstLaunch.add(const Duration(minutes: 1)),
  20. ),
  21. ),
  22. );
  23. expect(find.text('Hold a shortcut to change the app'), findsOneWidget);
  24. await tester.pump(const Duration(minutes: 10));
  25. await tester.pump(const Duration(milliseconds: 400));
  26. expect(find.text('Hold a shortcut to change the app'), findsNothing);
  27. });
  28. testWidgets('hint never appears after the first-launch window', (
  29. tester,
  30. ) async {
  31. final firstLaunch = DateTime(2026, 1, 1, 12);
  32. await tester.pumpWidget(
  33. _host(
  34. HomeHint(
  35. text: 'Hold a shortcut to change the app',
  36. firstLaunchAt: firstLaunch,
  37. clock: () => firstLaunch.add(const Duration(minutes: 11)),
  38. ),
  39. ),
  40. );
  41. expect(find.text('Hold a shortcut to change the app'), findsNothing);
  42. });
  43. testWidgets('an upgraded installation has no onboarding hint', (
  44. tester,
  45. ) async {
  46. await tester.pumpWidget(
  47. _host(
  48. HomeHint(
  49. text: 'Hold a shortcut to change the app',
  50. firstLaunchAt: DateTime.fromMillisecondsSinceEpoch(0),
  51. ),
  52. ),
  53. );
  54. expect(find.text('Hold a shortcut to change the app'), findsNothing);
  55. });
  56. }