| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import 'package:cardash_launcher/core/theme/app_theme.dart';
- import 'package:cardash_launcher/data/services/jellyfin_library_service.dart';
- import 'package:cardash_launcher/features/home/system_controller.dart';
- import 'package:cardash_launcher/features/jellyfin/jellyfin_album_screen.dart';
- import 'package:cardash_launcher/features/jellyfin/jellyfin_playback_controller.dart';
- import 'package:cardash_launcher/features/settings/jellyfin_controller.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_test/flutter_test.dart';
- import 'package:provider/provider.dart';
- import 'jellyfin_fakes.dart';
- void main() {
- testWidgets('shows the album, track list and transport, and changes tracks', (
- tester,
- ) async {
- await tester.binding.setSurfaceSize(const Size(1280, 800));
- addTearDown(() => tester.binding.setSurfaceSize(null));
- final jellyfin = await configuredJellyfinController();
- final gateway = FakeJellyfinLibraryGateway()
- ..albumFavorite = true
- ..tracks = {
- 'album-1': [
- track('t1', albumId: 'album-1', albumName: 'Album 1', index: 1),
- track('t2', albumId: 'album-1', albumName: 'Album 1', index: 2),
- track('t3', albumId: 'album-1', albumName: 'Album 1', index: 3),
- ],
- };
- final library = JellyfinLibraryService(
- connectionProvider: () => jellyfin.connection,
- gateway: gateway,
- );
- final platform = FakeJellyfinPlaybackPlatform();
- final playback = JellyfinPlaybackController(
- platform,
- library,
- jellyfin,
- pollInterval: const Duration(hours: 1),
- );
- final albumOne = album('album-1', year: 2025);
- await playback.playAlbum(albumOne);
- final system = SystemController(FakeSystemPlatform());
- await tester.pumpWidget(
- MultiProvider(
- providers: [
- Provider<JellyfinLibraryService>.value(value: library),
- ChangeNotifierProvider<JellyfinController>.value(value: jellyfin),
- ChangeNotifierProvider<JellyfinPlaybackController>.value(
- value: playback,
- ),
- ChangeNotifierProvider<SystemController>.value(value: system),
- ],
- child: MaterialApp(
- theme: AppTheme.light(),
- home: JellyfinAlbumScreen(album: albumOne),
- ),
- ),
- );
- await tester.pumpAndSettle();
- expect(find.text('Album album-1 (2025)'), findsOneWidget);
- expect(find.text('Tracks'), findsOneWidget);
- expect(find.text('Track t1'), findsWidgets);
- expect(find.text('Track t2'), findsOneWidget);
- expect(find.text('Track t3'), findsOneWidget);
- expect(find.text('Now playing'), findsOneWidget);
- expect(find.byType(Slider), findsOneWidget);
- expect(find.bySemanticsLabel('Previous track'), findsOneWidget);
- expect(find.bySemanticsLabel('Pause music'), findsOneWidget);
- expect(find.bySemanticsLabel('Next track'), findsOneWidget);
- expect(find.bySemanticsLabel('Volume down'), findsOneWidget);
- expect(find.bySemanticsLabel('Volume up'), findsOneWidget);
- expect(find.bySemanticsLabel('Remove from favorites'), findsOneWidget);
- final coverRect = tester.getRect(
- find.byKey(const ValueKey('jellyfin-album-cover')),
- );
- final cardRect = tester.getRect(
- find.byKey(const ValueKey('jellyfin-album-progress-card')),
- );
- expect(cardRect.bottom, moreOrLessEquals(coverRect.bottom, epsilon: 0.5));
- expect(tester.takeException(), isNull);
- await tester.drag(find.byType(Slider), const Offset(120, 0));
- await tester.pumpAndSettle();
- expect(
- platform.commands.any((command) => command.startsWith('seek:')),
- isTrue,
- );
- await tester.tap(find.bySemanticsLabel('Remove from favorites'));
- await tester.pumpAndSettle();
- expect(gateway.setFavoriteCalls, 1);
- expect(gateway.lastFavoriteValue, isFalse);
- expect(find.bySemanticsLabel('Add to favorites'), findsOneWidget);
- await tester.tap(find.bySemanticsLabel('Next track'));
- await tester.pumpAndSettle();
- expect(platform.commands, contains('next'));
- expect(playback.currentItem?.trackId, 't2');
- expect(find.text('Track t2'), findsWidgets);
- await tester.tap(find.text('Track t3'));
- await tester.pumpAndSettle();
- expect(platform.commands, contains('seekToIndex:2'));
- expect(playback.currentItem?.trackId, 't3');
- await tester.tap(find.bySemanticsLabel('Previous track'));
- await tester.pumpAndSettle();
- expect(platform.commands, contains('previous'));
- expect(playback.currentItem?.trackId, 't2');
- await tester.binding.setSurfaceSize(const Size(1024, 600));
- await tester.pumpAndSettle();
- final narrowCover = tester.getRect(
- find.byKey(const ValueKey('jellyfin-album-cover')),
- );
- final narrowCard = tester.getRect(
- find.byKey(const ValueKey('jellyfin-album-progress-card')),
- );
- expect(
- narrowCard.bottom,
- moreOrLessEquals(narrowCover.bottom, epsilon: 0.5),
- );
- expect(tester.takeException(), isNull);
- await tester.pumpWidget(const SizedBox.shrink());
- playback.dispose();
- jellyfin.dispose();
- system.dispose();
- });
- }
|