import 'package:cardash_launcher/core/theme/app_theme.dart'; import 'package:cardash_launcher/data/models/media_playback.dart'; import 'package:cardash_launcher/data/models/system_status.dart'; import 'package:cardash_launcher/features/home/widgets/volume_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('the card shows the now-playing title', (tester) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.light(), home: const Scaffold( body: VolumeCard( volume: VolumeInfo(index: 8, max: 15), onSetVolume: _ignoreVolume, onToggleMute: _ignore, isMusicPlaying: true, onPlayPause: _ignore, media: MediaPlayback( hasAccess: true, hasSession: true, playing: true, title: 'Night Drive', artist: 'The Dashboard', durationMs: 240000, positionMs: 60000, ), ), ), ), ); expect(find.text('Night Drive — The Dashboard'), findsOneWidget); expect(find.text('Nothing playing'), findsNothing); }); testWidgets('the card shows Nothing playing without a session', ( tester, ) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.dark(), home: const Scaffold( body: VolumeCard( volume: VolumeInfo(index: 8, max: 15), onSetVolume: _ignoreVolume, onToggleMute: _ignore, isMusicPlaying: false, onPlayPause: _ignore, media: MediaPlayback(), ), ), ), ); expect(find.text('Nothing playing'), findsOneWidget); }); testWidgets('the ring switches between play and pause', (tester) async { var playing = false; var taps = 0; await tester.pumpWidget( MaterialApp( theme: AppTheme.dark(), home: Scaffold( body: StatefulBuilder( builder: (context, setState) { return VolumeCard( volume: const VolumeInfo(index: 8, max: 15), onSetVolume: (_) {}, onToggleMute: () {}, isMusicPlaying: playing, media: const MediaPlayback(), onPlayPause: () { taps++; setState(() => playing = !playing); }, ); }, ), ), ), ); expect(find.byIcon(Icons.play_arrow_rounded), findsOneWidget); expect(find.byIcon(Icons.pause_rounded), findsNothing); await tester.tap(find.byIcon(Icons.play_arrow_rounded)); await tester.pump(); expect(taps, 1); expect(find.byIcon(Icons.pause_rounded), findsOneWidget); expect(find.byIcon(Icons.play_arrow_rounded), findsNothing); }); } void _ignore() {} void _ignoreVolume(int _) {}