Files
Melo/test/library/playlist_service_test.dart
T

43 lines
1.2 KiB
Dart

import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:melo/library/database.dart';
import 'package:melo/library/playlist_service.dart';
void main() {
late MeloDb db;
late PlaylistService service;
setUp(() {
db = MeloDb(NativeDatabase.memory());
service = PlaylistService(db);
});
tearDown(() async => db.close());
test('createPlaylist delegates to db and notifies listeners', () async {
var notified = false;
service.addListener(() => notified = true);
await service.createPlaylist('Road Trip');
final playlists = await db.watchPlaylists().first;
expect(playlists.length, 1);
expect(playlists.first.name, 'Road Trip');
expect(notified, true);
});
test('toggleFavorite delegates to db and notifies listeners', () async {
await db.into(db.songs).insert(SongsCompanion.insert(
id: 'song-1', path: '/a.mp3', title: 'A', dateAddedMs: 0, updatedAtMs: 0,
));
var notified = false;
service.addListener(() => notified = true);
await service.toggleFavorite('song-1');
expect(await db.watchIsFavorite('song-1').first, true);
expect(notified, true);
});
}