volume_card_test.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:cardash_launcher/core/theme/app_theme.dart';
  2. import 'package:cardash_launcher/data/models/media_playback.dart';
  3. import 'package:cardash_launcher/data/models/system_status.dart';
  4. import 'package:cardash_launcher/features/home/widgets/volume_card.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_test/flutter_test.dart';
  7. void main() {
  8. testWidgets('the card shows the now-playing title', (tester) async {
  9. await tester.pumpWidget(
  10. MaterialApp(
  11. theme: AppTheme.light(),
  12. home: const Scaffold(
  13. body: VolumeCard(
  14. volume: VolumeInfo(index: 8, max: 15),
  15. onSetVolume: _ignoreVolume,
  16. onToggleMute: _ignore,
  17. isMusicPlaying: true,
  18. onPlayPause: _ignore,
  19. media: MediaPlayback(
  20. hasAccess: true,
  21. hasSession: true,
  22. playing: true,
  23. title: 'Night Drive',
  24. artist: 'The Dashboard',
  25. durationMs: 240000,
  26. positionMs: 60000,
  27. ),
  28. ),
  29. ),
  30. ),
  31. );
  32. expect(find.text('Night Drive — The Dashboard'), findsOneWidget);
  33. expect(find.text('Nothing playing'), findsNothing);
  34. });
  35. testWidgets('the card shows Nothing playing without a session', (
  36. tester,
  37. ) async {
  38. await tester.pumpWidget(
  39. MaterialApp(
  40. theme: AppTheme.dark(),
  41. home: const Scaffold(
  42. body: VolumeCard(
  43. volume: VolumeInfo(index: 8, max: 15),
  44. onSetVolume: _ignoreVolume,
  45. onToggleMute: _ignore,
  46. isMusicPlaying: false,
  47. onPlayPause: _ignore,
  48. media: MediaPlayback(),
  49. ),
  50. ),
  51. ),
  52. );
  53. expect(find.text('Nothing playing'), findsOneWidget);
  54. });
  55. testWidgets('fixed car volume disables the slider and explains why', (
  56. tester,
  57. ) async {
  58. await tester.pumpWidget(
  59. MaterialApp(
  60. theme: AppTheme.dark(),
  61. home: const Scaffold(
  62. body: VolumeCard(
  63. volume: VolumeInfo(index: 100, max: 100, fixed: true),
  64. onSetVolume: _ignoreVolume,
  65. onToggleMute: _ignore,
  66. isMusicPlaying: false,
  67. onPlayPause: _ignore,
  68. media: MediaPlayback(),
  69. ),
  70. ),
  71. ),
  72. );
  73. expect(find.text('100%'), findsOneWidget);
  74. expect(find.text('Volume is controlled by the car'), findsOneWidget);
  75. expect(tester.widget<Slider>(find.byType(Slider)).onChanged, isNull);
  76. expect(find.text('Mute'), findsNothing);
  77. });
  78. testWidgets('the ring switches between play and pause', (tester) async {
  79. var playing = false;
  80. var taps = 0;
  81. await tester.pumpWidget(
  82. MaterialApp(
  83. theme: AppTheme.dark(),
  84. home: Scaffold(
  85. body: StatefulBuilder(
  86. builder: (context, setState) {
  87. return VolumeCard(
  88. volume: const VolumeInfo(index: 8, max: 15),
  89. onSetVolume: (_) {},
  90. onToggleMute: () {},
  91. isMusicPlaying: playing,
  92. media: const MediaPlayback(),
  93. onPlayPause: () {
  94. taps++;
  95. setState(() => playing = !playing);
  96. },
  97. );
  98. },
  99. ),
  100. ),
  101. ),
  102. );
  103. expect(find.byIcon(Icons.play_arrow_rounded), findsOneWidget);
  104. expect(find.byIcon(Icons.pause_rounded), findsNothing);
  105. await tester.tap(find.byIcon(Icons.play_arrow_rounded));
  106. await tester.pump();
  107. expect(taps, 1);
  108. expect(find.byIcon(Icons.pause_rounded), findsOneWidget);
  109. expect(find.byIcon(Icons.play_arrow_rounded), findsNothing);
  110. });
  111. }
  112. void _ignore() {}
  113. void _ignoreVolume(int _) {}