Files
plezy/test/widgets/setting_selection_tile_test.dart
T
edde746 9ac8002b53 feat(player): apply separate default quality on cellular connections
On mobile data the single default streaming quality either burns
through the user's data plan or permanently caps quality at home.
Playback start now applies a dedicated cellular default when the
device is on a cellular-only connection, read from the app's existing
single connectivity subscription. The new setting defaults to
following the general default, ships in Settings > Playback for
phones/tablets only, and explicit per-play quality picks still win.

'Metered connection' had been spelled out independently in the offline
provider, the download WiFi-only gate and the sync-rule cooldown.
Rather than add a fourth copy, all four now share
ConnectivityLinkType. Network *presence* is deliberately left alone:
its callers disagree on whether an empty snapshot counts as
connected, so folding that in would change behavior.

showSelectionDialog now returns the picked DialogOption instead of its
raw value so the tile's null-valued 'Same as Default Quality' option
stays distinguishable from dismissing the dialog.

close #2147
2026-08-27 14:14:01 +02:00

81 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:plezy/i18n/strings.g.dart';
import 'package:plezy/models/transcode_quality_preset.dart';
import 'package:plezy/screens/settings/settings_utils.dart';
import 'package:plezy/services/settings_service.dart';
import 'package:plezy/utils/quality_preset_labels.dart';
import 'package:plezy/widgets/setting_tile.dart';
import '../test_helpers/prefs.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
resetSharedPreferencesForTest();
SettingsService.resetForTesting();
await SettingsService.getInstance();
});
// The regression this defends: showSelectionDialog pops the picked
// DialogOption rather than its raw value, so choosing a null-valued option
// (the cellular tile's "Same as Default") stays distinguishable from
// dismissing the dialog.
group('SettingSelectionTile with a nullable pref', () {
Widget buildTile() {
return MaterialApp(
home: Scaffold(
body: SettingSelectionTile<TranscodeQualityPreset?>(
pref: SettingsService.cellularQualityPreset,
icon: Symbols.signal_cellular_alt_rounded,
title: t.settings.cellularQualityTitle,
subtitleBuilder: (p) => p == null ? t.settings.cellularQualitySameAsDefault : qualityPresetLabel(p),
options: [
DialogOption<TranscodeQualityPreset?>(value: null, title: t.settings.cellularQualitySameAsDefault),
...TranscodeQualityPreset.displayOrder.map(
(p) => DialogOption<TranscodeQualityPreset?>(value: p, title: qualityPresetLabel(p)),
),
],
),
),
);
}
testWidgets('picking a preset writes it, dismissing writes nothing', (tester) async {
final settings = SettingsService.instance;
await tester.pumpWidget(buildTile());
await tester.tap(find.text(t.settings.cellularQualityTitle));
await tester.pumpAndSettle();
await tester.tap(find.text(qualityPresetLabel(TranscodeQualityPreset.p720_2mbps)).last);
await tester.pumpAndSettle();
expect(settings.read(SettingsService.cellularQualityPreset), TranscodeQualityPreset.p720_2mbps);
// Dismissal via barrier must not touch the stored value.
await tester.tap(find.text(t.settings.cellularQualityTitle));
await tester.pumpAndSettle();
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
expect(settings.read(SettingsService.cellularQualityPreset), TranscodeQualityPreset.p720_2mbps);
});
testWidgets('picking the null option clears the stored value', (tester) async {
final settings = SettingsService.instance;
await settings.write(SettingsService.cellularQualityPreset, TranscodeQualityPreset.p1080_8mbps);
await tester.pumpWidget(buildTile());
await tester.tap(find.text(t.settings.cellularQualityTitle));
await tester.pumpAndSettle();
await tester.tap(find.text(t.settings.cellularQualitySameAsDefault).last);
await tester.pumpAndSettle();
expect(settings.read(SettingsService.cellularQualityPreset), isNull);
expect(settings.prefs.containsKey(SettingsService.cellularQualityPreset.key), isFalse);
});
});
}