Commit 98f2c42
Changed files (9)
app
lib
test
model
export_import
ui
components
measurement_list
app/lib/app.dart
@@ -67,7 +67,6 @@ class _AppState extends State<App> {
/// Load the primary app data asynchronously to allow load animations.
Future<Widget> _loadApp() async {
WidgetsFlutterBinding.ensureInitialized();
-
if (_loadedChild != null && _configDB != null && _entryDB != null) return _loadedChild!;
if (widget.forceClearAppDataOnLaunch) {
@@ -90,13 +89,12 @@ class _AppState extends State<App> {
_configDB = await ConfigDB.open();
final configDao = ConfigDao(_configDB!);
- assert(_settings == null);
- _settings = await configDao.loadSettings(0);
- _exportSettings = await configDao.loadExportSettings(0);
- _csvExportSettings = await configDao.loadCsvExportSettings(0);
- _pdfExportSettings = await configDao.loadPdfExportSettings(0);
- _intervallStorageManager = await IntervallStoreManager.load(configDao, 0);
- _exportColumnsManager = await configDao.loadExportColumnsManager(0);
+ _settings ??= await configDao.loadSettings(0);
+ _exportSettings ??= await configDao.loadExportSettings(0);
+ _csvExportSettings ??= await configDao.loadCsvExportSettings(0);
+ _pdfExportSettings ??= await configDao.loadPdfExportSettings(0);
+ _intervallStorageManager ??= await IntervallStoreManager.load(configDao, 0);
+ _exportColumnsManager ??= await configDao.loadExportColumnsManager(0);
_entryDB = await openDatabase(
join(await getDatabasesPath(), 'bp.db'),
app/test/model/export_import/exported_formats/formatted_times.csv
@@ -0,0 +1,4 @@
+someTime,systolic
+2024-03-12 15:45,1
+2004-12-08 00:42,2
+2012-10-8 0:4,3
\ No newline at end of file
app/test/model/export_import/exported_formats/v1.6.4.db
Binary file
app/test/model/export_import/exported_formats/v1.7.0.db
Binary file
app/test/model/export_import/csv_converter_test.dart
@@ -1,7 +1,9 @@
import 'dart:io';
+import 'package:blood_pressure_app/model/export_import/column.dart';
import 'package:blood_pressure_app/model/export_import/csv_converter.dart';
+import 'package:blood_pressure_app/model/export_import/export_configuration.dart';
import 'package:blood_pressure_app/model/export_import/record_parsing_result.dart';
import 'package:blood_pressure_app/model/storage/export_columns_store.dart';
import 'package:blood_pressure_app/model/storage/export_csv_settings_store.dart';
@@ -296,7 +298,50 @@ void main() {
.having((p0) => p0.$2.note, 'notes', '')
.having((p0) => p0.$2.color, 'pin', null),
),);
- // TODO: test time columns
+ });
+ test('should decode formated times', () {
+ final text = File('test/model/export_import/exported_formats/formatted_times.csv').readAsStringSync();
+
+ final cols = ExportColumnsManager();
+ cols.addOrUpdate(TimeColumn('someTime', 'yyyy-MM-dd HH:mm'));
+ final converter = CsvConverter(
+ CsvExportSettings(
+ exportFieldsConfiguration: ActiveExportColumnConfiguration(
+ activePreset: ExportImportPreset.none,
+ userSelectedColumnIds: [],
+ )
+ ),
+ cols,
+ );
+ final parsed = converter.parse(text);
+
+ final records = parsed.getOr(failParse);
+ expect(records, isNotNull);
+ expect(records.length, 3);
+ expect(records, contains(isA<FullEntry>()
+ .having((c) => c.sys?.mmHg, 'sys', 1)
+ .having((c) => c.time.year, 'year', 2024)
+ .having((c) => c.time.month, 'month', 3)
+ .having((c) => c.time.day, 'day', 12)
+ .having((c) => c.time.hour, 'hour', 15)
+ .having((c) => c.time.minute, 'minute', 45),
+ ));
+ expect(records, contains(isA<FullEntry>()
+ .having((c) => c.sys?.mmHg, 'sys', 2)
+ .having((c) => c.time.year, 'year', 2004)
+ .having((c) => c.time.month, 'month', 12)
+ .having((c) => c.time.day, 'day', 8)
+ .having((c) => c.time.hour, 'hour', 0)
+ .having((c) => c.time.minute, 'minute', 42),
+ ));
+ expect(records, contains(isA<FullEntry>()
+ .having((c) => c.sys?.mmHg, 'sys', 3)
+ .having((c) => c.time.year, 'year', 2012)
+ .having((c) => c.time.month, 'month', 10)
+ .having((c) => c.time.day, 'day', 8)
+ .having((c) => c.time.hour, 'hour', 0)
+ .having((c) => c.time.minute, 'minute', 4),
+ ));
});
}
app/test/model/bood_pressure_test.dart
@@ -34,6 +34,35 @@ void main() {
.create(dbPath: join(inMemoryDatabasePath, 'BPMShouldInit.db'));
expect(model, isNull);
});
- // TODO: test loading with db files from older versions
+ /* TODO: make reliable and reduce test data size
+ test('correctly loads db from v1.6.4 and prior', () async {
+
+ final model = await BloodPressureModel.create(dbPath: 'test/model/export_import/exported_formats/v1.6.4.db', isFullPath: true);
+ expect(model, isNotNull);
+
+ final all = await model!.all;
+ expect(all, hasLength(27620));
+ expect(all, contains(isA<OldBloodPressureRecord>()
+ .having((r) => r.creationTime.millisecondsSinceEpoch, 'time', 1077625200000)
+ .having((r) => r.systolic, 'sys', 100)
+ .having((r) => r.diastolic, 'dia', 82)
+ .having((r) => r.pulse, 'pul', 63),
+ ));
+ }, timeout: Timeout(Duration(minutes: 3)));
+ test('correctly loads db from v1.7.0 and later', () async {
+ sqfliteFfiInit();
+ final db = await databaseFactoryFfi.openDatabase('test/model/export_import/exported_formats/v1.7.0.db');
+ final hDataStore = await HealthDataStore.load(db);
+ final bpRepo = hDataStore.bpRepo;
+
+ final all = await bpRepo.get(DateRange.all());
+ expect(all, hasLength(27620));
+ expect(all, contains(isA<FullEntry>()
+ .having((r) => r.time.millisecondsSinceEpoch, 'time', 1077625200000)
+ .having((r) => r.sys, 'sys', 100)
+ .having((r) => r.dia, 'dia', 82)
+ .having((r) => r.pul, 'pul', 63),
+ ));
+ }, timeout: Timeout(Duration(minutes: 3)));*/
});
}
app/test/ui/components/measurement_list/measurement_list_entry_test.dart
@@ -91,13 +91,6 @@ void main() {
expect(requestCount, 1);
- /* TODO: use somewhere else
- /// Finder of text widgets that are descendants of the AddEntryDialoge.
- Finder descTxt(String txt) => find.descendant(
- of: find.byType(AddEntryDialoge),
- matching: find.text(txt),
- );*/
-
}, timeout: const Timeout(Duration(seconds: 10)),);
testWidgets('should indicate presence of intakes', (tester) async {
await tester.pumpWidget(materialApp(MeasurementListRow(
app/test/ui/statistics_test_.dart
@@ -14,7 +14,6 @@ import 'components/util.dart';
void main() {
testWidgets('should load page', (tester) async {
- // FIXME: doesn't finish
await _initStatsPage(tester, []);
expect(tester.takeException(), isNull);