Merge origin/dev into feat/bookmarks-ux-improvements
This commit is contained in:
commit
54ba703213
60 files changed
+2983
-1069
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
|
||||
void main() {
|
||||
// CMD_SET_AUTOADD_CONFIG: [cmd][flags][autoadd_max_hops?]. Firmware stores
|
||||
// the third byte (capped at 64) only when it is present.
|
||||
group('buildSetAutoAddConfigFrame', () {
|
||||
Iterable<int> frame({int? maxHops}) => buildSetAutoAddConfigFrame(
|
||||
autoAddChat: true,
|
||||
autoAddRepeater: false,
|
||||
autoAddRoomServer: true,
|
||||
autoAddSensor: false,
|
||||
overwriteOldest: true,
|
||||
maxHops: maxHops,
|
||||
);
|
||||
|
||||
const flags =
|
||||
autoAddChatFlag | autoAddRoomServerFlag | autoAddOverwriteOldestFlag;
|
||||
|
||||
test('omits the hop limit when not given', () {
|
||||
expect(frame(), [cmdSetAutoAddConfig, flags]);
|
||||
});
|
||||
|
||||
test('appends the hop limit, including 0 (no limit)', () {
|
||||
expect(frame(maxHops: 8), [cmdSetAutoAddConfig, flags, 8]);
|
||||
expect(frame(maxHops: 0), [cmdSetAutoAddConfig, flags, 0]);
|
||||
});
|
||||
|
||||
test('caps the hop limit at 64', () {
|
||||
expect(frame(maxHops: 200), [cmdSetAutoAddConfig, flags, 64]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/smaz.dart';
|
||||
|
||||
int _utf8Len(String s) => utf8.encode(s).length;
|
||||
|
||||
Uint8List _raw(String s) =>
|
||||
Smaz.compressBytes(Uint8List.fromList(utf8.encode(s)));
|
||||
|
||||
/// Sent size, raw SMAZ size and base64 wire size for [text].
|
||||
({int plain, int raw, int wire, int sent}) _measure(String text) {
|
||||
final raw = _raw(text);
|
||||
return (
|
||||
plain: _utf8Len(text),
|
||||
raw: raw.length,
|
||||
wire: _utf8Len('s:${base64Encode(raw)}'),
|
||||
sent: _utf8Len(Smaz.encodeIfSmaller(text)),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('compression results', () {
|
||||
test('lowercase English compresses well', () {
|
||||
const text = 'hello there, how are you doing today?';
|
||||
final m = _measure(text);
|
||||
expect((m.plain, m.raw, m.wire, m.sent), (37, 20, 30, 30));
|
||||
expect(Smaz.encodeIfSmaller(text), startsWith('s:'));
|
||||
});
|
||||
|
||||
test('sentence case compresses, a little less', () {
|
||||
const text = 'Hello there, how are you doing today?';
|
||||
final m = _measure(text);
|
||||
expect((m.plain, m.raw, m.wire, m.sent), (37, 22, 34, 34));
|
||||
expect(Smaz.encodeIfSmaller(text), startsWith('s:'));
|
||||
});
|
||||
|
||||
test('mixed case with many capitals barely compresses', () {
|
||||
const mixed = 'Meeting at Headquarters on Monday afternoon';
|
||||
const lower = 'meeting at headquarters on monday afternoon';
|
||||
expect(_measure(mixed).wire, 42);
|
||||
expect(_measure(mixed).plain, 43);
|
||||
expect(Smaz.encodeIfSmaller(mixed), startsWith('s:'));
|
||||
// The same words in lowercase save far more.
|
||||
expect(_measure(lower).wire, 34);
|
||||
expect(_measure(lower).raw, 24);
|
||||
// Each capital that is not in the codebook costs 2 bytes.
|
||||
expect(_measure(mixed).raw - _measure(lower).raw, 4);
|
||||
});
|
||||
|
||||
test('all caps is longer than the plain text, so it is sent plain', () {
|
||||
const text = 'HELLO THERE, HOW ARE YOU DOING TODAY?';
|
||||
final m = _measure(text);
|
||||
expect((m.plain, m.raw, m.wire, m.sent), (37, 50, 70, 37));
|
||||
expect(Smaz.encodeIfSmaller(text), text);
|
||||
});
|
||||
|
||||
test('a reply prefix costs the same in either case', () {
|
||||
expect(
|
||||
_raw('@[Alice] hello there, how are you?').length,
|
||||
_raw('@[alice] hello there, how are you?').length,
|
||||
);
|
||||
// 34 bytes plain, 34 bytes encoded: not strictly smaller, sent plain.
|
||||
const text = '@[Alice] hello there, how are you?';
|
||||
expect(_measure(text).wire, _measure(text).plain);
|
||||
expect(Smaz.encodeIfSmaller(text), text);
|
||||
});
|
||||
});
|
||||
|
||||
group('non-ASCII text', () {
|
||||
test('Cyrillic round-trips as raw bytes but is sent plain', () {
|
||||
const text = 'Привет, как дела сегодня?';
|
||||
final m = _measure(text);
|
||||
expect((m.plain, m.raw, m.wire, m.sent), (45, 52, 74, 45));
|
||||
expect(Smaz.encodeIfSmaller(text), text);
|
||||
// The byte-level codec is still lossless.
|
||||
expect(utf8.decode(Smaz.decompressBytes(_raw(text))), text);
|
||||
});
|
||||
|
||||
test('emoji survives a compressed round trip', () {
|
||||
const text =
|
||||
'see you soon 😀 the best of luck with the new house and the garden';
|
||||
final encoded = Smaz.encodeIfSmaller(text);
|
||||
expect(encoded, startsWith('s:'));
|
||||
expect(_utf8Len(encoded), lessThan(_utf8Len(text)));
|
||||
expect(Smaz.tryDecodePrefixed(encoded), text);
|
||||
});
|
||||
|
||||
test('a short emoji message is not smaller, so it is sent plain', () {
|
||||
const text = 'see you soon 😀 the best';
|
||||
final m = _measure(text);
|
||||
expect((m.plain, m.raw, m.wire, m.sent), (26, 17, 26, 26));
|
||||
expect(Smaz.encodeIfSmaller(text), text);
|
||||
});
|
||||
});
|
||||
|
||||
group('encodeIfSmaller falls back to plain text', () {
|
||||
test('short strings', () {
|
||||
for (final text in ['hi', 'ok', 'Hello', 'the']) {
|
||||
expect(Smaz.encodeIfSmaller(text), text, reason: text);
|
||||
}
|
||||
});
|
||||
|
||||
test('empty string', () {
|
||||
expect(Smaz.encodeIfSmaller(''), '');
|
||||
});
|
||||
|
||||
test('sent form is never longer than the plain text', () {
|
||||
for (final text in [
|
||||
'a',
|
||||
'Hello',
|
||||
'HELLO THERE, HOW ARE YOU DOING TODAY?',
|
||||
'the quick brown fox jumps over the lazy dog',
|
||||
'Привет, как дела?',
|
||||
'12345 67890',
|
||||
]) {
|
||||
expect(
|
||||
_utf8Len(Smaz.encodeIfSmaller(text)),
|
||||
lessThanOrEqualTo(_utf8Len(text)),
|
||||
reason: text,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('round trip', () {
|
||||
test('tryDecodePrefixed restores what encodeIfSmaller produced', () {
|
||||
for (final text in [
|
||||
'hello there, how are you doing today?',
|
||||
'Hello there, how are you doing today?',
|
||||
'Meeting at Headquarters on Monday afternoon',
|
||||
'the quick brown fox jumps over the lazy dog',
|
||||
'@[Alice] hello there, how are you doing today my friend?',
|
||||
]) {
|
||||
final encoded = Smaz.encodeIfSmaller(text);
|
||||
expect(encoded, startsWith('s:'), reason: text);
|
||||
expect(Smaz.tryDecodePrefixed(encoded), text, reason: text);
|
||||
}
|
||||
});
|
||||
|
||||
test('the decoder ignores leading whitespace', () {
|
||||
const text = 'hello there, how are you doing today?';
|
||||
expect(Smaz.tryDecodePrefixed(' ${Smaz.encodeIfSmaller(text)}'), text);
|
||||
});
|
||||
|
||||
test('plain text is not a compressed payload', () {
|
||||
expect(Smaz.tryDecodePrefixed('hello there'), isNull);
|
||||
expect(Smaz.tryDecodePrefixed('s:'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('"s:" guard', () {
|
||||
test('text that already starts with "s:" is never re-encoded', () {
|
||||
const text = 's:hello there, how are you doing today?';
|
||||
expect(Smaz.encodeIfSmaller(text), text);
|
||||
});
|
||||
|
||||
test('plain "s:" text is not mistaken for a compressed payload', () {
|
||||
expect(Smaz.tryDecodePrefixed('s:test'), isNull);
|
||||
expect(Smaz.tryDecodePrefixed('s:hello'), isNull);
|
||||
// Valid base64 that is not what the encoder would have produced.
|
||||
expect(Smaz.tryDecodePrefixed('s:AAAA'), isNull);
|
||||
});
|
||||
|
||||
test('malformed payloads return null instead of throwing', () {
|
||||
expect(Smaz.tryDecodePrefixed('s:!!!!'), isNull);
|
||||
// Truncated verbatim escape (0xFE with no byte after it).
|
||||
expect(Smaz.tryDecodePrefixed('s:${base64Encode([254])}'), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,626 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:provider/single_child_widget.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/review_mode/review_frames.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||
import 'package:meshcore_open/screens/channel_chat_screen.dart';
|
||||
import 'package:meshcore_open/screens/chat_screen.dart';
|
||||
import 'package:meshcore_open/services/app_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/ble_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/chat_text_scale_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
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/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
|
||||
/// Multi-select in channels, direct chats and rooms: taps must register
|
||||
/// within 250 ms (no double-tap recognizer may hold them back), and direct
|
||||
/// and room chats offer the same bulk actions as channels.
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final tempDir = Directory.systemTemp.createTempSync('bulk_selection_test');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||
(call) async => tempDir.path,
|
||||
);
|
||||
|
||||
setUpAll(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
clipboard = null;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
clipboard = (call.arguments as Map)['text'] as String?;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('direct and room chats: bulk bookmark saves every selected '
|
||||
'message', (tester) async {
|
||||
// One test for both: a bookmark write started in fake time only finishes
|
||||
// inside that test, and the next write queues behind it.
|
||||
for (final room in [false, true]) {
|
||||
final p = room ? 'room' : 'dm';
|
||||
_view(tester, const Size(400, 800));
|
||||
final (connector, chat) = await _pumpChat(tester, room: room);
|
||||
// Room posts name their author by key prefix; the bookmark must carry
|
||||
// that author's name, not the room server's.
|
||||
final authors = connector.contacts
|
||||
.where((c) => c.type == advTypeChat)
|
||||
.take(2)
|
||||
.toList();
|
||||
final posts = ['by author one', 'by author two'];
|
||||
if (room) {
|
||||
expect(authors, hasLength(2));
|
||||
for (var i = 0; i < 2; i++) {
|
||||
connector.handleFrameForTest(
|
||||
_roomPost(chat, authors[i], posts[i], _stamp++),
|
||||
);
|
||||
}
|
||||
await _settle(tester);
|
||||
}
|
||||
await _enterChatSelection(tester, '$p 8');
|
||||
await tester.tap(
|
||||
find.textContaining('$p 9', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
if (room) {
|
||||
for (final post in posts) {
|
||||
await tester.tap(
|
||||
find.textContaining(post, findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
}
|
||||
}
|
||||
await tester.tap(find.byTooltip('Bookmark'));
|
||||
await _settle(tester);
|
||||
// Bookmarks are stored per radio in the preferences; the writes
|
||||
// started in fake time need real time to finish.
|
||||
final prefs = PrefsManager.instance;
|
||||
String stored() => [
|
||||
for (final key in prefs.getKeys())
|
||||
if (key.startsWith('message_bookmarks_')) prefs.getString(key) ?? '',
|
||||
].join();
|
||||
for (
|
||||
var i = 0;
|
||||
i < 200 && !stored().contains(room ? posts[1] : '$p 9');
|
||||
i++
|
||||
) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 50)),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
}
|
||||
final saved = stored();
|
||||
expect(saved, contains('"text":"$p 8"'));
|
||||
expect(saved, contains('"text":"$p 9"'));
|
||||
expect(saved, isNot(contains('"text":"$p 7"')));
|
||||
if (room) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
final entry = RegExp(
|
||||
'\\{[^{}]*"text":"${posts[i]}"[^{}]*\\}',
|
||||
).firstMatch(saved)?.group(0);
|
||||
expect(entry, isNotNull, reason: 'missing ${posts[i]}');
|
||||
expect(entry, contains('"senderName":"${authors[i].name}"'));
|
||||
expect(entry, isNot(contains('"senderName":"${chat.name}"')));
|
||||
}
|
||||
}
|
||||
expect(find.textContaining('selected'), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
group('instant selection taps', () {
|
||||
testWidgets('channel: a tap selects within 250 ms and two taps 100 ms '
|
||||
'apart both select', (tester) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChannel(tester);
|
||||
await _enterChannelSelection(tester);
|
||||
expect(find.text('1 selected'), findsOneWidget);
|
||||
|
||||
await tester.tap(
|
||||
find.textContaining('History 38', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tap(
|
||||
find.textContaining('History 37', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('3 selected'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.check_circle), findsNWidgets(3));
|
||||
|
||||
// A lone tap needs no extra time either.
|
||||
await tester.tap(
|
||||
find.textContaining('History 36', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.byIcon(Icons.check_circle), findsNWidgets(4));
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('channel: a single frame after the tap already shows it', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChannel(tester);
|
||||
await _enterChannelSelection(tester);
|
||||
await tester.tap(
|
||||
find.textContaining('History 38', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byIcon(Icons.check_circle), findsNWidgets(2));
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('direct chat: taps select within 250 ms', (tester) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
final dm = await _pumpChat(tester, room: false);
|
||||
await _enterChatSelection(tester, 'dm 9');
|
||||
await tester.tap(
|
||||
find.textContaining('dm 8', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tap(
|
||||
find.textContaining('dm 7', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('3 selected'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.check_circle), findsNWidgets(3));
|
||||
expect(dm.$1.getMessages(dm.$2), isNotEmpty);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('room chat: taps select within 250 ms', (tester) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChat(tester, room: true);
|
||||
await _enterChatSelection(tester, 'room 9');
|
||||
await tester.tap(
|
||||
find.textContaining('room 8', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tap(
|
||||
find.textContaining('room 7', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('3 selected'), findsOneWidget);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('long press on a row toggles it while selecting', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChat(tester, room: false);
|
||||
await _enterChatSelection(tester, 'dm 9');
|
||||
await tester.longPress(
|
||||
find.textContaining('dm 8', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('2 selected'), findsOneWidget);
|
||||
await tester.longPress(
|
||||
find.textContaining('dm 8', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('1 selected'), findsOneWidget);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
});
|
||||
|
||||
for (final room in [false, true]) {
|
||||
final name = room ? 'room chat' : 'direct chat';
|
||||
final p = room ? 'room' : 'dm';
|
||||
|
||||
group('$name bulk actions', () {
|
||||
testWidgets('back clears the selection instead of leaving', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChat(tester, room: room);
|
||||
await _enterChatSelection(tester, '$p 9');
|
||||
await tester.tap(
|
||||
find.textContaining('$p 8', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.text('2 selected'), findsOneWidget);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(find.textContaining('selected'), findsNothing);
|
||||
expect(find.byType(ChatScreen), findsOneWidget);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('copy puts the selected messages oldest first', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChat(tester, room: room);
|
||||
await _enterChatSelection(tester, '$p 8');
|
||||
await tester.tap(
|
||||
find.textContaining('$p 5', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.tap(
|
||||
find.textContaining('$p 9', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.tap(find.byTooltip('Copy'));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(clipboard, '$p 5\n$p 8\n$p 9');
|
||||
expect(find.textContaining('selected'), findsNothing);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('delete asks first, then removes the selected messages', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
final (connector, contact) = await _pumpChat(tester, room: room);
|
||||
await _enterChatSelection(tester, '$p 8');
|
||||
await tester.tap(
|
||||
find.textContaining('$p 9', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.tap(find.byTooltip('Delete'));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(
|
||||
find.text('Delete 2 messages from this device?'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Delete'));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 100)),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
final texts = connector.getMessages(contact).map((m) => m.text);
|
||||
expect(texts, isNot(contains('$p 8')));
|
||||
expect(texts, isNot(contains('$p 9')));
|
||||
expect(texts, contains('$p 7'));
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('resend confirms, cancel does nothing, confirm resends', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(400, 800));
|
||||
final (connector, contact) = await _pumpChat(
|
||||
tester,
|
||||
room: room,
|
||||
outgoing: true,
|
||||
);
|
||||
List<String> ids() => [
|
||||
for (final m in connector.getMessages(contact))
|
||||
if (m.isOutgoing) m.messageId,
|
||||
];
|
||||
final before = ids();
|
||||
expect(before, hasLength(2));
|
||||
|
||||
await _enterChatSelection(tester, '$p out 1');
|
||||
await tester.tap(
|
||||
find.textContaining('$p out 2', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.tap(find.byTooltip('Resend'));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(
|
||||
find.text('Resend 2 selected outgoing messages to this contact?'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(ids(), before);
|
||||
expect(find.text('2 selected'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Resend'));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Resend'));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 300)),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
final after = ids();
|
||||
expect(after, hasLength(2));
|
||||
expect(after, isNot(before));
|
||||
expect(find.textContaining('selected'), findsNothing);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
group('no overflow at 320 dp', () {
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets('channel selection bar at ${scale}x text', (tester) async {
|
||||
_view(tester, const Size(320, 700));
|
||||
await _pumpChannel(tester, textScale: scale);
|
||||
await _enterChannelSelection(tester);
|
||||
await tester.tap(find.byIcon(Icons.radio_button_unchecked).first);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(tester.takeException(), isNull);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('direct chat selection bar at ${scale}x text', (
|
||||
tester,
|
||||
) async {
|
||||
_view(tester, const Size(320, 700));
|
||||
await _pumpChat(tester, room: false, outgoing: true, textScale: scale);
|
||||
await _enterChatSelection(tester, 'dm out 2');
|
||||
expect(find.byTooltip('Resend'), findsOneWidget);
|
||||
expect(find.byTooltip('Delete'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await _tearDown(tester);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A room-server post: a signed contact message whose 4-byte "signature" is
|
||||
/// the author's public key prefix.
|
||||
Uint8List _roomPost(Contact room, Contact author, String text, int stamp) {
|
||||
final writer = BufferWriter();
|
||||
writer.writeByte(respCodeContactMsgRecvV3);
|
||||
writer.writeByte(24);
|
||||
writer.writeByte(0);
|
||||
writer.writeByte(0);
|
||||
writer.writeBytes(Uint8List.fromList(room.publicKey.sublist(0, 6)));
|
||||
writer.writeByte(0xFF);
|
||||
writer.writeByte(txtTypeSigned);
|
||||
writer.writeUInt32LE(stamp);
|
||||
writer.writeBytes(Uint8List.fromList(author.publicKey.sublist(0, 4)));
|
||||
writer.writeString(text);
|
||||
writer.writeByte(0);
|
||||
return writer.toBytes();
|
||||
}
|
||||
|
||||
String? clipboard;
|
||||
|
||||
void _view(WidgetTester tester, Size size) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _tearDown(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
// Let writes started during the test finish, so they cannot stall the
|
||||
// next test's preferences writes.
|
||||
for (var i = 0; i < 20; i++) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 25)),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 25));
|
||||
}
|
||||
await tester.pump(const Duration(minutes: 1));
|
||||
}
|
||||
|
||||
/// Opens the message action sheet for the message showing [text] (by calling
|
||||
/// its long-press handler: a real long press on bubble text starts text
|
||||
/// selection in tests) and picks "Select messages".
|
||||
Future<void> _enterSelectionFrom(WidgetTester tester, Finder message) async {
|
||||
final target = tester.getCenter(message);
|
||||
final detector = find
|
||||
.byWidgetPredicate((w) => w is GestureDetector && w.onLongPress != null)
|
||||
.evaluate()
|
||||
.firstWhere((e) {
|
||||
final box = e.renderObject! as RenderBox;
|
||||
// Full-width detectors: match on the message's row, not its text.
|
||||
return (box.localToGlobal(box.size.center(Offset.zero)).dy - target.dy)
|
||||
.abs() <
|
||||
20;
|
||||
});
|
||||
(detector.widget as GestureDetector).onLongPress!();
|
||||
await _settle(tester);
|
||||
await tester.ensureVisible(find.text('Select messages'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Select messages'));
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
Future<void> _enterChannelSelection(WidgetTester tester) => _enterSelectionFrom(
|
||||
tester,
|
||||
find.textContaining('History 39', findRichText: true),
|
||||
);
|
||||
|
||||
Future<void> _enterChatSelection(WidgetTester tester, String text) =>
|
||||
_enterSelectionFrom(tester, find.textContaining(text, findRichText: true));
|
||||
|
||||
(MeshCoreConnector, List<SingleChildWidget>)? _shared;
|
||||
|
||||
Widget _app(List<SingleChildWidget> providers, Widget home, double textScale) =>
|
||||
MultiProvider(
|
||||
providers: providers,
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
|
||||
var _stamp = DateTime.now().millisecondsSinceEpoch ~/ 1000 - 100000;
|
||||
|
||||
Future<MeshCoreConnector> _pumpChannel(
|
||||
WidgetTester tester, {
|
||||
double textScale = 1.0,
|
||||
}) async {
|
||||
final (connector, providers) = _shared ??= await _connect(tester);
|
||||
final channel = connector.channels[0];
|
||||
if (connector.getChannelMessages(channel).length < 40) {
|
||||
for (var i = 0; i < 40; i++) {
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Alice',
|
||||
message: 'History $i',
|
||||
timestampSecs: _stamp + i * 60,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
await tester.pumpWidget(
|
||||
_app(providers, ChannelChatScreen(channel: channel), textScale),
|
||||
);
|
||||
await _settle(tester);
|
||||
return connector;
|
||||
}
|
||||
|
||||
/// Shows a direct chat (or the review radio's room) holding ten incoming
|
||||
/// messages "dm 0".."dm 9" / "room 0".."room 9", plus two outgoing ones when
|
||||
/// [outgoing].
|
||||
Future<(MeshCoreConnector, Contact)> _pumpChat(
|
||||
WidgetTester tester, {
|
||||
required bool room,
|
||||
bool outgoing = false,
|
||||
double textScale = 1.0,
|
||||
bool fresh = false,
|
||||
}) async {
|
||||
final (connector, providers) = fresh
|
||||
? await _connect(tester)
|
||||
: (_shared ??= await _connect(tester));
|
||||
final contact = connector.contacts.firstWhere(
|
||||
(c) => room ? c.type == advTypeRoom : c.type == advTypeChat,
|
||||
);
|
||||
final p = room ? 'room' : 'dm';
|
||||
connector.clearMessagesForContact(contact);
|
||||
await tester.runAsync(() => connector.flushPendingWrites());
|
||||
for (var i = 0; i < 10; i++) {
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: '$p $i',
|
||||
timestampSecs: _stamp++,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (outgoing) {
|
||||
await tester.runAsync(() async {
|
||||
await connector.sendMessage(contact, '$p out 1');
|
||||
await connector.sendMessage(contact, '$p out 2');
|
||||
});
|
||||
}
|
||||
connector.markContactRead(contact.publicKeyHex);
|
||||
await tester.pumpWidget(
|
||||
_app(providers, ChatScreen(contact: contact), textScale),
|
||||
);
|
||||
await _settle(tester);
|
||||
return (connector, contact);
|
||||
}
|
||||
|
||||
Future<(MeshCoreConnector, List<SingleChildWidget>)> _connect(
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final storage = StorageService();
|
||||
final connector = MeshCoreConnector();
|
||||
final retry = MessageRetryService();
|
||||
final settings = AppSettingsService();
|
||||
final translation = TranslationService(settings);
|
||||
await tester.runAsync(() async {
|
||||
await settings.loadSettings();
|
||||
connector.initialize(
|
||||
retryService: retry,
|
||||
pathHistoryService: PathHistoryService(storage),
|
||||
appSettingsService: settings,
|
||||
translationService: translation,
|
||||
);
|
||||
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
ackDelay: const Duration(hours: 1),
|
||||
replyDelay: const Duration(hours: 1),
|
||||
);
|
||||
await connector.connectReview();
|
||||
final end = DateTime.now().add(const Duration(seconds: 8));
|
||||
while ((!connector.contacts.any((c) => c.type == advTypeRoom) ||
|
||||
!connector.contacts.any((c) => c.type == advTypeChat) ||
|
||||
connector.channels.length < 2) &&
|
||||
DateTime.now().isBefore(end)) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
});
|
||||
expect(connector.channels.length, greaterThanOrEqualTo(2));
|
||||
|
||||
return (
|
||||
connector,
|
||||
<SingleChildWidget>[
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: retry),
|
||||
ChangeNotifierProvider.value(value: PathHistoryService(storage)),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: BleDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: AppDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: ChatTextScaleService()),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: UiViewStateService()),
|
||||
Provider.value(value: storage),
|
||||
ChangeNotifierProvider.value(
|
||||
value: MapTileCacheService(appSettingsService: settings),
|
||||
),
|
||||
ChangeNotifierProvider.value(value: TimeoutPredictionService(storage)),
|
||||
ChangeNotifierProvider.value(value: ImageCodecService(settings)),
|
||||
ChangeNotifierProvider.value(value: ReceivedImageStore()),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
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/screens/chat_compression_screen.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 ChangeNotifier {
|
||||
ChatCompressionMode mode;
|
||||
String? profileId;
|
||||
final bool enabled;
|
||||
final List<ChatCompressionMode> modeCalls = [];
|
||||
final List<String> profileCalls = [];
|
||||
final List<Completer<void>> pending = [];
|
||||
|
||||
_Host({
|
||||
this.mode = ChatCompressionMode.off,
|
||||
this.enabled = true,
|
||||
this.profileId,
|
||||
});
|
||||
|
||||
ChatCompressionState read() => ChatCompressionState(
|
||||
mode: mode,
|
||||
enabled: enabled,
|
||||
disabledReason: enabled ? null : _l10n.chatCompression_noStorageId,
|
||||
profiles: _profiles,
|
||||
profileId: profileId,
|
||||
defaultProfileId: 'ru',
|
||||
);
|
||||
|
||||
Future<void> _write(void Function() apply) async {
|
||||
final completer = Completer<void>();
|
||||
pending.add(completer);
|
||||
await completer.future;
|
||||
apply();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> setMode(ChatCompressionMode m) {
|
||||
modeCalls.add(m);
|
||||
return _write(() => mode = m);
|
||||
}
|
||||
|
||||
Future<void> setProfile(String id) {
|
||||
profileCalls.add(id);
|
||||
return _write(() => profileId = id);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
late _Host host;
|
||||
|
||||
Future<void> pumpPage(
|
||||
WidgetTester tester, {
|
||||
ChatCompressionMode mode = ChatCompressionMode.off,
|
||||
bool enabled = true,
|
||||
String? profileId,
|
||||
Size size = const Size(400, 800),
|
||||
double textScale = 1.0,
|
||||
}) async {
|
||||
host = _Host(mode: mode, enabled: enabled, profileId: profileId);
|
||||
addTearDown(host.dispose);
|
||||
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: ChatCompressionScreen(
|
||||
listenable: host,
|
||||
read: host.read,
|
||||
onModeChanged: host.setMode,
|
||||
onProfileChanged: host.setProfile,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Finder optionRow(String label) =>
|
||||
find.ancestor(of: find.text(label), matching: find.byType(ListTile));
|
||||
|
||||
bool isSelected(String label) {
|
||||
return find
|
||||
.descendant(
|
||||
of: optionRow(label),
|
||||
matching: find.byIcon(Icons.radio_button_checked),
|
||||
)
|
||||
.evaluate()
|
||||
.isNotEmpty;
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'lists the three modes with short notes and marks the saved one',
|
||||
(tester) async {
|
||||
await pumpPage(tester, mode: ChatCompressionMode.smaz);
|
||||
|
||||
expect(find.text(_l10n.chatCompression_title), findsWidgets);
|
||||
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(_l10n.chatCompression_smaz), isTrue);
|
||||
expect(isSelected(_l10n.chatCompression_off), isFalse);
|
||||
expect(find.text(_l10n.chatCompression_profile), findsNothing);
|
||||
for (final mode in [
|
||||
_l10n.chatCompression_off,
|
||||
_l10n.chatCompression_smaz,
|
||||
_l10n.chatCompression_cyr2lat,
|
||||
]) {
|
||||
expect(
|
||||
tester.getSize(optionRow(mode)).height,
|
||||
greaterThanOrEqualTo(48),
|
||||
reason: mode,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a choice shows only after it is saved', (tester) async {
|
||||
await pumpPage(tester);
|
||||
|
||||
await tester.tap(find.text(_l10n.chatCompression_smaz));
|
||||
await tester.pump();
|
||||
expect(host.modeCalls, [ChatCompressionMode.smaz]);
|
||||
// Still saving: old mode shown, options locked against rapid taps.
|
||||
expect(isSelected(_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(host.modeCalls, [ChatCompressionMode.smaz]);
|
||||
|
||||
host.pending.single.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
|
||||
expect(isSelected(_l10n.chatCompression_off), isFalse);
|
||||
expect(
|
||||
tester.widget<ListTile>(optionRow(_l10n.chatCompression_cyr2lat)).enabled,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Cyr2Lat reveals the profile picker', (tester) async {
|
||||
await pumpPage(tester);
|
||||
|
||||
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
|
||||
await tester.pump();
|
||||
host.pending.removeAt(0).complete();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(isSelected(_l10n.chatCompression_cyr2lat), isTrue);
|
||||
expect(find.text(_l10n.chatCompression_profile), findsWidgets);
|
||||
// No profile saved for the chat: the app-wide one is what sending uses.
|
||||
expect(find.text('Russian'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Russian'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Serbian').last);
|
||||
await tester.pump();
|
||||
expect(host.profileCalls, ['sr']);
|
||||
host.pending.removeAt(0).complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Serbian'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a failed save keeps the saved mode and says so', (tester) async {
|
||||
await pumpPage(tester, mode: ChatCompressionMode.smaz);
|
||||
|
||||
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
|
||||
await tester.pump();
|
||||
host.pending.single.completeError(StateError('disk full'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
|
||||
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
|
||||
expect(isSelected(_l10n.chatCompression_cyr2lat), isFalse);
|
||||
expect(
|
||||
tester.widget<ListTile>(optionRow(_l10n.chatCompression_off)).enabled,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a failed profile save shows the saved profile again', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpPage(tester, mode: ChatCompressionMode.cyr2lat, profileId: 'ru');
|
||||
|
||||
await tester.tap(find.text('Russian'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Serbian').last);
|
||||
await tester.pump();
|
||||
expect(host.profileCalls, ['sr']);
|
||||
host.pending.single.completeError(StateError('disk full'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.text('Russian'), 100);
|
||||
expect(find.text('Russian'), findsOneWidget);
|
||||
expect(find.text('Serbian'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('disabled shows the saved mode, says why and allows no change', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpPage(tester, mode: ChatCompressionMode.smaz, enabled: false);
|
||||
|
||||
expect(find.text(_l10n.chatCompression_noStorageId), findsOneWidget);
|
||||
expect(isSelected(_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(host.modeCalls, isEmpty);
|
||||
});
|
||||
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets('fits a 320dp phone at ${scale}x text', (tester) async {
|
||||
await pumpPage(
|
||||
tester,
|
||||
mode: ChatCompressionMode.cyr2lat,
|
||||
size: const Size(320, 568),
|
||||
textScale: scale,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
// The page scrolls to its last option and the profile picker.
|
||||
await tester.scrollUntilVisible(
|
||||
find.byType(DropdownButtonFormField<String>),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,8 @@ 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/screens/chat_compression_screen.dart';
|
||||
import 'package:meshcore_open/widgets/connect_sheet.dart';
|
||||
|
||||
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
|
||||
@@ -349,10 +348,18 @@ void main() {
|
||||
await tester.pump(const Duration(minutes: 1));
|
||||
});
|
||||
|
||||
group('compression selector', () {
|
||||
Future<void> choose(WidgetTester tester, String mode) async {
|
||||
await tester.tap(find.byType(ChatCompressionSelector));
|
||||
group('compression menu item', () {
|
||||
Future<void> openMenu(WidgetTester tester) async {
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
/// Opens the page from the overflow menu, picks [mode], and returns.
|
||||
Future<void> choose(WidgetTester tester, String mode) async {
|
||||
await openMenu(tester);
|
||||
await tester.tap(find.textContaining('${_l10n.chatCompression_title}:'));
|
||||
await _settle(tester);
|
||||
expect(find.byType(ChatCompressionScreen), findsOneWidget);
|
||||
await tester.tap(find.text(mode));
|
||||
await _settle(tester);
|
||||
// Connector notifications are debounced on a real timer.
|
||||
@@ -360,9 +367,11 @@ void main() {
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 200)),
|
||||
);
|
||||
await _settle(tester);
|
||||
await tester.pageBack();
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
testWidgets('DM chat shows it at the top and saves offline', (
|
||||
testWidgets('DM chat shows it in the menu and saves offline', (
|
||||
tester,
|
||||
) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
@@ -373,32 +382,27 @@ void main() {
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(ChatCompressionSelector), findsOneWidget);
|
||||
// No strip above the transcript any more.
|
||||
expect(find.byType(ChatCompressionScreen), findsNothing);
|
||||
expect(find.text(_l10n.chatCompression_label('Off')), findsNothing);
|
||||
await openMenu(tester);
|
||||
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),
|
||||
);
|
||||
expect(find.byIcon(Icons.compress), findsOneWidget);
|
||||
await tester.tapAt(const Offset(1, 1));
|
||||
await _settle(tester);
|
||||
|
||||
await choose(tester, _l10n.chatCompression_smaz);
|
||||
await openMenu(tester);
|
||||
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
|
||||
await tester.tapAt(const Offset(1, 1));
|
||||
await _settle(tester);
|
||||
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);
|
||||
await openMenu(tester);
|
||||
expect(find.text(_l10n.chatCompression_label('Cyr2Lat')), findsOneWidget);
|
||||
expect(
|
||||
connector.contactCompressionMode(alice.publicKeyHex),
|
||||
@@ -416,8 +420,6 @@ void main() {
|
||||
);
|
||||
|
||||
// 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);
|
||||
@@ -431,7 +433,7 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('channel chat uses the same selector and saves offline', (
|
||||
testWidgets('channel chat uses the same page and saves offline', (
|
||||
tester,
|
||||
) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
@@ -442,10 +444,13 @@ void main() {
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(ChatCompressionSelector), findsOneWidget);
|
||||
await openMenu(tester);
|
||||
expect(find.text(_l10n.chatCompression_label('Off')), findsOneWidget);
|
||||
await tester.tapAt(const Offset(1, 1));
|
||||
await _settle(tester);
|
||||
|
||||
await choose(tester, _l10n.chatCompression_smaz);
|
||||
await openMenu(tester);
|
||||
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
|
||||
expect(
|
||||
await tester.runAsync(() => store.loadSmazEnabled(channel.storageId!)),
|
||||
|
||||
@@ -37,6 +37,7 @@ final _l10n = AppLocalizationsEn();
|
||||
|
||||
MeshCoreConnector? _sharedConnector;
|
||||
AppSettingsService? _sharedSettings;
|
||||
final _frameLog = BleDebugLogService();
|
||||
|
||||
Future<MeshCoreConnector> _connectedConnector(WidgetTester tester) async {
|
||||
if (_sharedConnector != null) return _sharedConnector!;
|
||||
@@ -51,6 +52,7 @@ Future<MeshCoreConnector> _connectedConnector(WidgetTester tester) async {
|
||||
pathHistoryService: PathHistoryService(storage),
|
||||
appSettingsService: settings,
|
||||
translationService: translation,
|
||||
bleDebugLogService: _frameLog,
|
||||
);
|
||||
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
@@ -338,6 +340,77 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('Contact Settings sends the hop limit and reads it back', (
|
||||
tester,
|
||||
) async {
|
||||
final connector = await _connectedConnector(tester);
|
||||
final original = connector.autoAddMaxHops;
|
||||
expect(original, isNotNull, reason: 'review radio reports the hop limit');
|
||||
await tester.pumpWidget(
|
||||
_app(connector, _launcher(const ContactSettingsScreen())),
|
||||
);
|
||||
await _open(tester);
|
||||
String option(int hops) => _l10n.contactsSettings_hopLimitOption(hops);
|
||||
expect(find.text(option(original!)), findsOneWidget);
|
||||
|
||||
Future<void> setHops(int hops) async {
|
||||
final field = find.byType(DropdownButtonFormField<int>);
|
||||
await tester.ensureVisible(field);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(field);
|
||||
await tester.pumpAndSettle();
|
||||
// The open menu builds only the rows around the current value.
|
||||
final item = find.text(option(hops));
|
||||
await tester.scrollUntilVisible(
|
||||
item,
|
||||
hops < connector.autoAddMaxHops! ? -48 : 48,
|
||||
scrollable: find.byType(Scrollable).last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(item.last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_saveAction);
|
||||
await _waitFor(tester, () => connector.autoAddMaxHops == hops);
|
||||
}
|
||||
|
||||
// The last frame of [code] the app sent to the radio.
|
||||
List<int> lastSent(int code) => _frameLog.entries
|
||||
.lastWhere((e) => e.outgoing && e.payload.first == code)
|
||||
.payload;
|
||||
int sentCount(int code) => _frameLog.entries
|
||||
.where((e) => e.outgoing && e.payload.first == code)
|
||||
.length;
|
||||
|
||||
final fetchesBefore = sentCount(cmdGetAutoAddConfig);
|
||||
await setHops(8);
|
||||
expect(connector.autoAddMaxHops, 8);
|
||||
expect(find.text(option(8)), findsOneWidget);
|
||||
expect(_saveAction, findsNothing);
|
||||
// [CMD_SET_AUTOADD_CONFIG][flags][max hops], then a fetch to read it back.
|
||||
expect(lastSent(cmdSetAutoAddConfig), hasLength(3));
|
||||
expect(lastSent(cmdSetAutoAddConfig).last, 8);
|
||||
expect(sentCount(cmdGetAutoAddConfig), fetchesBefore + 1);
|
||||
|
||||
// Changing only another setting sends the old two-byte frame.
|
||||
final overwrite = find.text(_l10n.contactsSettings_overwriteOldestTitle);
|
||||
for (var i = 0; i < 2; i++) {
|
||||
await tester.ensureVisible(overwrite);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(overwrite);
|
||||
await tester.pump();
|
||||
await tester.tap(_saveAction);
|
||||
await _waitFor(tester, () => _saveAction.evaluate().isEmpty);
|
||||
expect(lastSent(cmdSetAutoAddConfig), hasLength(2));
|
||||
}
|
||||
expect(connector.autoAddMaxHops, 8);
|
||||
|
||||
await setHops(original);
|
||||
expect(connector.autoAddMaxHops, original);
|
||||
expect(lastSent(cmdSetAutoAddConfig), hasLength(3));
|
||||
expect(lastSent(cmdSetAutoAddConfig).last, original);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('Node Name counts bytes and saves to the radio', (tester) async {
|
||||
final connector = await _connectedConnector(tester);
|
||||
final originalName = connector.selfName!;
|
||||
|
||||
@@ -1,334 +0,0 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user