import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:melo/library/database.dart'; import 'package:melo/player/audio_handler.dart'; void main() { group('shouldCountPlay', () { test('zählt einen neu gestarteten Titel', () { expect(shouldCountPlay(0, null), isTrue); expect(shouldCountPlay(3, 2), isTrue); }); test('zählt denselben Titel nicht mehrfach', () { expect(shouldCountPlay(2, 2), isFalse); }); test('zählt nicht ohne aktuellen Titel', () { expect(shouldCountPlay(null, 1), isFalse); }); }); group('MeloDb.incrementPlayCount', () { late MeloDb db; setUp(() => db = MeloDb(NativeDatabase.memory())); tearDown(() => db.close()); test('erhöht den Zähler des Songs um eins', () async { await db.upsertSongs([ SongsCompanion.insert( id: '1', path: '/a.mp3', title: 'Song A', dateAddedMs: 0, updatedAtMs: 0, ), ]); await db.incrementPlayCount('1'); await db.incrementPlayCount('1'); final song = (await db.watchSongs().first).single; expect(song.playCount, 2); }); test('lässt andere Songs unberührt', () async { await db.upsertSongs([ SongsCompanion.insert( id: '1', path: '/a.mp3', title: 'A', dateAddedMs: 0, updatedAtMs: 0), SongsCompanion.insert( id: '2', path: '/b.mp3', title: 'B', dateAddedMs: 0, updatedAtMs: 0), ]); await db.incrementPlayCount('1'); final songs = await db.watchSongs().first; expect(songs.firstWhere((s) => s.id == '1').playCount, 1); expect(songs.firstWhere((s) => s.id == '2').playCount, 0); }); }); }