feat(flutter/track-actions): AddToPlaylistSheet picker

Modal bottom sheet listing the caller's user-created playlists (system
playlists like For-You are filtered out — they're not user-mutable).
Tap a row to pop with the playlist id; consumer (TrackActionsSheet)
then calls PlaylistsApi.appendTracks.

Empty-state copy: "You haven't created any playlists yet."

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 13:42:19 -04:00
parent 2944288050
commit 36006d703d
2 changed files with 208 additions and 0 deletions
@@ -0,0 +1,114 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:minstrel/api/endpoints/playlists.dart';
import 'package:minstrel/models/playlist.dart';
import 'package:minstrel/playlists/playlists_provider.dart';
import 'package:minstrel/shared/widgets/track_actions/add_to_playlist_sheet.dart';
import 'package:minstrel/theme/theme_data.dart';
const _userPlaylist = Playlist(
id: 'p1',
userId: 'u1',
name: 'Road trip',
description: '',
isPublic: false,
systemVariant: null,
trackCount: 12,
coverUrl: '',
ownerUsername: 'alice',
createdAt: '2026-05-01T00:00:00Z',
updatedAt: '2026-05-01T00:00:00Z',
);
const _systemPlaylist = Playlist(
id: 'p2',
userId: 'u1',
name: 'For You',
description: '',
isPublic: false,
systemVariant: 'for_you',
trackCount: 75,
coverUrl: '',
ownerUsername: 'alice',
createdAt: '2026-05-01T00:00:00Z',
updatedAt: '2026-05-01T00:00:00Z',
);
Widget _harness(PlaylistsList lists) {
return ProviderScope(
overrides: [
playlistsListProvider('user').overrideWith((ref) async => lists),
],
child: MaterialApp(
theme: buildThemeData(),
home: Builder(builder: (ctx) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () => AddToPlaylistSheet.show(ctx),
child: const Text('open'),
),
),
);
}),
),
);
}
void main() {
testWidgets('renders user playlists, hides system ones', (t) async {
await t.pumpWidget(_harness(
const PlaylistsList(owned: [_userPlaylist, _systemPlaylist], public: []),
));
await t.tap(find.text('open'));
await t.pumpAndSettle();
expect(find.text('Road trip'), findsOneWidget);
expect(find.text('For You'), findsNothing);
});
testWidgets('empty state when no user playlists', (t) async {
await t.pumpWidget(_harness(
const PlaylistsList(owned: [_systemPlaylist], public: []),
));
await t.tap(find.text('open'));
await t.pumpAndSettle();
expect(
find.text("You haven't created any playlists yet."),
findsOneWidget,
);
});
testWidgets('tapping a row pops with playlist id', (t) async {
String? picked;
await t.pumpWidget(ProviderScope(
overrides: [
playlistsListProvider('user').overrideWith(
(ref) async =>
const PlaylistsList(owned: [_userPlaylist], public: []),
),
],
child: MaterialApp(
theme: buildThemeData(),
home: Builder(builder: (ctx) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () async {
picked = await AddToPlaylistSheet.show(ctx);
},
child: const Text('open'),
),
),
);
}),
),
));
await t.tap(find.text('open'));
await t.pumpAndSettle();
await t.tap(find.byKey(const Key('add_to_playlist_p1')));
await t.pumpAndSettle();
expect(picked, 'p1');
});
}