mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-11 19:53:53 +01:00
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>
25 lines
795 B
Dart
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
|