| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import 'package:cardash_launcher/data/models/app_entry.dart';
- import 'package:cardash_launcher/data/models/media_playback.dart';
- import 'package:cardash_launcher/data/models/system_status.dart';
- import 'package:cardash_launcher/data/services/native_bridge.dart';
- import 'package:cardash_launcher/features/home/system_controller.dart';
- import 'package:flutter_test/flutter_test.dart';
- class _MediaPlatform implements LauncherPlatform {
- bool playing = false;
- MediaPlayback media = const MediaPlayback();
- final List<String> keys = [];
- @override
- Future<List<AppEntry>> listApps() async => const [];
- @override
- Future<void> launchApp({
- required String packageName,
- required String activityName,
- }) async {}
- @override
- Future<bool> isDefaultHome() async => true;
- @override
- Future<bool> requestDefaultHome() async => true;
- @override
- Future<SystemStatus> getStatus() async => const SystemStatus();
- @override
- Future<VolumeInfo> getVolume() async => const VolumeInfo(index: 8, max: 15);
- @override
- Future<void> setVolume(int index) async {}
- @override
- Future<bool> isMusicPlaying() async => playing;
- @override
- Future<bool> sendMediaKey(String action) async {
- keys.add(action);
- if (action == 'play') playing = true;
- if (action == 'pause') playing = false;
- return true;
- }
- @override
- Future<MediaPlayback> getMediaState() async => media;
- @override
- Future<bool> openNotificationAccessSettings() async => true;
- @override
- Future<void> setKeepScreenOn(bool enabled) async {}
- }
- void main() {
- test('pause sends the pause key and clears playing state', () async {
- final platform = _MediaPlatform()..playing = true;
- final controller = SystemController(platform);
- await controller.start();
- addTearDown(controller.dispose);
- expect(controller.isMusicPlaying, isTrue);
- await controller.pauseMusic();
- expect(platform.keys, contains('pause'));
- expect(controller.isMusicPlaying, isFalse);
- controller.stop();
- });
- test('media state supplies the title, progress and playing flag', () async {
- final platform = _MediaPlatform()
- ..media = const MediaPlayback(
- hasAccess: true,
- hasSession: true,
- playing: true,
- title: 'Night Drive',
- artist: 'The Dashboard',
- durationMs: 240000,
- positionMs: 60000,
- );
- final controller = SystemController(platform);
- await controller.start();
- addTearDown(controller.dispose);
- expect(controller.hasMediaAccess, isTrue);
- expect(controller.media.displayTitle, 'Night Drive — The Dashboard');
- expect(controller.media.progress, 0.25);
- expect(controller.isMusicPlaying, isTrue);
- controller.stop();
- });
- test('play resumes and reports whether audio started', () async {
- final platform = _MediaPlatform();
- final controller = SystemController(platform);
- await controller.start();
- addTearDown(controller.dispose);
- expect(controller.isMusicPlaying, isFalse);
- expect(await controller.playMusic(), isTrue);
- expect(platform.keys, contains('play'));
- expect(controller.isMusicPlaying, isTrue);
- controller.stop();
- });
- }
|