Refine backendless share intake
This commit is contained in:
@@ -10,7 +10,7 @@ import 'package:relationship_saver/features/sync/sync_coordinator.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'triggers sync when reachability transitions from offline to online',
|
||||
'does not trigger sync when background sync is disabled by default',
|
||||
(WidgetTester tester) async {
|
||||
final _TestReachability reachability = _TestReachability(initial: false);
|
||||
addTearDown(reachability.dispose);
|
||||
@@ -39,56 +39,56 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
|
||||
// Startup trigger always runs once when background sync is enabled.
|
||||
expect(syncCalls, 1);
|
||||
expect(syncCalls, 0);
|
||||
|
||||
reachability.emit(false);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 40));
|
||||
expect(syncCalls, 1);
|
||||
expect(syncCalls, 0);
|
||||
|
||||
reachability.emit(true);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
expect(syncCalls, 2);
|
||||
expect(syncCalls, 0);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('does not trigger extra sync while connectivity stays online', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final _TestReachability reachability = _TestReachability(initial: true);
|
||||
addTearDown(reachability.dispose);
|
||||
testWidgets(
|
||||
'does not trigger sync while connectivity stays online by default',
|
||||
(WidgetTester tester) async {
|
||||
final _TestReachability reachability = _TestReachability(initial: true);
|
||||
addTearDown(reachability.dispose);
|
||||
|
||||
int syncCalls = 0;
|
||||
int syncCalls = 0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
networkReachabilityProvider.overrideWithValue(reachability),
|
||||
syncCoordinatorProvider.overrideWith(
|
||||
(Ref ref) => _TestSyncCoordinator(
|
||||
ref,
|
||||
onSyncNow: () async {
|
||||
syncCalls += 1;
|
||||
return _okResult();
|
||||
},
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
networkReachabilityProvider.overrideWithValue(reachability),
|
||||
syncCoordinatorProvider.overrideWith(
|
||||
(Ref ref) => _TestSyncCoordinator(
|
||||
ref,
|
||||
onSyncNow: () async {
|
||||
syncCalls += 1;
|
||||
return _okResult();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
child: const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: SyncBackgroundRunner(child: SizedBox()),
|
||||
),
|
||||
],
|
||||
child: const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: SyncBackgroundRunner(child: SizedBox()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
|
||||
expect(syncCalls, 1);
|
||||
expect(syncCalls, 0);
|
||||
|
||||
reachability.emit(true);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
reachability.emit(true);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 60));
|
||||
|
||||
expect(syncCalls, 1);
|
||||
});
|
||||
expect(syncCalls, 0);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _TestSyncCoordinator extends SyncCoordinator {
|
||||
|
||||
@@ -111,6 +111,29 @@ void main() {
|
||||
);
|
||||
expect(queueState.cursor, 'cursor-remote-1');
|
||||
});
|
||||
|
||||
test('default fake pull is inert and does not seed people', () async {
|
||||
final ProviderContainer container = ProviderContainer(
|
||||
overrides: [
|
||||
backendGatewayProvider.overrideWithValue(BackendGatewayFake()),
|
||||
localDataStoreProvider.overrideWithValue(InMemoryLocalDataStore()),
|
||||
syncStateStoreProvider.overrideWithValue(InMemorySyncStateStore()),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
await container.read(localRepositoryProvider.future);
|
||||
|
||||
final SyncRunResult result = await container
|
||||
.read(syncCoordinatorProvider)
|
||||
.pullRemote();
|
||||
|
||||
expect(result.success, isTrue);
|
||||
expect(result.pulled, 0);
|
||||
|
||||
final localState = await container.read(localRepositoryProvider.future);
|
||||
expect(localState.people, isEmpty);
|
||||
});
|
||||
}
|
||||
|
||||
class _TestGateway extends BackendGatewayFake {
|
||||
|
||||
@@ -23,6 +23,15 @@ void main() {
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
await container.read(localRepositoryProvider.future);
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addPerson(
|
||||
name: 'Repair Person',
|
||||
relationship: 'Friend',
|
||||
notes: '',
|
||||
tags: const <String>[],
|
||||
);
|
||||
final localBefore = await container.read(localRepositoryProvider.future);
|
||||
final person = localBefore.people.first;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user