only-bible-app v3.7.2+24
git clone https://git.pyrossh.dev/only-bible-app
The only bible app you will ever need. No ads. No in-app purchases. No distractions.
test/actions_backup_test.dart
| fe24dd6 | 1 | import "dart:convert"; |
| fe24dd6 | 2 | |
| c2e460a | 3 | import "package:flutter/material.dart"; |
| fe24dd6 | 4 | import "package:flutter_test/flutter_test.dart"; |
| fe24dd6 | 5 | import "package:only_bible_app/store/actions_backup.dart"; |
| fe24dd6 | 6 | import "package:only_bible_app/store/app_state.dart"; |
| fe24dd6 | 7 | |
| fe24dd6 | 8 | import "app_logic_test.dart" show buildTestBible; |
| fe24dd6 | 9 | |
| fe24dd6 | 10 | void main() { |
| fe24dd6 | 11 | group("buildBackupFileName", () { |
| fe24dd6 | 12 | test("formats a zero-padded date", () { |
| fe24dd6 | 13 | expect( |
| fe24dd6 | 14 | buildBackupFileName(DateTime.utc(2026, 3, 5)), |
| fe24dd6 | 15 | "only_bible_app_backup_2026-03-05.json", |
| fe24dd6 | 16 | ); |
| fe24dd6 | 17 | }); |
| fe24dd6 | 18 | }); |
| fe24dd6 | 19 | |
| fe24dd6 | 20 | group("buildBackupJson / parseBackupState", () { |
| fe24dd6 | 21 | test("round-trips highlights and settings through export and import", () async { |
| fe24dd6 | 22 | final bible = buildTestBible(); |
| fe24dd6 | 23 | final state = AppState( |
| fe24dd6 | 24 | bible: bible, |
| c2e460a | 25 | themeMode: ThemeMode.dark, |
| fe24dd6 | 26 | fontSize: 22, |
| fe24dd6 | 27 | highlights: {"0:0:0": 2}, |
| fe24dd6 | 28 | highlightHistory: [ |
| fe24dd6 | 29 | HighlightHistoryEntry(book: 0, chapter: 0, verseIndex: 0, colorIndex: 2, timestamp: DateTime.utc(2026, 1, 1)), |
| fe24dd6 | 30 | ], |
| fe24dd6 | 31 | ); |
| fe24dd6 | 32 | |
| fe24dd6 | 33 | final jsonString = buildBackupJson(state); |
| fe24dd6 | 34 | final restored = await parseBackupState(jsonString, loadBibleFn: (_) async => bible); |
| fe24dd6 | 35 | |
| c2e460a | 36 | expect(restored.themeMode, ThemeMode.dark); |
| fe24dd6 | 37 | expect(restored.fontSize, 22); |
| fe24dd6 | 38 | expect(restored.highlights["0:0:0"], 2); |
| fe24dd6 | 39 | expect(restored.highlightHistory.single.colorIndex, 2); |
| fe24dd6 | 40 | }); |
| fe24dd6 | 41 | |
| fe24dd6 | 42 | test("rejects malformed JSON", () async { |
| fe24dd6 | 43 | expect( |
| fe24dd6 | 44 | () => parseBackupState("not json", loadBibleFn: (_) async => buildTestBible()), |
| fe24dd6 | 45 | throwsA(isA<BackupParseException>()), |
| fe24dd6 | 46 | ); |
| fe24dd6 | 47 | }); |
| fe24dd6 | 48 | |
| fe24dd6 | 49 | test("rejects valid JSON that isn't an object", () async { |
| fe24dd6 | 50 | expect( |
| fe24dd6 | 51 | () => parseBackupState(jsonEncode([1, 2, 3]), loadBibleFn: (_) async => buildTestBible()), |
| fe24dd6 | 52 | throwsA(isA<BackupParseException>()), |
| fe24dd6 | 53 | ); |
| fe24dd6 | 54 | }); |
| fe24dd6 | 55 | |
| fe24dd6 | 56 | test("rejects a bibleName the app can't load", () async { |
| fe24dd6 | 57 | expect( |
| fe24dd6 | 58 | () => parseBackupState( |
| fe24dd6 | 59 | jsonEncode({"bibleName": "does_not_exist"}), |
| fe24dd6 | 60 | loadBibleFn: (_) async => throw Exception("no such asset"), |
| fe24dd6 | 61 | ), |
| fe24dd6 | 62 | throwsA(isA<BackupParseException>()), |
| fe24dd6 | 63 | ); |
| fe24dd6 | 64 | }); |
| fe24dd6 | 65 | }); |
| fe24dd6 | 66 | } |