jellyfin_album_screen_test.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'package:cardash_launcher/core/theme/app_theme.dart';
  2. import 'package:cardash_launcher/data/services/jellyfin_library_service.dart';
  3. import 'package:cardash_launcher/features/home/system_controller.dart';
  4. import 'package:cardash_launcher/features/jellyfin/jellyfin_album_screen.dart';
  5. import 'package:cardash_launcher/features/jellyfin/jellyfin_playback_controller.dart';
  6. import 'package:cardash_launcher/features/settings/jellyfin_controller.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_test/flutter_test.dart';
  9. import 'package:provider/provider.dart';
  10. import 'jellyfin_fakes.dart';
  11. void main() {
  12. testWidgets('shows the album, track list and transport, and changes tracks', (
  13. tester,
  14. ) async {
  15. await tester.binding.setSurfaceSize(const Size(1280, 800));
  16. addTearDown(() => tester.binding.setSurfaceSize(null));
  17. final jellyfin = await configuredJellyfinController();
  18. final gateway = FakeJellyfinLibraryGateway()
  19. ..albumFavorite = true
  20. ..tracks = {
  21. 'album-1': [
  22. track('t1', albumId: 'album-1', albumName: 'Album 1', index: 1),
  23. track('t2', albumId: 'album-1', albumName: 'Album 1', index: 2),
  24. track('t3', albumId: 'album-1', albumName: 'Album 1', index: 3),
  25. ],
  26. };
  27. final library = JellyfinLibraryService(
  28. connectionProvider: () => jellyfin.connection,
  29. gateway: gateway,
  30. );
  31. final platform = FakeJellyfinPlaybackPlatform();
  32. final playback = JellyfinPlaybackController(
  33. platform,
  34. library,
  35. jellyfin,
  36. pollInterval: const Duration(hours: 1),
  37. );
  38. await playback.playAlbum(album('album-1'));
  39. final system = SystemController(FakeSystemPlatform());
  40. await tester.pumpWidget(
  41. MultiProvider(
  42. providers: [
  43. Provider<JellyfinLibraryService>.value(value: library),
  44. ChangeNotifierProvider<JellyfinController>.value(value: jellyfin),
  45. ChangeNotifierProvider<JellyfinPlaybackController>.value(
  46. value: playback,
  47. ),
  48. ChangeNotifierProvider<SystemController>.value(value: system),
  49. ],
  50. child: MaterialApp(
  51. theme: AppTheme.light(),
  52. home: JellyfinAlbumScreen(album: album('album-1')),
  53. ),
  54. ),
  55. );
  56. await tester.pumpAndSettle();
  57. expect(find.text('Album album-1'), findsOneWidget);
  58. expect(find.text('Tracks'), findsOneWidget);
  59. expect(find.text('Track t1'), findsWidgets);
  60. expect(find.text('Track t2'), findsOneWidget);
  61. expect(find.text('Track t3'), findsOneWidget);
  62. expect(find.text('Now playing'), findsOneWidget);
  63. expect(find.byType(Slider), findsOneWidget);
  64. expect(find.bySemanticsLabel('Previous track'), findsOneWidget);
  65. expect(find.bySemanticsLabel('Pause music'), findsOneWidget);
  66. expect(find.bySemanticsLabel('Next track'), findsOneWidget);
  67. expect(find.bySemanticsLabel('Volume down'), findsOneWidget);
  68. expect(find.bySemanticsLabel('Volume up'), findsOneWidget);
  69. expect(find.bySemanticsLabel('Remove from favorites'), findsOneWidget);
  70. expect(tester.takeException(), isNull);
  71. await tester.drag(find.byType(Slider), const Offset(120, 0));
  72. await tester.pumpAndSettle();
  73. expect(
  74. platform.commands.any((command) => command.startsWith('seek:')),
  75. isTrue,
  76. );
  77. await tester.tap(find.bySemanticsLabel('Remove from favorites'));
  78. await tester.pumpAndSettle();
  79. expect(gateway.setFavoriteCalls, 1);
  80. expect(gateway.lastFavoriteValue, isFalse);
  81. expect(find.bySemanticsLabel('Add to favorites'), findsOneWidget);
  82. await tester.tap(find.bySemanticsLabel('Next track'));
  83. await tester.pumpAndSettle();
  84. expect(platform.commands, contains('next'));
  85. expect(playback.currentItem?.trackId, 't2');
  86. expect(find.text('Track t2'), findsWidgets);
  87. await tester.tap(find.text('Track t3'));
  88. await tester.pumpAndSettle();
  89. expect(platform.commands, contains('seekToIndex:2'));
  90. expect(playback.currentItem?.trackId, 't3');
  91. await tester.tap(find.bySemanticsLabel('Previous track'));
  92. await tester.pumpAndSettle();
  93. expect(platform.commands, contains('previous'));
  94. expect(playback.currentItem?.trackId, 't2');
  95. await tester.pumpWidget(const SizedBox.shrink());
  96. playback.dispose();
  97. jellyfin.dispose();
  98. system.dispose();
  99. });
  100. }