mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-02 17:18:36 +02:00
fix(library): retain history during active downloads
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:spotiflac_android/screens/queue_library_refresh_policy.dart';
|
||||
import 'package:spotiflac_android/services/library_database.dart';
|
||||
|
||||
void main() {
|
||||
const empty = QueueLibraryCounts(
|
||||
allTrackCount: 0,
|
||||
albumCount: 0,
|
||||
singleTrackCount: 0,
|
||||
);
|
||||
const cached = QueueLibraryCounts(
|
||||
allTrackCount: 20,
|
||||
albumCount: 2,
|
||||
singleTrackCount: 3,
|
||||
);
|
||||
const fallback = QueueLibraryCounts(
|
||||
allTrackCount: 15,
|
||||
albumCount: 1,
|
||||
singleTrackCount: 4,
|
||||
);
|
||||
|
||||
test('keeps cached counts when a download refresh returns empty', () {
|
||||
final resolved = resolveQueueLibraryCountsSnapshot(
|
||||
current: empty,
|
||||
cached: cached,
|
||||
activeDownloadFallback: fallback,
|
||||
);
|
||||
|
||||
expect(identical(resolved, cached), isTrue);
|
||||
});
|
||||
|
||||
test('uses in-memory history when no page cache exists yet', () {
|
||||
final resolved = resolveQueueLibraryCountsSnapshot(
|
||||
current: empty,
|
||||
activeDownloadFallback: fallback,
|
||||
);
|
||||
|
||||
expect(identical(resolved, fallback), isTrue);
|
||||
});
|
||||
|
||||
test('allows a legitimate empty refresh without an active fallback', () {
|
||||
final resolved = resolveQueueLibraryCountsSnapshot(
|
||||
current: empty,
|
||||
cached: cached,
|
||||
);
|
||||
|
||||
expect(identical(resolved, empty), isTrue);
|
||||
expect(
|
||||
shouldRetainQueueLibraryPageSnapshot(
|
||||
currentIsEmpty: true,
|
||||
cachedHasContent: true,
|
||||
activeDownloadFallbackAvailable: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('retains a non-empty page only while its fallback is available', () {
|
||||
expect(
|
||||
shouldRetainQueueLibraryPageSnapshot(
|
||||
currentIsEmpty: true,
|
||||
cachedHasContent: true,
|
||||
activeDownloadFallbackAvailable: true,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
shouldRetainQueueLibraryPageSnapshot(
|
||||
currentIsEmpty: false,
|
||||
cachedHasContent: true,
|
||||
activeDownloadFallbackAvailable: true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user