volume_card_test.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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('the ring switches between play and pause', (tester) async {
  56. var playing = false;
  57. var taps = 0;
  58. await tester.pumpWidget(
  59. MaterialApp(
  60. theme: AppTheme.dark(),
  61. home: Scaffold(
  62. body: StatefulBuilder(
  63. builder: (context, setState) {
  64. return VolumeCard(
  65. volume: const VolumeInfo(index: 8, max: 15),
  66. onSetVolume: (_) {},
  67. onToggleMute: () {},
  68. isMusicPlaying: playing,
  69. media: const MediaPlayback(),
  70. onPlayPause: () {
  71. taps++;
  72. setState(() => playing = !playing);
  73. },
  74. );
  75. },
  76. ),
  77. ),
  78. ),
  79. );
  80. expect(find.byIcon(Icons.play_arrow_rounded), findsOneWidget);
  81. expect(find.byIcon(Icons.pause_rounded), findsNothing);
  82. await tester.tap(find.byIcon(Icons.play_arrow_rounded));
  83. await tester.pump();
  84. expect(taps, 1);
  85. expect(find.byIcon(Icons.pause_rounded), findsOneWidget);
  86. expect(find.byIcon(Icons.play_arrow_rounded), findsNothing);
  87. });
  88. }
  89. void _ignore() {}
  90. void _ignoreVolume(int _) {}