removeContact now waits for the radio's reply and only drops the contact locally when the radio confirms (or reports it doesn't have it), so a lost command no longer leaves a contact that the next sync restores. Failures are shown to the user. The delete dialog warns when the radio auto-adds that contact type, since the contact returns on its next advert.
82 lines
3.0 KiB
Dart
82 lines
3.0 KiB
Dart
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));
|
|
}
|
|
}
|
|
|
|
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()),
|
|
);
|
|
connector.reviewRadioFactoryForTest = () =>
|
|
ReviewRadio(scheduledMessageInterval: const Duration(hours: 1));
|
|
|
|
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);
|
|
|
|
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);
|
|
});
|
|
}
|