Files
plezy/test/mixins/library_tab_state_test.dart
T
edde746 316a69a1de refactor: share the paginated grid tab, cached remote store, and tile focus
- PaginatedCardGridTabState: the collections and playlists tabs were 95%
  identical; they now supply only pageSize/fetchPage/idOf instead of each
  duplicating the grid, memo, inflation budget and focus wiring.
- EtagCachedRemoteStore: the anime-lists and fribb mapping stores now share
  one download/cache/isolate-parse/conditional-GET lifecycle.
- FocusableTileStateMixin manages its own initState/didUpdateWidget/dispose
  instead of requiring every caller to forward three lifecycle hooks.

Also drops unused ServerCapabilities entries and dead code in
focusable_list_tile and music/track_row.
2026-07-26 06:09:48 +02:00

69 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:plezy/media/ids.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/media/media_backend.dart';
import 'package:plezy/media/media_kind.dart';
import 'package:plezy/media/media_library.dart';
import 'package:plezy/mixins/library_tab_state.dart';
import 'package:provider/provider.dart';
import 'package:plezy/providers/multi_server_provider.dart';
import 'package:plezy/services/multi_server_manager.dart';
import '../test_helpers/multi_server_fixtures.dart';
class _Probe extends StatefulWidget {
const _Probe({required this.library, required this.onState});
final MediaLibrary library;
final void Function(_ProbeState state) onState;
@override
State<_Probe> createState() => _ProbeState();
}
class _ProbeState extends State<_Probe> with LibraryTabStateMixin<_Probe> {
@override
MediaLibrary get library => widget.library;
@override
Widget build(BuildContext context) {
// Surface state after the first frame so tests receive a mounted probe.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) widget.onState(this);
});
return const SizedBox.shrink();
}
}
MediaLibrary _lib({ServerId? serverId, String key = '1'}) =>
MediaLibrary(id: key, backend: MediaBackend.plex, title: 'Movies', kind: MediaKind.movie, serverId: serverId);
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('LibraryTabStateMixin', () {
testWidgets('getClientForLibrary throws when no server matches and no fallback online', (tester) async {
late _ProbeState state;
final manager = MultiServerManager();
final provider = testMultiServerProvider(manager);
// provider.dispose() cascades to manager.dispose() — only register
// the outer teardown to avoid a double-close on the manager's stream.
addTearDown(provider.dispose);
await tester.pumpWidget(
ChangeNotifierProvider<MultiServerProvider>.value(
value: provider,
child: _Probe(
library: _lib(serverId: ServerId('srv-missing')),
onState: (s) => state = s,
),
),
);
await tester.pump();
expect(() => state.getClientForLibrary(), throwsA(isA<Exception>()));
});
});
}