diet-guard/app/lib/services/document_store_web.dart
Krzysztof kuhy Rudnicki 2231850bfc app: test the IndexedDB stores instead of shipping them unverified
The IndexedDB stores are the desktop device's primary copy of the food log and
the *only* copy of its photos -- photos never sync -- and their wrapper-mirror
fallback is what makes a wiped Chrome profile recoverable. All of that was
invisible to the suite: the files import `idb_browser.dart`, which cannot be
imported outside a web compile, so they were simply absent from the VM test
run rather than covered.

Splitting the store classes from the browser-factory `open…()` functions lets
them run against `idb_shim`'s in-memory backend on the plain VM, which is what
the flutter-desktop-to-chrome skill recommends the shim for. Twelve tests now
pin the round-trip, the mirror write, the recover-from-mirror path, and the
no-wrapper-running case (a plain browser tab, where the app must still work).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 16:56:15 +02:00

25 lines
795 B
Dart

/// Opens the IndexedDB-backed [DocumentStore] in the browser.
library;
import 'package:diet_guard_app/services/document_store.dart';
import 'package:diet_guard_app/services/document_store_indexeddb.dart';
import 'package:idb_shim/idb_browser.dart';
/// Opens (creating if needed) the IndexedDB-backed document store.
// coverage:ignore-start
Future<DocumentStore> openDocumentStore() async {
final database = await idbFactoryBrowser.open(
IndexedDbDocumentStore.databaseName,
version: 1,
onUpgradeNeeded: (event) {
final db = event.database;
if (!db.objectStoreNames.contains(IndexedDbDocumentStore.storeName)) {
db.createObjectStore(IndexedDbDocumentStore.storeName);
}
},
);
return IndexedDbDocumentStore(database);
}
// coverage:ignore-end