Merge upstream/dev: Android Auto as opt-in flavor, decluttered map overlay
build / build (push) Failing after 3m2s
build / build (push) Failing after 3m2s
Conflicts: the manifest keeps our unread widget receiver and drops the Android Auto meta-data, which upstream moved to the androidAuto source set (fe7e72a). Rename detection had moved our unread_widget_info.xml into that source set with it; it stays in main. _mapChip is gone upstream with the map overlay declutter (ed5884e), so our terminal-theme restyle of it goes too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
9489dee1c3
114 files changed
+11506
-1027
No files matched your search
@@ -13,6 +13,7 @@ import 'package:meshcore_open/review_mode/review_script.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_message_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:pointycastle/export.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -185,6 +186,7 @@ void main() {
|
||||
|
||||
expect(_channelAt(1).name, 'Hiking Group');
|
||||
expect(_texts(1), isNot(contains('ghost message')));
|
||||
await _connector.flushPendingWrites();
|
||||
// The old channel's history is kept under its own ID.
|
||||
expect(_storedTexts(ghostId), ['ghost message']);
|
||||
expect(_storedTexts(hikingId), contains(_queuedHikingText));
|
||||
@@ -218,6 +220,7 @@ void main() {
|
||||
.firstWhere((m) => m.text == _queuedHikingText);
|
||||
expect(restored.channelIndex, 6);
|
||||
await _connector.deleteChannelMessage(restored);
|
||||
await _connector.flushPendingWrites();
|
||||
expect(_texts(6), isNot(contains(_queuedHikingText)));
|
||||
expect(_storedTexts(hikingId), isNot(contains(_queuedHikingText)));
|
||||
});
|
||||
@@ -237,12 +240,48 @@ void main() {
|
||||
test('deleting a channel clears its stored history', () async {
|
||||
await _connect(_TestRadio());
|
||||
await _waitFor(() => _texts(1).contains(_queuedHikingText));
|
||||
await _connector.flushPendingWrites();
|
||||
expect(_storedTexts(hikingId), isNotEmpty);
|
||||
|
||||
await _connector.deleteChannel(1);
|
||||
expect(_storedTexts(hikingId), isEmpty);
|
||||
});
|
||||
|
||||
test('deleting a channel clears its history when the refresh cannot read '
|
||||
'the slot', () async {
|
||||
_connector.channelSyncTimeoutMs = 30;
|
||||
var deleted = false;
|
||||
final radio = _TestRadio(
|
||||
swallow: (frame) {
|
||||
if (frame[0] == cmdSetChannel && frame[1] == 1) deleted = true;
|
||||
return deleted && frame[0] == cmdGetChannel && frame[1] == 1;
|
||||
},
|
||||
);
|
||||
await _connect(radio);
|
||||
await _waitFor(() => _texts(1).contains(_queuedHikingText));
|
||||
|
||||
await _connector.deleteChannel(1);
|
||||
expect(_connector.channelIdForSlot(1), hikingId);
|
||||
expect(_storedTexts(hikingId), isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'deleting one of two slots with the same PSK keeps the history',
|
||||
() async {
|
||||
final radio = _TestRadio();
|
||||
await _connect(
|
||||
radio,
|
||||
seed: () =>
|
||||
radio.handle(buildSetChannelFrame(5, 'Hiking Twin', _psk(1))),
|
||||
);
|
||||
await _waitFor(() => _texts(1).contains(_queuedHikingText));
|
||||
|
||||
await _connector.deleteChannel(1);
|
||||
await _connector.flushPendingWrites();
|
||||
expect(_storedTexts(hikingId), contains(_queuedHikingText));
|
||||
},
|
||||
);
|
||||
|
||||
test('a channel frame that arrives before the slot map is held, then filed '
|
||||
'by the confirmed map', () async {
|
||||
final radio = _TestRadio(
|
||||
@@ -265,6 +304,7 @@ void main() {
|
||||
seed: () => _seedSlotMap({0: _id(_psk(0)), 1: ghostId, 2: _id(_psk(2))}),
|
||||
);
|
||||
await _waitFor(() => _texts(1).contains('before the map'));
|
||||
await _connector.flushPendingWrites();
|
||||
expect(_storedTexts(hikingId), contains('before the map'));
|
||||
expect(_storedTexts(ghostId), isNot(contains('before the map')));
|
||||
});
|
||||
@@ -348,6 +388,7 @@ void main() {
|
||||
);
|
||||
await _waitFor(() => _texts(1).contains('from the twin slot'));
|
||||
expect(_texts(5), contains('from the twin slot'));
|
||||
await _connector.flushPendingWrites();
|
||||
expect(
|
||||
_storedTexts(hikingId).where((t) => t == 'from the twin slot'),
|
||||
hasLength(1),
|
||||
@@ -366,7 +407,36 @@ void main() {
|
||||
),
|
||||
);
|
||||
await _waitFor(() => _texts(2).contains('heard over the air'));
|
||||
await _connector.flushPendingWrites();
|
||||
expect(_storedTexts(localId), contains('heard over the air'));
|
||||
expect(_texts(1), isNot(contains('heard over the air')));
|
||||
});
|
||||
|
||||
test('a busy channel is capped at the stored-message limit in memory and '
|
||||
'in storage', () async {
|
||||
await _connect(_TestRadio());
|
||||
await _waitFor(() => _texts(1).contains(_queuedHikingText));
|
||||
const cap = ChannelMessageStore.maxStoredMessages;
|
||||
final start = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
for (var i = 0; i < cap + 50; i++) {
|
||||
_connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: 1,
|
||||
sender: 'Sam',
|
||||
message: 'busy $i',
|
||||
timestampSecs: start + i,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final texts = _texts(1);
|
||||
expect(texts, hasLength(cap));
|
||||
expect(texts.last, 'busy ${cap + 49}');
|
||||
// Nothing is written per frame; the batch lands on flush.
|
||||
await _connector.flushPendingWrites();
|
||||
final stored = _storedTexts(hikingId);
|
||||
expect(stored, hasLength(cap));
|
||||
expect(stored.first, 'busy 50');
|
||||
expect(stored.last, 'busy ${cap + 49}');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/services/app_settings_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/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';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('stores return null for chats that were never set', () async {
|
||||
final channels = ChannelSettingsStore()..setPublicKeyHex = 'aabbccddeeff';
|
||||
final contacts = ContactSettingsStore()..setPublicKeyHex = 'aabbccddeeff';
|
||||
expect(await channels.loadUrlImagesEnabled('chan'), isNull);
|
||||
expect(await contacts.loadUrlImagesEnabled('c1'), isNull);
|
||||
|
||||
await channels.saveUrlImagesEnabled('chan', false);
|
||||
await contacts.saveUrlImagesEnabled('c1', false);
|
||||
expect(await channels.loadUrlImagesEnabled('chan'), isFalse);
|
||||
expect(await contacts.loadUrlImagesEnabled('c1'), isFalse);
|
||||
});
|
||||
|
||||
test('effective value is the per-chat choice, else the default', () async {
|
||||
final settings = AppSettingsService();
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
addTearDown(retryService.dispose);
|
||||
connector.initialize(
|
||||
retryService: retryService,
|
||||
pathHistoryService: PathHistoryService(StorageService()),
|
||||
appSettingsService: settings,
|
||||
);
|
||||
var notified = 0;
|
||||
connector.addListener(() => notified++);
|
||||
|
||||
expect(connector.isContactUrlImagesEnabled('c1'), isFalse);
|
||||
expect(connector.isChannelUrlImagesEnabled(0), isFalse);
|
||||
|
||||
await settings.setShowLinkImagesByDefault(true);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
expect(notified, greaterThan(0));
|
||||
expect(connector.isContactUrlImagesEnabled('c1'), isTrue);
|
||||
expect(connector.isChannelUrlImagesEnabled(0), isTrue);
|
||||
|
||||
await connector.setContactUrlImagesEnabled('c2', false);
|
||||
expect(connector.isContactUrlImagesEnabled('c2'), isFalse);
|
||||
|
||||
await settings.setShowLinkImagesByDefault(false);
|
||||
await connector.setContactUrlImagesEnabled('c3', true);
|
||||
expect(connector.isContactUrlImagesEnabled('c1'), isFalse);
|
||||
expect(connector.isContactUrlImagesEnabled('c3'), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
|
||||
void main() {
|
||||
bool mentions(String text, String? name) =>
|
||||
MeshCoreConnector.textMentionsName(text, name);
|
||||
|
||||
test('matches bracketed and plain mentions case-insensitively', () {
|
||||
expect(mentions('@[Bob] hello', 'Bob'), isTrue);
|
||||
expect(mentions('hey @[bob]', 'Bob'), isTrue);
|
||||
expect(mentions('hey @bob, look', 'Bob'), isTrue);
|
||||
expect(mentions('@BOB', 'Bob'), isTrue);
|
||||
expect(mentions('ping @Иван!', 'иван'), isTrue);
|
||||
});
|
||||
|
||||
test('requires a word boundary for plain mentions', () {
|
||||
expect(mentions('hey @bobby', 'Bob'), isFalse);
|
||||
expect(mentions('mail x@bob.com', 'Bob'), isFalse);
|
||||
expect(mentions('hey bob', 'Bob'), isFalse);
|
||||
});
|
||||
|
||||
test('names with spaces or regex characters must match in full', () {
|
||||
expect(mentions('hi @Bob Smith', 'Bob Smith'), isTrue);
|
||||
expect(mentions('hi @Bob', 'Bob Smith'), isFalse);
|
||||
expect(mentions('@[Node (1)] ok', 'Node (1)'), isTrue);
|
||||
expect(mentions('@[Node 1] ok', 'Node (1)'), isFalse);
|
||||
});
|
||||
|
||||
test('no self name never matches', () {
|
||||
expect(mentions('@[Bob] hi', null), isFalse);
|
||||
expect(mentions('@ hi', ''), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -65,7 +65,12 @@ void main() {
|
||||
waitForReply: true,
|
||||
);
|
||||
queue.takeErr(6);
|
||||
await expectLater(pending!.completer!.future, throwsException);
|
||||
await expectLater(
|
||||
pending!.completer!.future,
|
||||
throwsA(
|
||||
isA<FirmwareCommandException>().having((e) => e.errCode, 'errCode', 6),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('timed-out entries', () {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
|
||||
String _reference(Uint8List bytes) =>
|
||||
bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
|
||||
void main() {
|
||||
test('pubKeyToHex is lowercase, zero-padded hex for every byte value', () {
|
||||
final all = Uint8List.fromList(List<int>.generate(256, (i) => i));
|
||||
expect(pubKeyToHex(all), _reference(all));
|
||||
expect(pubKeyToHex(Uint8List(0)), '');
|
||||
expect(pubKeyToHex(Uint8List.fromList([0x00, 0x0a, 0xff])), '000aff');
|
||||
});
|
||||
|
||||
test('pubKeyToHex round-trips random keys through hexToPubKey', () {
|
||||
final random = Random(7);
|
||||
for (var i = 0; i < 200; i++) {
|
||||
final key = Uint8List.fromList(
|
||||
List<int>.generate(32, (_) => random.nextInt(256)),
|
||||
);
|
||||
final hex = pubKeyToHex(key);
|
||||
expect(hex, _reference(key));
|
||||
expect(hexToPubKey(hex), key);
|
||||
}
|
||||
});
|
||||
|
||||
test('Contact.publicKeyHex is stable and drives equality', () {
|
||||
final key = Uint8List.fromList(List<int>.generate(32, (i) => i * 7));
|
||||
Contact make(String name) => Contact(
|
||||
publicKey: key,
|
||||
name: name,
|
||||
type: 1,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime(2026),
|
||||
);
|
||||
final a = make('a');
|
||||
expect(a.publicKeyHex, _reference(key));
|
||||
expect(identical(a.publicKeyHex, a.publicKeyHex), isTrue);
|
||||
expect(a, make('renamed'));
|
||||
expect(a.hashCode, make('renamed').hashCode);
|
||||
expect(a.copyWith(name: 'b').publicKeyHex, a.publicKeyHex);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.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/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<void> _waitFor(bool Function() condition, {int seconds = 8}) async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
}
|
||||
|
||||
/// Review radio that records every frame the app sends.
|
||||
class _RecordingReviewRadio extends ReviewRadio {
|
||||
final List<Uint8List> sent = [];
|
||||
|
||||
_RecordingReviewRadio()
|
||||
: super(scheduledMessageInterval: const Duration(hours: 1));
|
||||
|
||||
@override
|
||||
void handle(Uint8List frame) {
|
||||
sent.add(frame);
|
||||
super.handle(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('removed contact stays gone from the radio, list and store', () async {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
addTearDown(retryService.dispose);
|
||||
connector.initialize(
|
||||
retryService: retryService,
|
||||
pathHistoryService: PathHistoryService(StorageService()),
|
||||
);
|
||||
final radio = _RecordingReviewRadio();
|
||||
connector.reviewRadioFactoryForTest = () => radio;
|
||||
|
||||
await connector.connectReview();
|
||||
await _waitFor(
|
||||
() => connector.hasLoadedContacts && connector.contacts.length >= 6,
|
||||
);
|
||||
final contact = connector.contacts.firstWhere((c) => c.name == 'Maya');
|
||||
|
||||
await connector.removeContact(contact);
|
||||
|
||||
bool listed() =>
|
||||
connector.contacts.any((c) => c.publicKeyHex == contact.publicKeyHex);
|
||||
expect(listed(), isFalse);
|
||||
expect(
|
||||
connector.discoveredContacts
|
||||
.firstWhere((c) => c.publicKeyHex == contact.publicKeyHex)
|
||||
.isActive,
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// A full resync from the radio must not bring it back.
|
||||
await connector.getContacts();
|
||||
await _waitFor(() => connector.hasLoadedContacts);
|
||||
expect(connector.contacts, isNotEmpty);
|
||||
expect(listed(), isFalse);
|
||||
|
||||
final store = ContactStore()..setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
final saved = await store.loadContacts();
|
||||
expect(saved.any((c) => c.publicKeyHex == contact.publicKeyHex), isFalse);
|
||||
|
||||
// An open chat/repeater screen still syncs the path before each send, and
|
||||
// the favourite toggle writes flags. On firmware CMD_ADD_UPDATE_CONTACT
|
||||
// adds unknown keys, so neither may be sent for the removed contact.
|
||||
radio.sent.clear();
|
||||
await connector.setContactPath(contact, Uint8List.fromList([0x42]), 1);
|
||||
await connector.preparePathForContactSend(contact);
|
||||
await connector.setContactFlags(contact, isFavorite: true);
|
||||
expect(radio.sent.where((f) => f.first == cmdAddUpdateContact), isEmpty);
|
||||
|
||||
await connector.disconnect(manual: true);
|
||||
});
|
||||
|
||||
test('auto-add config reports which contact types come back', () {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
connector.handleFrameForTest([respCodeAutoAddConfig, autoAddRepeaterFlag]);
|
||||
|
||||
expect(connector.autoAddsContactType(advTypeRepeater), isTrue);
|
||||
expect(connector.autoAddsContactType(advTypeChat), isFalse);
|
||||
expect(connector.autoAddsContactType(advTypeRoom), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -12,11 +12,15 @@ import 'package:meshcore_open/services/usb_serial_frame_codec.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<void> _waitFor(bool Function() condition, {int seconds = 10}) async {
|
||||
Future<void> _waitFor(
|
||||
bool Function() condition, {
|
||||
int seconds = 10,
|
||||
Duration pollInterval = const Duration(milliseconds: 25),
|
||||
}) async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
await Future<void>.delayed(pollInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,11 +204,22 @@ void main() {
|
||||
// The companion goes away entirely: attempts fail and are rescheduled.
|
||||
await companion.close();
|
||||
await _waitFor(
|
||||
() => _connector.state == MeshCoreConnectionState.disconnected,
|
||||
() =>
|
||||
_connector.state == MeshCoreConnectionState.disconnected &&
|
||||
_connector.isAutoReconnectScheduled,
|
||||
);
|
||||
await _waitFor(
|
||||
() => !_connector.isAutoReconnectScheduled,
|
||||
pollInterval: const Duration(milliseconds: 1),
|
||||
);
|
||||
// The timer firing proves an attempt started; wait for its failure to
|
||||
// finish and the next backoff to become active.
|
||||
await _waitFor(
|
||||
() =>
|
||||
_connector.state == MeshCoreConnectionState.disconnected &&
|
||||
_connector.isAutoReconnectScheduled,
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1500));
|
||||
expect(_connector.isTcpTransportConnected, isFalse);
|
||||
expect(_connector.isAutoReconnectScheduled, isTrue);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/ipfs_link_attach_flow.dart';
|
||||
import 'package:meshcore_open/helpers/ipfs_upload_helper.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
|
||||
void main() {
|
||||
const url = 'ipfs://cid';
|
||||
String identity(String text) => text;
|
||||
|
||||
group('composeIpfsLinkDraft', () {
|
||||
test('puts the link before an empty draft with a trailing space', () {
|
||||
expect(composeIpfsLinkDraft(messageUrl: url, existingText: ''), '$url ');
|
||||
});
|
||||
|
||||
test('keeps the whole draft after the link', () {
|
||||
final draft = 'x' * 500;
|
||||
expect(
|
||||
composeIpfsLinkDraft(messageUrl: url, existingText: draft),
|
||||
'$url\n$draft',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('ipfsLinkDraftFits', () {
|
||||
test('accepts a draft at the limit and rejects one byte over', () {
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 13, encodeOutbound: identity),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 12, encodeOutbound: identity),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('measures the encoded form, including a reply prefix', () {
|
||||
String withReply(String text) => '@[Alice] $text';
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 13, encodeOutbound: withReply),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 22, encodeOutbound: withReply),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('ignores the trailing space the send path trims', () {
|
||||
expect(
|
||||
ipfsLinkDraftFits(
|
||||
'$url ',
|
||||
maxBytes: url.length,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('IpfsUploadHelper.linkForCid', () {
|
||||
test('uses ipfs:// without a gateway', () {
|
||||
expect(
|
||||
IpfsUploadHelper.linkForCid(uploadGateway: '', cid: 'abc'),
|
||||
'ipfs://abc',
|
||||
);
|
||||
});
|
||||
|
||||
test('sample CID is CIDv1 base32 length', () {
|
||||
expect(IpfsUploadHelper.sampleCid.length, 59);
|
||||
});
|
||||
});
|
||||
|
||||
group('ipfsUploadErrorText', () {
|
||||
final l10n = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
test('gives every config reason its own localized message', () {
|
||||
final texts = {
|
||||
for (final reason in IpfsUploadConfigError.values)
|
||||
reason: ipfsUploadErrorText(l10n, IpfsUploadConfigException(reason)),
|
||||
};
|
||||
expect(
|
||||
texts[IpfsUploadConfigError.emptyEndpoint],
|
||||
l10n.chat_ipfsUploadNotConfigured,
|
||||
);
|
||||
expect(
|
||||
texts[IpfsUploadConfigError.kuboPathInvalid],
|
||||
l10n.chat_ipfsKuboPathInvalid,
|
||||
);
|
||||
expect(texts.values.toSet(), hasLength(texts.length));
|
||||
});
|
||||
|
||||
test('wraps other errors in the generic message without the prefix', () {
|
||||
expect(
|
||||
ipfsUploadErrorText(l10n, Exception('IPFS upload failed (500): x')),
|
||||
l10n.chat_ipfsUploadFailed('IPFS upload failed (500): x'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:meshcore_open/helpers/ipfs_upload_helper.dart';
|
||||
|
||||
void main() {
|
||||
group('IpfsUploadHelper', () {
|
||||
tearDown(() => IpfsUploadHelper.httpClient = null);
|
||||
|
||||
test('does not upload when the upload endpoint is empty', () async {
|
||||
var requestCount = 0;
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
requestCount++;
|
||||
return http.Response('{}', 200);
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: '',
|
||||
uploadApiKey: '',
|
||||
),
|
||||
throwsException,
|
||||
);
|
||||
expect(requestCount, 0);
|
||||
});
|
||||
|
||||
for (final endpoint in [
|
||||
'not a url',
|
||||
'ftp://host/api/v0/add',
|
||||
'https://host/ipfs-upload',
|
||||
'https://uploads.example.com/v1/files',
|
||||
]) {
|
||||
test('rejects $endpoint before uploading', () async {
|
||||
var requestCount = 0;
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
requestCount++;
|
||||
return http.Response('{"Hash":"bafytest"}', 200);
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: endpoint,
|
||||
uploadApiKey: 'token',
|
||||
),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
expect(requestCount, 0);
|
||||
});
|
||||
}
|
||||
|
||||
test('copies to MFS through a proxied Kubo endpoint', () async {
|
||||
final urls = <Uri>[];
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
urls.add(request.url);
|
||||
return http.Response('{"Hash":"bafytest"}', 200);
|
||||
});
|
||||
|
||||
final message = await IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: 'https://host/ipfs-upload/api/v0/add',
|
||||
uploadApiKey: '',
|
||||
);
|
||||
|
||||
expect(message, 'ipfs://bafytest');
|
||||
expect(urls.map((url) => url.path), [
|
||||
'/ipfs-upload/api/v0/add',
|
||||
'/ipfs-upload/api/v0/files/cp',
|
||||
]);
|
||||
expect(urls.last.queryParametersAll['arg'], [
|
||||
'/ipfs/bafytest',
|
||||
'/meshcore_uploads/bafytest-image.png',
|
||||
]);
|
||||
});
|
||||
|
||||
test(
|
||||
'uploads and returns an ipfs scheme when upload gateway is empty',
|
||||
() async {
|
||||
final requests = <http.BaseRequest>[];
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
requests.add(request);
|
||||
expect(request.method, 'POST');
|
||||
return http.Response(
|
||||
'{"Hash":"bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly"}',
|
||||
200,
|
||||
);
|
||||
});
|
||||
|
||||
final message = await IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: 'http://127.0.0.1:5001/api/v0/add',
|
||||
uploadApiKey: '',
|
||||
);
|
||||
|
||||
expect(
|
||||
message,
|
||||
'ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
);
|
||||
expect(requests.first.url.path, '/api/v0/add');
|
||||
expect(requests.first.url.queryParameters, {
|
||||
'cid-version': '1',
|
||||
'pin': 'true',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
're-sharing a file already in Kubo MFS still returns the link',
|
||||
() async {
|
||||
final paths = <String>[];
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
paths.add(request.url.path);
|
||||
if (request.url.path.endsWith('/files/cp')) {
|
||||
return http.Response(
|
||||
'{"Message":"cp: cannot put node in path /meshcore_uploads/bafytest-image.png: directory already has entry by that name","Code":0,"Type":"error"}',
|
||||
500,
|
||||
);
|
||||
}
|
||||
return http.Response('{"Hash":"bafytest"}', 200);
|
||||
});
|
||||
|
||||
final message = await IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: 'http://127.0.0.1:5001/api/v0/add',
|
||||
uploadApiKey: '',
|
||||
);
|
||||
|
||||
expect(message, 'ipfs://bafytest');
|
||||
expect(paths, ['/api/v0/add', '/api/v0/files/cp']);
|
||||
},
|
||||
);
|
||||
|
||||
test('other Kubo MFS errors still fail the upload', () async {
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
if (request.url.path.endsWith('/files/cp')) {
|
||||
return http.Response('{"Message":"permission denied"}', 500);
|
||||
}
|
||||
return http.Response('{"Hash":"bafytest"}', 200);
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: 'http://127.0.0.1:5001/api/v0/add',
|
||||
uploadApiKey: '',
|
||||
),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
|
||||
test('sends the Pinata request to the endpoint unchanged', () async {
|
||||
late http.BaseRequest upload;
|
||||
IpfsUploadHelper.httpClient = MockClient((request) async {
|
||||
upload = request;
|
||||
return http.Response('{"IpfsHash":"bafytest"}', 200);
|
||||
});
|
||||
|
||||
final message = await IpfsUploadHelper.uploadImage(
|
||||
bytes: Uint8List.fromList(<int>[1, 2, 3]),
|
||||
fileName: 'image.png',
|
||||
mimeType: 'image/png',
|
||||
uploadEndpoint: 'https://api.pinata.cloud/pinning/pinFileToIPFS',
|
||||
uploadApiKey: 'jwt',
|
||||
uploadGateway: 'https://gateway.example.com',
|
||||
);
|
||||
|
||||
expect(
|
||||
upload.url.toString(),
|
||||
'https://api.pinata.cloud/pinning/pinFileToIPFS',
|
||||
);
|
||||
expect(upload.headers['Authorization'], 'Bearer jwt');
|
||||
expect(message, 'https://gateway.example.com/ipfs/bafytest');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -5,7 +5,10 @@ import 'package:meshcore_open/helpers/message_url_image_helper.dart';
|
||||
|
||||
void main() {
|
||||
group('MessageUrlImageHelper', () {
|
||||
tearDown(() => MessageUrlImageHelper.httpClient = null);
|
||||
tearDown(() {
|
||||
MessageUrlImageHelper.httpClient = null;
|
||||
MessageUrlImageHelper.loadLinkImages.value = true;
|
||||
});
|
||||
|
||||
void mockPyxPage(String id) {
|
||||
MessageUrlImageHelper.httpClient = MockClient((request) async {
|
||||
@@ -48,29 +51,45 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('parses direct ipfs cid urls', () async {
|
||||
final attachment = await MessageUrlImageHelper.parse(
|
||||
'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
|
||||
);
|
||||
|
||||
expect(attachment, isNotNull);
|
||||
test('resolves ipfs cid links with the default ipfs.io gateway', () async {
|
||||
expect(
|
||||
attachment,
|
||||
await MessageUrlImageHelper.parse(
|
||||
'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
|
||||
),
|
||||
'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
);
|
||||
expect(
|
||||
await MessageUrlImageHelper.parse(
|
||||
'my picture: ipfs:bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
|
||||
),
|
||||
'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
);
|
||||
});
|
||||
|
||||
test('parses direct ipfs cid urls without double slashes', () async {
|
||||
test('uses the configured public gateway for direct ipfs cid urls', () async {
|
||||
final attachment = await MessageUrlImageHelper.parse(
|
||||
'my picture: ipfs:bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
|
||||
'ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
publicGateway: 'https://gateway.example.com',
|
||||
);
|
||||
|
||||
expect(
|
||||
attachment,
|
||||
'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
'https://gateway.example.com/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'does not resolve ipfs cid links when the download gateway is empty',
|
||||
() async {
|
||||
final attachment = await MessageUrlImageHelper.parse(
|
||||
'ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
|
||||
publicGateway: '',
|
||||
);
|
||||
|
||||
expect(attachment, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('parses http image urls', () async {
|
||||
final attachment = await MessageUrlImageHelper.parse(
|
||||
'see this image https://example.com/picture.png?size=large additional text',
|
||||
@@ -104,5 +123,26 @@ void main() {
|
||||
|
||||
expect(attachment, isNull);
|
||||
});
|
||||
|
||||
test('fetches nothing when loading link images is off', () async {
|
||||
MessageUrlImageHelper.loadLinkImages.value = false;
|
||||
MessageUrlImageHelper.httpClient = MockClient((request) async {
|
||||
fail('Unexpected request to ${request.url}');
|
||||
});
|
||||
|
||||
for (final text in [
|
||||
'https://pyx.li/?i=RzmdkTsE',
|
||||
'https://ibb.co/abc123',
|
||||
'ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi',
|
||||
'https://example.com/photo.png',
|
||||
]) {
|
||||
expect(await MessageUrlImageHelper.parse(text), isNull);
|
||||
expect(await MessageUrlImageHelper.parseVerified(text), isNull);
|
||||
expect(
|
||||
await MessageUrlImageHelper.parseVerifiedForMessage('m1', text),
|
||||
isNull,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
|
||||
void main() {
|
||||
test('channel notification modes round-trip by name', () {
|
||||
final settings = AppSettings(
|
||||
channelNotificationModes: {
|
||||
'a': ChannelNotificationMode.mentionsOnly,
|
||||
'b': ChannelNotificationMode.muted,
|
||||
},
|
||||
);
|
||||
final json = settings.toJson();
|
||||
expect(json['channel_notification_modes'], {
|
||||
'a': 'mentionsOnly',
|
||||
'b': 'muted',
|
||||
});
|
||||
expect(json['muted_channels'], ['b']);
|
||||
expect(
|
||||
AppSettings.fromJson(json).channelNotificationModes,
|
||||
settings.channelNotificationModes,
|
||||
);
|
||||
});
|
||||
|
||||
test('invalid channel notification mode entries are skipped', () {
|
||||
final settings = AppSettings.fromJson({
|
||||
'channel_notification_modes': {
|
||||
'ok': 'muted',
|
||||
'unknown': 'loud',
|
||||
'int': 2,
|
||||
'null': null,
|
||||
},
|
||||
});
|
||||
expect(settings.channelNotificationModes, {
|
||||
'ok': ChannelNotificationMode.muted,
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
|
||||
Contact _contact(List<int> key) => Contact(
|
||||
publicKey: Uint8List.fromList(key),
|
||||
name: 'Node',
|
||||
type: advTypeChat,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
|
||||
void main() {
|
||||
final contact = _contact([0xA3, 0x0F, 0xB2, 0x44]);
|
||||
|
||||
test('formats the first pathHashByteWidth bytes as uppercase hex', () {
|
||||
expect(contact.publicKeyPrefixHex(1), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(2), 'A30F');
|
||||
expect(contact.publicKeyPrefixHex(3), 'A30FB2');
|
||||
});
|
||||
|
||||
test('clamps width to the supported 1-3 range', () {
|
||||
expect(contact.publicKeyPrefixHex(0), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(4), 'A30FB2');
|
||||
});
|
||||
|
||||
test('handles keys shorter than the width', () {
|
||||
expect(_contact([0x01]).publicKeyPrefixHex(3), '01');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:meshcore_open/models/map_path_trace_draft.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
|
||||
void main() {
|
||||
test('draft survives on the shared view state service', () {
|
||||
final service = UiViewStateService();
|
||||
final draft = service.mapPathTrace
|
||||
..active = true
|
||||
..returnPath = false;
|
||||
draft.pathBytes.addAll([0xAB, 0xCD]);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
expect(identical(service.mapPathTrace, draft), isTrue);
|
||||
expect(service.mapPathTrace.hasHops, isTrue);
|
||||
expect(service.mapPathTrace.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('clear drops hops and the last result but keeps the mode', () {
|
||||
final draft = MapPathTraceDraft()
|
||||
..returnPath = false
|
||||
..lastResultFrame = Uint8List.fromList([1, 2, 3]);
|
||||
draft.pathBytes.add(0xAB);
|
||||
draft.hopWidths.add(1);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
draft.clear();
|
||||
|
||||
expect(draft.hasHops, isFalse);
|
||||
expect(draft.hopWidths, isEmpty);
|
||||
expect(draft.points, isEmpty);
|
||||
expect(draft.lastResultFrame, isNull);
|
||||
expect(draft.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('belongsTo matches only the radio it was built on', () {
|
||||
final draft = MapPathTraceDraft();
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
draft.radioKey = Uint8List.fromList([1, 2]);
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
expect(draft.belongsTo(Uint8List.fromList([3, 4])), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -443,6 +443,53 @@ void main() {
|
||||
expect(settings.evictDiscoveredContactsEnabled, isFalse);
|
||||
});
|
||||
|
||||
test('load link images defaults on and round-trips through JSON', () {
|
||||
expect(AppSettings().loadLinkImages, isTrue);
|
||||
expect(AppSettings.fromJson({}).loadLinkImages, isTrue);
|
||||
final saved = AppSettings(loadLinkImages: false).toJson();
|
||||
expect(AppSettings.fromJson(saved).loadLinkImages, isFalse);
|
||||
});
|
||||
|
||||
test('show link images by default is off and round-trips', () {
|
||||
expect(AppSettings().showLinkImagesByDefault, isFalse);
|
||||
expect(AppSettings.fromJson({}).showLinkImagesByDefault, isFalse);
|
||||
final saved = AppSettings(showLinkImagesByDefault: true).toJson();
|
||||
expect(AppSettings.fromJson(saved).showLinkImagesByDefault, isTrue);
|
||||
});
|
||||
|
||||
test('public IPFS gateway defaults to ipfs.io when never set', () {
|
||||
expect(
|
||||
AppSettings.fromJson({}).publicIpfsGateway,
|
||||
'https://ipfs.io/ipfs/',
|
||||
);
|
||||
expect(AppSettings().publicIpfsGateway, 'https://ipfs.io/ipfs/');
|
||||
});
|
||||
|
||||
test('public IPFS gateway keeps a saved empty value as deactivated', () {
|
||||
final saved = AppSettings(publicIpfsGateway: '').toJson();
|
||||
expect(AppSettings.fromJson(saved).publicIpfsGateway, isEmpty);
|
||||
});
|
||||
|
||||
test('public IPFS gateway keeps saved ipfs.io and dweb.link values', () {
|
||||
for (final gateway in [
|
||||
'https://ipfs.io/ipfs/',
|
||||
'https://dweb.link/ipfs/',
|
||||
'https://gateway.example.com/ipfs/',
|
||||
]) {
|
||||
final saved = AppSettings(publicIpfsGateway: gateway).toJson();
|
||||
expect(AppSettings.fromJson(saved).publicIpfsGateway, gateway);
|
||||
}
|
||||
});
|
||||
|
||||
test('empty upload gateway does not fall back to the download gateway', () {
|
||||
final settings = AppSettings(
|
||||
publicIpfsGateway: 'https://gateway.example.com/ipfs/',
|
||||
uploadIpfsGateway: '',
|
||||
);
|
||||
|
||||
expect(settings.effectiveUploadIpfsGateway, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'fromJson with missing new fields uses defaults (backward compat)',
|
||||
() {
|
||||
|
||||
@@ -24,7 +24,10 @@ void main() {
|
||||
test('channel mutes made in review mode are undone on exit', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.muteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
@@ -39,23 +42,41 @@ void main() {
|
||||
|
||||
await connector.connectReview();
|
||||
// Mutes are keyed by channel name, so these would leak into real radios.
|
||||
await settings.muteChannel('Public');
|
||||
await settings.unmuteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
// Other app preferences are the user's to change, even while reviewing.
|
||||
await PrefsManager.instance.setString('unrelated_key', 'changed');
|
||||
|
||||
await connector.disconnect(manual: true);
|
||||
|
||||
expect(settings.isChannelMuted('Public'), isFalse);
|
||||
expect(settings.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(PrefsManager.instance.getString('unrelated_key'), 'changed');
|
||||
|
||||
// A fresh launch has nothing left to undo.
|
||||
final relaunched = AppSettingsService();
|
||||
await relaunched.loadSettings();
|
||||
await endReviewModeSession(relaunched);
|
||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -63,11 +84,20 @@ void main() {
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.muteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
|
||||
await beginReviewModeSession(settings);
|
||||
await settings.muteChannel('Public');
|
||||
await settings.unmuteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
await PrefsManager.instance.setString(
|
||||
'contacts${ReviewRadio.storagePrefix}',
|
||||
'[]',
|
||||
@@ -76,11 +106,20 @@ void main() {
|
||||
|
||||
final relaunched = AppSettingsService();
|
||||
await relaunched.loadSettings();
|
||||
expect(relaunched.isChannelMuted('Public'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await endReviewModeSession(relaunched);
|
||||
|
||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(
|
||||
PrefsManager.instance.getKeys().where(
|
||||
(k) => k.contains(ReviewRadio.storagePrefix),
|
||||
@@ -90,6 +129,61 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('every channel notification mode is restored on exit', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Noisy',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
|
||||
await beginReviewModeSession(settings);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Noisy',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await endReviewModeSession(settings);
|
||||
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Noisy'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
});
|
||||
|
||||
test('setting a channel back to all drops its stored mode', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(settings.settings.channelNotificationModes, isEmpty);
|
||||
});
|
||||
|
||||
test('the review scope never adopts legacy unscoped data', () async {
|
||||
await PrefsManager.instance.setString('contacts', '[]');
|
||||
await beginReviewModeSession(null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/screens/map_screen.dart';
|
||||
import 'package:meshcore_open/helpers/marker_message.dart';
|
||||
|
||||
void main() {
|
||||
test('parseMarkerText accepts in-range coordinates', () {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:meshcore_open/services/node_banner_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const _record =
|
||||
'v=1;on=1;url=https%3A%2F%2Fshop.example.com%2Fnode%3Fref%3Da%26b%3Dc;'
|
||||
'title=Need%20a%20node%3F';
|
||||
|
||||
String _doh(String data, {int status = 0, int ttl = 300}) => jsonEncode({
|
||||
'Status': status,
|
||||
'Answer': [
|
||||
{'name': '_banner.meshcoreopen.org', 'type': 16, 'TTL': ttl, 'data': data},
|
||||
],
|
||||
});
|
||||
|
||||
void main() {
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
group('NodeBannerConfig.parse', () {
|
||||
test('reads the link and decodes text overrides', () {
|
||||
final config = NodeBannerConfig.parse(_record)!;
|
||||
expect(config.url.toString(), 'https://shop.example.com/node?ref=a&b=c');
|
||||
expect(config.title, 'Need a node?');
|
||||
expect(config.body, isNull);
|
||||
expect(config.action, isNull);
|
||||
});
|
||||
|
||||
test('accepts plain-text values', () {
|
||||
final config = NodeBannerConfig.parse(
|
||||
'v=1;on=1;url=https://shop.example.com/node?ref=a&b=c;'
|
||||
'title=Need a new node?;body=Waterproof, 50% off this week.;'
|
||||
'cta=Get one here',
|
||||
)!;
|
||||
expect(config.url.toString(), 'https://shop.example.com/node?ref=a&b=c');
|
||||
expect(config.title, 'Need a new node?');
|
||||
expect(config.body, 'Waterproof, 50% off this week.');
|
||||
expect(config.action, 'Get one here');
|
||||
});
|
||||
|
||||
test('is off for on=0, unknown versions, and non-https links', () {
|
||||
expect(
|
||||
NodeBannerConfig.parse(_record.replaceAll('on=1', 'on=0')),
|
||||
isNull,
|
||||
);
|
||||
expect(NodeBannerConfig.parse(_record.replaceAll('v=1', 'v=2')), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1;url=http%3A%2F%2Fx.com'), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1'), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1;url=%E0%A4%A'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('joins split TXT character-strings and unescapes them', () {
|
||||
final answer = NodeBannerService.txtFromDohJson(
|
||||
_doh(r'"v=1;on=1;url=https%3A%2F%2Fa.com" ";title=Say \"hi\""'),
|
||||
)!;
|
||||
expect(answer.text, 'v=1;on=1;url=https%3A%2F%2Fa.com;title=Say "hi"');
|
||||
expect(answer.ttl, 300);
|
||||
});
|
||||
|
||||
test('no record or NXDOMAIN gives no answer', () {
|
||||
expect(NodeBannerService.txtFromDohJson(jsonEncode({'Status': 3})), isNull);
|
||||
expect(NodeBannerService.txtFromDohJson(jsonEncode({'Status': 0})), isNull);
|
||||
});
|
||||
|
||||
test('load queries Cloudflare DoH and caches for the TTL', () async {
|
||||
var calls = 0;
|
||||
var now = DateTime(2026, 1, 1);
|
||||
final client = MockClient((request) async {
|
||||
calls++;
|
||||
expect(request.url.host, 'cloudflare-dns.com');
|
||||
expect(request.url.queryParameters['name'], '_banner.meshcoreopen.org');
|
||||
expect(request.url.queryParameters['type'], 'TXT');
|
||||
expect(request.headers['accept'], 'application/dns-json');
|
||||
return http.Response(_doh('"$_record"'), 200);
|
||||
});
|
||||
final service = NodeBannerService(client: client, now: () => now);
|
||||
|
||||
expect((await service.load())?.title, 'Need a node?');
|
||||
expect((await service.load())?.title, 'Need a node?');
|
||||
expect(calls, 1);
|
||||
|
||||
now = now.add(const Duration(minutes: 6));
|
||||
await service.load();
|
||||
expect(calls, 2);
|
||||
});
|
||||
|
||||
test('load returns null when the lookup fails', () async {
|
||||
final failing = NodeBannerService(
|
||||
client: MockClient((_) async => throw http.ClientException('offline')),
|
||||
);
|
||||
expect(await failing.load(), isNull);
|
||||
|
||||
final serverError = NodeBannerService(
|
||||
client: MockClient((_) async => http.Response('', 503)),
|
||||
);
|
||||
expect(await serverError.load(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/gif_helper.dart';
|
||||
import 'package:meshcore_open/helpers/reaction_helper.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/widgets/marker_label_dialog.dart';
|
||||
|
||||
void main() {
|
||||
final l10n = lookupAppLocalizations(const Locale('en'));
|
||||
String format(String text) =>
|
||||
NotificationService.formatNotificationText(text, l10n);
|
||||
|
||||
test('shared locations show a summary instead of coordinates', () {
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, 'Camp', 'poi')),
|
||||
'Shared a location: Camp',
|
||||
);
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, '', 'poi')),
|
||||
'Shared a location',
|
||||
);
|
||||
});
|
||||
|
||||
test('reactions, GIFs and images are summarized', () {
|
||||
expect(
|
||||
format(ReactionHelper.encodeReaction('ab12', '00')),
|
||||
startsWith('Reacted '),
|
||||
);
|
||||
expect(format('👍\nabcd2345'), 'Reacted 👍');
|
||||
expect(format(GifHelper.encodeGif('xT9IgG50Fb7Mi0prBC')), 'Sent a GIF');
|
||||
expect(
|
||||
format('https://media.giphy.com/media/xT9IgG50Fb7Mi0prBC/giphy.gif'),
|
||||
'Sent a GIF',
|
||||
);
|
||||
expect(format(ReceivedImageRef.encode('0a1b2c3d4e5f60')), 'Sent an image');
|
||||
});
|
||||
|
||||
test('plain text is unchanged', () {
|
||||
expect(format('see you at m:ain street'), 'see you at m:ain street');
|
||||
expect(format('hello'), 'hello');
|
||||
});
|
||||
}
|
||||
@@ -858,6 +858,8 @@ void main() {
|
||||
svc.recordPathResult(pubKey, sel, success: true, successIncrement: 0.5);
|
||||
}
|
||||
await _flush();
|
||||
// Saves are batched; a restart only follows a flush (app backgrounded).
|
||||
await svc.flushPendingWrites();
|
||||
|
||||
final fresh = PathHistoryService(storage);
|
||||
fresh.recordPathResult(pubKey, sel, success: true, successIncrement: 0.5);
|
||||
@@ -871,6 +873,7 @@ void main() {
|
||||
test('getRecentPaths load does not drop a concurrent add', () async {
|
||||
final pubKey = _hex('k004');
|
||||
await _seed(svc, pubKey, pathBytes: [0x01], weight: 1.0);
|
||||
await svc.flushPendingWrites();
|
||||
|
||||
final fresh = PathHistoryService(storage);
|
||||
fresh.getRecentPaths(pubKey);
|
||||
|
||||
@@ -61,30 +61,34 @@ int _readIntOption(Socket socket, int level, int option) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('connect enables TCP keepalive with short probe timings', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
}, skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones');
|
||||
test(
|
||||
'connect enables TCP keepalive with short probe timings',
|
||||
() async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
},
|
||||
skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones',
|
||||
);
|
||||
|
||||
test('connect/disconnect updates TCP transport state', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/utils/channel_qr.dart';
|
||||
|
||||
void main() {
|
||||
group('parseChannelQr', () {
|
||||
test('parses the official channel link', () {
|
||||
final result = parseChannelQr(
|
||||
'meshcore://channel/add?name=Public&secret=8b3387e9c5cdea6ac9e5edbaa115cd72',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.name, 'Public');
|
||||
expect(result.psk.length, 16);
|
||||
expect(result.psk[0], 0x8b);
|
||||
expect(result.psk[15], 0x72);
|
||||
});
|
||||
|
||||
test('decodes URL-encoded names and uppercase hex', () {
|
||||
final result = parseChannelQr(
|
||||
'meshcore://channel/add?name=%23ipnet%20test&secret=${'AB' * 16}',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.name, '#ipnet test');
|
||||
expect(result.psk.every((b) => b == 0xab), isTrue);
|
||||
});
|
||||
|
||||
test('ignores the optional region_scope parameter', () {
|
||||
final result = parseChannelQr(
|
||||
'meshcore://channel/add?name=Test&secret=${'00' * 16}®ion_scope=gb-est',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.name, 'Test');
|
||||
});
|
||||
|
||||
test('rejects missing name, bad secret and other links', () {
|
||||
expect(
|
||||
parseChannelQr('meshcore://channel/add?secret=${'00' * 16}'),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
parseChannelQr('meshcore://channel/add?name=X&secret=abcd'),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
parseChannelQr('meshcore://channel/add?name=X&secret=${'zz' * 16}'),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
parseChannelQr('meshcore://contact/add?name=X&public_key=${'00' * 32}'),
|
||||
isNull,
|
||||
);
|
||||
expect(parseChannelQr('https://ipnt.uk/channels'), isNull);
|
||||
expect(
|
||||
parseChannelQr(
|
||||
'meshcore://channel/add?name=%FF&secret=8b3387e9c5cdea6ac9e5edbaa115cd72',
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(parseChannelQr('{"type":"meshcore_community"}'), isNull);
|
||||
expect(parseChannelQr(''), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/utils/coalesced_writes.dart';
|
||||
|
||||
const _delay = Duration(milliseconds: 40);
|
||||
|
||||
Future<void> _wait(int ms) => Future<void>.delayed(Duration(milliseconds: ms));
|
||||
|
||||
void main() {
|
||||
test('repeated schedules for a key run only the latest write once', () async {
|
||||
final writes = CoalescedWrites(delay: _delay);
|
||||
final ran = <String>[];
|
||||
for (var i = 0; i < 100; i++) {
|
||||
writes.schedule('channel:a', () async => ran.add('a$i'));
|
||||
}
|
||||
writes.schedule('contacts', () async => ran.add('contacts'));
|
||||
|
||||
expect(ran, isEmpty);
|
||||
await _wait(120);
|
||||
expect(ran, ['a99', 'contacts']);
|
||||
expect(writes.hasPending, isFalse);
|
||||
});
|
||||
|
||||
test('a steady stream of schedules does not push the write back', () async {
|
||||
final writes = CoalescedWrites(delay: _delay);
|
||||
var count = 0;
|
||||
final stop = DateTime.now().add(const Duration(milliseconds: 300));
|
||||
while (DateTime.now().isBefore(stop)) {
|
||||
writes.schedule('k', () async => count++);
|
||||
await _wait(5);
|
||||
}
|
||||
// Persistence keeps landing while frames keep arriving.
|
||||
expect(count, greaterThanOrEqualTo(3));
|
||||
await writes.flush();
|
||||
});
|
||||
|
||||
test('flush starts every write synchronously and clears the queue', () {
|
||||
final writes = CoalescedWrites();
|
||||
final ran = <String>[];
|
||||
writes.schedule('a', () async => ran.add('a'));
|
||||
writes.schedule('b', () async => ran.add('b'));
|
||||
|
||||
final done = writes.flush();
|
||||
// Stores read their scoped key on entry, before any await.
|
||||
expect(ran, ['a', 'b']);
|
||||
expect(writes.hasPending, isFalse);
|
||||
return done;
|
||||
});
|
||||
|
||||
test('cancel drops a queued write', () async {
|
||||
final writes = CoalescedWrites(delay: _delay);
|
||||
var ran = false;
|
||||
writes.schedule('channel:a', () async => ran = true);
|
||||
writes.cancel('channel:a');
|
||||
await _wait(120);
|
||||
expect(ran, isFalse);
|
||||
});
|
||||
|
||||
test('a failing write does not stop the others', () async {
|
||||
final writes = CoalescedWrites();
|
||||
var ran = false;
|
||||
writes.schedule('bad', () => throw StateError('boom'));
|
||||
writes.schedule('good', () async => ran = true);
|
||||
await writes.flush();
|
||||
expect(ran, isTrue);
|
||||
});
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/node_banner_service.dart';
|
||||
import 'package:meshcore_open/widgets/get_node_banner.dart';
|
||||
|
||||
final _config = NodeBannerConfig(url: Uri.parse('https://example.com/node'));
|
||||
|
||||
void main() {
|
||||
Future<void> pumpBanner(
|
||||
WidgetTester tester, {
|
||||
required Size size,
|
||||
required double textScale,
|
||||
NodeBannerConfig? config,
|
||||
bool hidden = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -21,7 +26,11 @@ void main() {
|
||||
size: size,
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
),
|
||||
child: const Scaffold(bottomNavigationBar: GetNodeBanner()),
|
||||
child: Scaffold(
|
||||
bottomNavigationBar: GetNodeBanner(
|
||||
loadConfig: () async => hidden ? null : config ?? _config,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -29,11 +38,11 @@ void main() {
|
||||
|
||||
testWidgets('shows the pitch and affiliate link', (tester) async {
|
||||
await pumpBanner(tester, size: const Size(390, 844), textScale: 1);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Need a new node?'), findsOneWidget);
|
||||
expect(find.text('Get one here'), findsOneWidget);
|
||||
expect(find.textContaining('Affiliate link'), findsOneWidget);
|
||||
expect(getNodeUrl, contains('sensecap_affiliate=JFWID0g'));
|
||||
// Leaves most of the screen for the device list.
|
||||
expect(
|
||||
tester.getSize(find.byType(GetNodeBanner)).height,
|
||||
@@ -43,6 +52,38 @@ void main() {
|
||||
|
||||
testWidgets('lays out on a narrow phone with large text', (tester) async {
|
||||
await pumpBanner(tester, size: const Size(320, 800), textScale: 1.5);
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('uses text overrides from the record', (tester) async {
|
||||
await pumpBanner(
|
||||
tester,
|
||||
size: const Size(390, 844),
|
||||
textScale: 1,
|
||||
config: NodeBannerConfig(
|
||||
url: Uri.parse('https://example.com'),
|
||||
title: 'Spring sale',
|
||||
action: 'Shop now',
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Spring sale'), findsOneWidget);
|
||||
expect(find.text('Shop now'), findsOneWidget);
|
||||
expect(find.textContaining('Affiliate link'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows nothing when there is no config', (tester) async {
|
||||
await pumpBanner(
|
||||
tester,
|
||||
size: const Size(390, 844),
|
||||
textScale: 1,
|
||||
hidden: true,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InkWell), findsNothing);
|
||||
expect(tester.getSize(find.byType(GetNodeBanner)).height, 0);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user