Merge pull request #678 from zjs81/feat/chat-compression-selector

Add in-chat compression selector
This commit is contained in:
zjs81 authored and GitHub committed 2026-11-20 21:15:51 -07:00
commit 173c8db9cc
38 files changed
+2331 -551

No files matched your search

+3 -2
View File
@@ -7,6 +7,7 @@ import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/models/channel.dart';
import 'package:meshcore_open/models/channel_message.dart';
import 'package:meshcore_open/models/chat_compression_mode.dart';
import 'package:meshcore_open/review_mode/review_frames.dart';
import 'package:meshcore_open/review_mode/review_radio.dart';
import 'package:meshcore_open/review_mode/review_script.dart';
@@ -201,7 +202,7 @@ void main() {
'another slot brings its history back', () async {
await _connect(_TestRadio());
await _waitFor(() => _texts(1).contains(_queuedHikingText));
await _connector.setChannelSmazEnabled(1, true);
await _connector.setChannelCompressionMode(1, ChatCompressionMode.smaz);
await _connector.setChannel(1, 'Hiking Group', ghostPsk);
expect(_connector.channelIdForSlot(1), ghostId);
@@ -408,7 +409,7 @@ void main() {
expect(_texts(5), _texts(1));
// Settings are stored per channel, so both slots see a change.
await _connector.setChannelSmazEnabled(5, true);
await _connector.setChannelCompressionMode(5, ChatCompressionMode.smaz);
expect(_connector.isChannelSmazEnabled(1), isTrue);
await _connector.setChannelRegion(1, 'test-region');
expect(_connector.getChannelRegion(5), 'test-region');
@@ -0,0 +1,163 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/models/chat_compression_mode.dart';
import 'package:meshcore_open/review_mode/review_radio.dart';
import 'package:meshcore_open/services/message_retry_service.dart';
import 'package:meshcore_open/services/path_history_service.dart';
import 'package:meshcore_open/services/storage_service.dart';
import 'package:meshcore_open/storage/channel_settings_store.dart';
import 'package:meshcore_open/storage/contact_settings_store.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _contactKey =
'1111111111111111111111111111111111111111111111111111111111111111';
Future<void> _waitFor(bool Function() condition) async {
final end = DateTime.now().add(const Duration(seconds: 8));
while (!condition()) {
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
await Future<void>.delayed(const Duration(milliseconds: 20));
}
}
ContactSettingsStore _contactStore() =>
ContactSettingsStore()..setPublicKeyHex = ReviewRadio.selfPublicKeyHex;
ChannelSettingsStore _channelStore() =>
ChannelSettingsStore()..setPublicKeyHex = ReviewRadio.selfPublicKeyHex;
Future<(bool, bool)> _savedContactFlags() async => (
await _contactStore().loadSmazEnabled(_contactKey),
await _contactStore().loadCyr2LatEnabled(_contactKey),
);
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late MeshCoreConnector connector;
// The connector's frame streams can only be listened to once per process,
// so the tests share one connected review radio.
setUpAll(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
connector = MeshCoreConnector();
final retryService = MessageRetryService();
connector.initialize(
retryService: retryService,
pathHistoryService: PathHistoryService(StorageService()),
);
connector.reviewRadioFactoryForTest = () => ReviewRadio(
scheduledMessageInterval: const Duration(hours: 1),
ackDelay: const Duration(hours: 1),
replyDelay: const Duration(hours: 1),
);
await connector.connectReview();
await _waitFor(() => connector.channelMapConfirmed);
addTearDown(() async {
await connector.disconnect();
connector.dispose();
retryService.dispose();
});
});
test('contact modes are mutually exclusive and saved', () async {
expect(
connector.contactCompressionMode(_contactKey),
ChatCompressionMode.off,
);
await connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.smaz,
);
expect(connector.isContactSmazEnabled(_contactKey), isTrue);
expect(connector.isContactCyr2LatEnabled(_contactKey), isFalse);
expect(await _savedContactFlags(), (true, false));
await connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.cyr2lat,
);
expect(
connector.contactCompressionMode(_contactKey),
ChatCompressionMode.cyr2lat,
);
expect(connector.isContactSmazEnabled(_contactKey), isFalse);
expect(await _savedContactFlags(), (false, true));
await connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.off,
);
expect(
connector.contactCompressionMode(_contactKey),
ChatCompressionMode.off,
);
expect(await _savedContactFlags(), (false, false));
});
test('overlapping contact choices end on the last one, never both', () async {
final writes = [
connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.smaz,
),
connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.cyr2lat,
),
connector.setContactCompressionMode(
_contactKey,
ChatCompressionMode.smaz,
),
];
await Future.wait(writes);
expect(
connector.contactCompressionMode(_contactKey),
ChatCompressionMode.smaz,
);
expect(connector.isContactCyr2LatEnabled(_contactKey), isFalse);
expect(await _savedContactFlags(), (true, false));
});
test(
'channel modes are mutually exclusive and saved by channel ID',
() async {
final channelId = connector.channelIdForSlot(1)!;
await connector.setChannelCompressionMode(1, ChatCompressionMode.cyr2lat);
expect(connector.channelCompressionMode(1), ChatCompressionMode.cyr2lat);
expect(await _channelStore().loadCyr2LatEnabled(channelId), isTrue);
expect(await _channelStore().loadSmazEnabled(channelId), isFalse);
await connector.setChannelCompressionMode(1, ChatCompressionMode.smaz);
expect(connector.channelCompressionMode(1), ChatCompressionMode.smaz);
expect(connector.isChannelCyr2LatEnabled(1), isFalse);
expect(await _channelStore().loadCyr2LatEnabled(channelId), isFalse);
expect(await _channelStore().loadSmazEnabled(channelId), isTrue);
// Other channels are untouched.
expect(connector.channelCompressionMode(0), ChatCompressionMode.off);
},
);
test('a channel slot without a storage ID is refused', () async {
const emptySlot = 30;
expect(connector.channelIdForSlot(emptySlot), isNull);
await expectLater(
connector.setChannelCompressionMode(emptySlot, ChatCompressionMode.smaz),
throwsStateError,
);
expect(
connector.channelCompressionMode(emptySlot),
ChatCompressionMode.off,
);
// A refused write does not block later ones.
await connector.setChannelCompressionMode(1, ChatCompressionMode.smaz);
expect(connector.channelCompressionMode(1), ChatCompressionMode.smaz);
});
}
+246
View File
@@ -34,13 +34,17 @@ import 'package:meshcore_open/services/timeout_prediction_service.dart';
import 'package:meshcore_open/services/translation_service.dart';
import 'package:meshcore_open/services/ui_view_state_service.dart';
import 'package:meshcore_open/storage/channel_message_store.dart';
import 'package:meshcore_open/storage/channel_settings_store.dart';
import 'package:meshcore_open/storage/contact_settings_store.dart';
import 'package:meshcore_open/storage/channel_store.dart';
import 'package:meshcore_open/storage/contact_store.dart';
import 'package:meshcore_open/storage/last_radio_store.dart';
import 'package:meshcore_open/storage/message_store.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/chat_background.dart';
import 'package:meshcore_open/widgets/chat_composer.dart';
import 'package:meshcore_open/widgets/chat_compression_selector.dart';
import 'package:meshcore_open/widgets/connect_sheet.dart';
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
@@ -344,4 +348,246 @@ void main() {
await tester.pumpWidget(const SizedBox());
await tester.pump(const Duration(minutes: 1));
});
group('compression selector', () {
Future<void> choose(WidgetTester tester, String mode) async {
await tester.tap(find.byType(ChatCompressionSelector));
await _settle(tester);
await tester.tap(find.text(mode));
await _settle(tester);
// Connector notifications are debounced on a real timer.
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 200)),
);
await _settle(tester);
}
testWidgets('DM chat shows it at the top and saves offline', (
tester,
) async {
final connector = await _offlineConnector(tester);
final alice = connector.contacts.single;
final store = ContactSettingsStore()..setPublicKeyHex = _radioHex;
await tester.pumpWidget(
await _app(tester, connector, ChatScreen(contact: alice)),
);
await _settle(tester);
expect(find.byType(ChatCompressionSelector), findsOneWidget);
expect(find.text(_l10n.chatCompression_label('Off')), findsOneWidget);
// Above the transcript, outside its scroll view.
expect(
find.ancestor(
of: find.byType(ChatCompressionSelector),
matching: find.byType(Scrollable),
),
findsNothing,
);
expect(
tester.getBottomLeft(find.byType(ChatCompressionSelector)).dy,
lessThanOrEqualTo(tester.getTopLeft(find.byType(ChatBackdrop)).dy),
);
await choose(tester, _l10n.chatCompression_smaz);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
expect(
await tester.runAsync(() => store.loadSmazEnabled(alice.publicKeyHex)),
isTrue,
);
await choose(tester, _l10n.chatCompression_cyr2lat);
// Cyr2Lat keeps the sheet open for its profile picker.
await tester.tap(find.byTooltip('Close'));
await _settle(tester);
expect(find.text(_l10n.chatCompression_label('Cyr2Lat')), findsOneWidget);
expect(
connector.contactCompressionMode(alice.publicKeyHex),
ChatCompressionMode.cyr2lat,
);
expect(
await tester.runAsync(() => store.loadSmazEnabled(alice.publicKeyHex)),
isFalse,
);
expect(
await tester.runAsync(
() => store.loadCyr2LatEnabled(alice.publicKeyHex),
),
isTrue,
);
// The settings dialog no longer carries the compression switches.
await tester.tap(find.byIcon(Icons.more_vert));
await _settle(tester);
await tester.tap(find.text(_l10n.contact_settings).last);
await _settle(tester);
expect(find.byType(AlertDialog), findsOneWidget);
expect(
find.descendant(
of: find.byType(AlertDialog),
matching: find.textContaining(RegExp('SMAZ|Cyr2Lat')),
),
findsNothing,
);
await tester.pumpWidget(const SizedBox());
});
testWidgets('channel chat uses the same selector and saves offline', (
tester,
) async {
final connector = await _offlineConnector(tester);
final channel = connector.channels.single;
final store = ChannelSettingsStore()..setPublicKeyHex = _radioHex;
await tester.pumpWidget(
await _app(tester, connector, ChannelChatScreen(channel: channel)),
);
await _settle(tester);
expect(find.byType(ChatCompressionSelector), findsOneWidget);
expect(find.text(_l10n.chatCompression_label('Off')), findsOneWidget);
await choose(tester, _l10n.chatCompression_smaz);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
expect(
await tester.runAsync(() => store.loadSmazEnabled(channel.storageId!)),
isTrue,
);
expect(
await tester.runAsync(
() => store.loadCyr2LatEnabled(channel.storageId!),
),
isFalse,
);
await tester.pumpWidget(const SizedBox());
});
testWidgets('saving the channel edit sheet leaves compression alone', (
tester,
) async {
final connector = MeshCoreConnector();
addTearDown(connector.dispose);
connector.reviewRadioFactoryForTest = () => ReviewRadio(
scheduledMessageInterval: const Duration(hours: 1),
ackDelay: const Duration(hours: 1),
replyDelay: const Duration(hours: 1),
);
await tester.runAsync(connector.connectReview);
await _waitFor(tester, () => connector.channelMapConfirmed);
final channel = connector.channels.firstWhere((c) => c.index == 1);
await tester.runAsync(
() => connector.setChannelCompressionMode(1, ChatCompressionMode.smaz),
);
await tester.pumpWidget(
await _app(
tester,
connector,
Builder(
builder: (context) => Scaffold(
body: Center(
child: TextButton(
onPressed: () =>
showEditChannelSheet(context, connector, channel),
child: const Text('edit'),
),
),
),
),
),
);
await tester.tap(find.text('edit'));
await _settle(tester);
expect(find.text('SMAZ compression'), findsNothing);
// The chat's selector changes the mode while the sheet is open.
await tester.runAsync(
() =>
connector.setChannelCompressionMode(1, ChatCompressionMode.cyr2lat),
);
await tester.enterText(find.byType(TextField).first, 'Hiking Crew');
await tester.tap(find.text(_l10n.common_save));
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 500)),
);
await _settle(tester);
expect(
connector.channels.firstWhere((c) => c.index == 1).name,
'Hiking Crew',
);
expect(connector.channelCompressionMode(1), ChatCompressionMode.cyr2lat);
await tester.runAsync(connector.disconnect);
await tester.pumpWidget(const SizedBox());
await tester.pump(const Duration(minutes: 1));
});
testWidgets('a new PSK in the channel edit sheet keeps compression', (
tester,
) async {
final connector = MeshCoreConnector();
addTearDown(connector.dispose);
connector.reviewRadioFactoryForTest = () => ReviewRadio(
scheduledMessageInterval: const Duration(hours: 1),
ackDelay: const Duration(hours: 1),
replyDelay: const Duration(hours: 1),
);
await tester.runAsync(connector.connectReview);
await _waitFor(tester, () => connector.channelMapConfirmed);
final channel = connector.channels.firstWhere((c) => c.index == 1);
final oldId = connector.channelIdForSlot(1);
await tester.runAsync(
() => connector.setChannelCompressionMode(1, ChatCompressionMode.smaz),
);
await tester.pumpWidget(
await _app(
tester,
connector,
Builder(
builder: (context) => Scaffold(
body: Center(
child: TextButton(
onPressed: () =>
showEditChannelSheet(context, connector, channel),
child: const Text('edit'),
),
),
),
),
),
);
await tester.tap(find.text('edit'));
await _settle(tester);
await tester.enterText(find.byType(TextField).at(1), '0f' * 16);
await tester.tap(find.text(_l10n.common_save));
// The save runs in the test zone and waits on the radio's real I/O.
for (var i = 0; i < 40; i++) {
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 50)),
);
await tester.pump(const Duration(milliseconds: 100));
if (find
.text(_l10n.channels_channelUpdated(channel.name))
.evaluate()
.isNotEmpty) {
break;
}
}
await _settle(tester);
final newId = connector.channelIdForSlot(1);
expect(newId, isNot(oldId));
expect(connector.channelCompressionMode(1), ChatCompressionMode.smaz);
final store = ChannelSettingsStore()
..setPublicKeyHex = connector.selfPublicKeyHex;
expect(
await tester.runAsync(() => store.loadSmazEnabled(newId!)),
isTrue,
);
await tester.runAsync(connector.disconnect);
await tester.pumpWidget(const SizedBox());
await tester.pump(const Duration(minutes: 1));
});
});
}
@@ -0,0 +1,334 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/app_settings.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/chat_compression_selector.dart';
final _l10n = lookupAppLocalizations(const Locale('en'));
final _profiles = [
Cyr2LatProfile(id: 'ru', name: 'Russian', charMap: const {'А': 'A'}),
Cyr2LatProfile(id: 'sr', name: 'Serbian', charMap: const {'З': '3'}),
];
/// Stands in for a chat screen: keeps the "saved" state and applies a change
/// only when the test completes the pending write.
class _Host extends StatefulWidget {
final ChatCompressionMode initialMode;
final bool enabled;
final String? initialProfileId;
final List<ChatCompressionMode> modeCalls;
final List<String> profileCalls;
final List<Completer<void>> pending;
const _Host({
this.initialMode = ChatCompressionMode.off,
this.enabled = true,
this.initialProfileId,
required this.modeCalls,
required this.profileCalls,
required this.pending,
});
@override
State<_Host> createState() => _HostState();
}
class _HostState extends State<_Host> {
late ChatCompressionMode _mode = widget.initialMode;
late String? _profileId = widget.initialProfileId;
Future<void> _write(void Function() apply) async {
final completer = Completer<void>();
widget.pending.add(completer);
await completer.future;
if (mounted) setState(apply);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Chat')),
body: Column(
children: [
ChatCompressionSelector(
mode: _mode,
enabled: widget.enabled,
disabledReason: widget.enabled
? null
: _l10n.chatCompression_noStorageId,
profiles: _profiles,
profileId: _profileId,
defaultProfileId: 'ru',
onModeChanged: (mode) {
widget.modeCalls.add(mode);
return _write(() => _mode = mode);
},
onProfileChanged: (id) {
widget.profileCalls.add(id);
return _write(() => _profileId = id);
},
),
const Expanded(child: Placeholder()),
],
),
);
}
}
void main() {
late List<ChatCompressionMode> modeCalls;
late List<String> profileCalls;
late List<Completer<void>> pending;
setUp(() {
modeCalls = [];
profileCalls = [];
pending = [];
});
Future<void> pumpHost(
WidgetTester tester, {
ChatCompressionMode mode = ChatCompressionMode.off,
bool enabled = true,
String? profileId,
Size size = const Size(400, 800),
double textScale = 1.0,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
theme: MeshTheme.light(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: _Host(
initialMode: mode,
enabled: enabled,
initialProfileId: profileId,
modeCalls: modeCalls,
profileCalls: profileCalls,
pending: pending,
),
),
);
}
Future<void> openSheet(WidgetTester tester) async {
await tester.tap(find.byType(ChatCompressionSelector));
await tester.pumpAndSettle();
}
Finder optionRow(String label) =>
find.ancestor(of: find.text(label), matching: find.byType(ListTile));
bool isSelected(WidgetTester tester, String label) {
final row = optionRow(label);
return find
.descendant(of: row, matching: find.byIcon(Icons.radio_button_checked))
.evaluate()
.isNotEmpty;
}
testWidgets('shows the saved mode and announces it', (tester) async {
final semantics = tester.ensureSemantics();
await pumpHost(tester, mode: ChatCompressionMode.smaz);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
expect(
tester.getSemantics(
find.bySemanticsLabel(_l10n.chatCompression_label('SMAZ')),
),
isSemantics(
label: _l10n.chatCompression_label('SMAZ'),
hint: _l10n.chatCompression_changeHint,
isButton: true,
isEnabled: true,
hasTapAction: true,
),
);
expect(
tester.getSize(find.byType(ChatCompressionSelector)).height,
greaterThanOrEqualTo(48),
);
semantics.dispose();
});
testWidgets('one sheet lists the three modes with their explanations', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
expect(find.text(_l10n.chatCompression_title), findsOneWidget);
expect(find.text(_l10n.chatCompression_off), findsOneWidget);
expect(find.text(_l10n.chatCompression_smaz), findsOneWidget);
expect(find.text(_l10n.chatCompression_cyr2lat), findsOneWidget);
expect(find.text(_l10n.chatCompression_offDescription), findsOneWidget);
expect(find.text(_l10n.chatCompression_smazDescription), findsOneWidget);
expect(find.text(_l10n.chatCompression_cyr2latDescription), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_off), isTrue);
expect(isSelected(tester, _l10n.chatCompression_smaz), isFalse);
// No profile picker unless Cyr2Lat is chosen.
expect(find.text(_l10n.chatCompression_profile), findsNothing);
expect(find.byType(Dialog), findsNothing);
});
testWidgets('a choice shows only after it is saved, then the sheet closes', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_smaz));
await tester.pump();
expect(modeCalls, [ChatCompressionMode.smaz]);
// Still saving: old mode shown, options locked against rapid taps.
expect(isSelected(tester, _l10n.chatCompression_off), isTrue);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_cyr2lat)).enabled,
isFalse,
);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
expect(modeCalls, [ChatCompressionMode.smaz]);
pending.single.complete();
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_title), findsNothing);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
});
testWidgets('Cyr2Lat keeps the sheet open with its profile picker', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_title), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_cyr2lat), isTrue);
expect(find.text(_l10n.chatCompression_profile), findsOneWidget);
// No profile saved for the chat: the app-wide one is what sending uses.
expect(find.text('Russian'), findsOneWidget);
await tester.ensureVisible(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(profileCalls, ['sr']);
pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(find.text('Serbian'), findsOneWidget);
expect(find.text(_l10n.chatCompression_label('Cyr2Lat')), findsOneWidget);
});
testWidgets('a failed save keeps the saved mode and says so', (tester) async {
await pumpHost(tester, mode: ChatCompressionMode.smaz);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_smaz), isTrue);
expect(isSelected(tester, _l10n.chatCompression_cyr2lat), isFalse);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_off)).enabled,
isTrue,
);
await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
});
testWidgets('a failed profile save shows the saved profile again', (
tester,
) async {
await pumpHost(tester, mode: ChatCompressionMode.cyr2lat, profileId: 'ru');
await openSheet(tester);
await tester.ensureVisible(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(profileCalls, ['sr']);
pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
expect(find.text('Russian'), findsOneWidget);
expect(find.text('Serbian'), findsNothing);
});
testWidgets('disabled shows the saved mode, and the sheet says why and '
'allows no change', (tester) async {
final semantics = tester.ensureSemantics();
await pumpHost(tester, mode: ChatCompressionMode.smaz, enabled: false);
final label = _l10n.chatCompression_label('SMAZ');
expect(find.text(label), findsOneWidget);
expect(find.byIcon(Icons.lock_outline), findsOneWidget);
expect(
find.bySemanticsLabel('$label. ${_l10n.chatCompression_noStorageId}'),
findsOneWidget,
);
await openSheet(tester);
expect(find.text(_l10n.chatCompression_noStorageId), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_smaz), isTrue);
for (final mode in [
_l10n.chatCompression_off,
_l10n.chatCompression_smaz,
_l10n.chatCompression_cyr2lat,
]) {
expect(tester.widget<ListTile>(optionRow(mode)).enabled, isFalse);
}
await tester.tap(find.text(_l10n.chatCompression_off), warnIfMissed: false);
await tester.pumpAndSettle();
expect(modeCalls, isEmpty);
semantics.dispose();
});
for (final scale in [1.3, 2.0]) {
testWidgets('fits a 320dp phone at ${scale}x text', (tester) async {
await pumpHost(
tester,
mode: ChatCompressionMode.cyr2lat,
enabled: true,
size: const Size(320, 568),
textScale: scale,
);
expect(tester.takeException(), isNull);
await openSheet(tester);
expect(tester.takeException(), isNull);
// The sheet scrolls to its last option and the profile picker.
await tester.scrollUntilVisible(
find.text(_l10n.chatCompression_profile),
200,
scrollable: find.byType(Scrollable).last,
);
expect(tester.takeException(), isNull);
});
}
}