mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-18 07:42:22 +02:00
fix(download): compare size estimates at each quality tier
This commit is contained in:
@@ -22,6 +22,7 @@ class _PickerExtensions extends ExtensionNotifier {
|
||||
hasDownloadProvider: true,
|
||||
qualityOptions: [
|
||||
QualityOption(id: 'LOSSLESS', label: 'Lossless'),
|
||||
QualityOption(id: 'HI_RES', label: 'Hi-Res'),
|
||||
QualityOption(id: 'HI_RES_LOSSLESS', label: 'Hi-Res'),
|
||||
],
|
||||
),
|
||||
@@ -106,13 +107,16 @@ void main() {
|
||||
duration: const Duration(minutes: 4),
|
||||
onSelect: (quality, service) => selected = (quality, service),
|
||||
);
|
||||
expect(find.text('≈ 20.2 MB–32.3 MB'), findsOneWidget);
|
||||
expect(find.text('≈ 20.2 MB–210.9 MB'), findsOneWidget);
|
||||
expect(find.text('≈ 26.2 MB'), findsOneWidget);
|
||||
expect(find.text('≈ 85.7 MB if 24-bit/96kHz'), findsOneWidget);
|
||||
expect(find.text('≈ 171.4 MB if 24-bit/192kHz'), findsOneWidget);
|
||||
expect(find.textContaining('MB–'), findsNothing);
|
||||
await tester.tap(find.text('Audio B'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('≈ 7.3 MB'), findsOneWidget);
|
||||
expect(find.text('Size estimate unavailable'), findsOneWidget);
|
||||
expect(find.text('≈ 20.2 MB–32.3 MB'), findsNothing);
|
||||
expect(find.text('≈ 26.2 MB'), findsNothing);
|
||||
expect(find.textContaining('if 24-bit'), findsNothing);
|
||||
await tester.tap(find.text('Opus 256kbps'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, ('opus_256', 'provider-b'));
|
||||
@@ -123,7 +127,7 @@ void main() {
|
||||
'missing duration stays unknown and downloads remain selectable',
|
||||
(tester) async {
|
||||
await _openPicker(tester, locale: const Locale('id'));
|
||||
expect(find.text('Estimasi ukuran belum tersedia'), findsNWidgets(2));
|
||||
expect(find.text('Estimasi ukuran belum tersedia'), findsNWidgets(3));
|
||||
expect(find.textContaining('≈'), findsNothing);
|
||||
await tester.tap(find.text('FLAC Lossless'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -131,6 +135,18 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('capped estimates show their quality assumption in Indonesian', (
|
||||
tester,
|
||||
) async {
|
||||
await _openPicker(
|
||||
tester,
|
||||
duration: const Duration(minutes: 4),
|
||||
locale: const Locale('id'),
|
||||
);
|
||||
expect(find.text('≈ 85.7 MB jika 24-bit/96kHz'), findsOneWidget);
|
||||
expect(find.text('≈ 171.4 MB jika 24-bit/192kHz'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'conversion estimate is separate and fits narrow, enlarged text',
|
||||
(tester) async {
|
||||
@@ -148,7 +164,7 @@ void main() {
|
||||
autoConvertBitrate: '256k',
|
||||
),
|
||||
);
|
||||
expect(find.text('≈ 20.2 MB–32.3 MB'), findsOneWidget);
|
||||
expect(find.text('≈ 26.2 MB'), findsOneWidget);
|
||||
final conversionNote = find.textContaining(
|
||||
'After conversion to OPUS: ≈ 7.3 MB',
|
||||
);
|
||||
|
||||
@@ -29,38 +29,37 @@ void main() {
|
||||
duration: duration,
|
||||
quality: quality,
|
||||
)!;
|
||||
expect(estimate.minBytes, 7680000);
|
||||
expect(estimate.maxBytes, 7680000);
|
||||
expect(estimate.bytes, 7680000);
|
||||
expect(estimate.assumedBitDepth, isNull);
|
||||
expect(estimate.assumedSampleRate, isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'lossless range scales with duration and includes lower capped tiers',
|
||||
() {
|
||||
const cd = QualityOption(id: 'LOSSLESS', label: 'Lossless');
|
||||
final cdSize = estimateDownloadSize(duration: duration, quality: cd)!;
|
||||
expect(cdSize.minBytes, 21168000);
|
||||
expect(cdSize.maxBytes, 33868800);
|
||||
final batchSize = estimateDownloadSize(
|
||||
duration: totalDownloadDuration([_track(240), _track(240)]),
|
||||
quality: cd,
|
||||
)!;
|
||||
expect(batchSize.minBytes, cdSize.minBytes * 2);
|
||||
expect(batchSize.maxBytes, cdSize.maxBytes * 2);
|
||||
test('lossless estimates compare each tier at its own quality', () {
|
||||
const cd = QualityOption(id: 'LOSSLESS', label: 'Lossless');
|
||||
final cdSize = estimateDownloadSize(duration: duration, quality: cd)!;
|
||||
expect(cdSize.bytes, 27518400);
|
||||
expect(cdSize.assumedSampleRate, isNull);
|
||||
final batchSize = estimateDownloadSize(
|
||||
duration: totalDownloadDuration([_track(240), _track(240)]),
|
||||
quality: cd,
|
||||
)!;
|
||||
expect(batchSize.bytes, cdSize.bytes * 2);
|
||||
|
||||
for (final (id, maximum) in [
|
||||
('HI_RES', 110592000),
|
||||
('HI_RES_LOSSLESS', 221184000),
|
||||
]) {
|
||||
final size = estimateDownloadSize(
|
||||
duration: duration,
|
||||
quality: QualityOption(id: id, label: ''),
|
||||
)!;
|
||||
expect(size.minBytes, cdSize.minBytes);
|
||||
expect(size.maxBytes, maximum);
|
||||
}
|
||||
},
|
||||
);
|
||||
for (final (id, rate, bytes) in [
|
||||
('HI_RES', 96000, 89856000),
|
||||
('HI_RES_LOSSLESS', 192000, 179712000),
|
||||
]) {
|
||||
final size = estimateDownloadSize(
|
||||
duration: duration,
|
||||
quality: QualityOption(id: id, label: ''),
|
||||
)!;
|
||||
expect(size.bytes, bytes);
|
||||
expect(size.bytes, greaterThan(cdSize.bytes));
|
||||
expect(size.assumedBitDepth, 24);
|
||||
expect(size.assumedSampleRate, rate);
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'explicit parameters override legacy assumptions and preserve channels',
|
||||
@@ -74,8 +73,9 @@ void main() {
|
||||
duration: duration,
|
||||
quality: quality,
|
||||
)!;
|
||||
expect(estimate.minBytes, 17280000);
|
||||
expect(estimate.maxBytes, 27648000);
|
||||
expect(estimate.bytes, 22464000);
|
||||
expect(estimate.assumedBitDepth, isNull);
|
||||
expect(estimate.assumedSampleRate, isNull);
|
||||
final capped = estimateDownloadSize(
|
||||
duration: duration,
|
||||
quality: QualityOption.fromJson({
|
||||
@@ -88,8 +88,9 @@ void main() {
|
||||
},
|
||||
}),
|
||||
)!;
|
||||
expect(capped.minBytes, 21168000);
|
||||
expect(capped.maxBytes, 221184000);
|
||||
expect(capped.bytes, 179712000);
|
||||
expect(capped.assumedBitDepth, 24);
|
||||
expect(capped.assumedSampleRate, 192000);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user