fix(player): 修复详情往返播放位置丢失
This commit is contained in:
1 parent
fe49c6d8b2
commit
759a02375a
16 files changed
+464
-5
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_position_cache.dart';
|
||||
|
||||
void main() {
|
||||
test('should_store_and_read_recent_position_when_drama_matches', () {
|
||||
final now = DateTime(2026, 10, 22, 12);
|
||||
final cache = PlaybackPositionCache(now: () => now);
|
||||
|
||||
cache.save(
|
||||
episodeId: 'episode-3',
|
||||
dramaId: 'drama-a',
|
||||
position: const Duration(minutes: 1, seconds: 20),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
|
||||
final entry = cache.read('episode-3', dramaId: 'drama-a');
|
||||
expect(entry, isNotNull);
|
||||
expect(entry!.position, const Duration(minutes: 1, seconds: 20));
|
||||
expect(entry.duration, const Duration(minutes: 3));
|
||||
expect(entry.updatedAt, now);
|
||||
});
|
||||
|
||||
test('should_reject_cached_position_when_drama_does_not_match', () {
|
||||
final cache = PlaybackPositionCache();
|
||||
cache.save(
|
||||
episodeId: 'episode-3',
|
||||
dramaId: 'drama-a',
|
||||
position: const Duration(seconds: 80),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
|
||||
expect(cache.read('episode-3', dramaId: 'drama-b'), isNull);
|
||||
});
|
||||
|
||||
test('should_use_latest_saved_episode_when_timestamps_match', () {
|
||||
final now = DateTime(2026, 10, 22, 12);
|
||||
final cache = PlaybackPositionCache(now: () => now);
|
||||
cache.save(
|
||||
episodeId: 'episode-1',
|
||||
dramaId: 'drama-a',
|
||||
position: const Duration(seconds: 30),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
cache.save(
|
||||
episodeId: 'episode-2',
|
||||
dramaId: 'drama-a',
|
||||
position: const Duration(seconds: 45),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
|
||||
expect(cache.latestForDrama('drama-a')?.episodeId, 'episode-2');
|
||||
});
|
||||
|
||||
test('should_reject_expired_cached_position', () {
|
||||
var now = DateTime(2026, 10, 22, 12);
|
||||
final cache = PlaybackPositionCache(now: () => now);
|
||||
cache.save(
|
||||
episodeId: 'episode-3',
|
||||
dramaId: 'drama-a',
|
||||
position: const Duration(seconds: 80),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
now = now.add(const Duration(days: 1));
|
||||
|
||||
expect(cache.read('episode-3', dramaId: 'drama-a'), isNull);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user