mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-19 00:34:34 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Todo: fda71ed1 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
/// Tests for the file-backed revision cache.
|
|
///
|
|
/// The cache is what keeps a sync tick from re-downloading every peer's whole
|
|
/// log when nothing has changed, so "does it actually survive a restart" is
|
|
/// the behaviour worth pinning.
|
|
@TestOn('vm')
|
|
library;
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:todo/sync/sync_state_factory_io.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
void main() {
|
|
late Directory dir;
|
|
|
|
setUp(() async {
|
|
dir = await Directory.systemTemp.createTemp('todo_state_');
|
|
});
|
|
|
|
tearDown(() async {
|
|
if (dir.existsSync()) await dir.delete(recursive: true);
|
|
});
|
|
|
|
test('persists revisions across a restart', () async {
|
|
// A fresh store instance stands in for the next app launch: an
|
|
// in-memory cache would forget every peer and re-download everything.
|
|
await openSyncStateStoreIn(
|
|
dir.path,
|
|
).save(const SyncState(pushedRev: 'mine', peerRevs: {'phone': 'theirs'}));
|
|
|
|
final reloaded = await openSyncStateStoreIn(dir.path).load();
|
|
|
|
expect(reloaded.pushedRev, 'mine');
|
|
expect(reloaded.peerRevs, {'phone': 'theirs'});
|
|
});
|
|
|
|
test('writes beside the log it describes', () async {
|
|
await openSyncStateStoreIn(dir.path).save(const SyncState(pushedRev: 'x'));
|
|
|
|
expect(File(p.join(dir.path, kSyncStateFileName)).existsSync(), isTrue);
|
|
});
|
|
|
|
test('reports nothing remembered before the first sync', () async {
|
|
final state = await openSyncStateStoreIn(dir.path).load();
|
|
|
|
expect(state.pushedRev, isNull);
|
|
expect(state.peerRevs, isEmpty);
|
|
});
|
|
}
|