Files
study-bible-project/src/utils/noteHistory.test.js
T
nmemmertandClaude Sonnet 5.5 67645cf1df App quality: offline badge, per-note history, keyboard study mode, notes import
- Study cards say whether the Bible text works offline, with a button to save
  the missing book (notes are always kept on the device).
- Each note keeps its last 12 versions with Restore (History under each note).
- Keyboard-only study: 1/2/3 write in Observe/Interpret/Apply, C/W/X/P switch
  resource tabs, V compares, Esc leaves a note box; listed under "?".
- Export > Import notes: bring Word/Markdown/text notes into the matching
  chunks without overwriting anything; can mark them as not your own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 13:01:11 -04:00

27 lines
1.2 KiB
JavaScript

import { beforeEach, expect, test } from 'vitest';
import { MAX_VERSIONS, listNoteVersions, recordNoteVersion } from './noteHistory.js';
beforeEach(() => localStorage.clear());
test('versions are kept newest first, and blanks and repeats are skipped', () => {
recordNoteVersion('c1', 'observation', 'first', 1);
recordNoteVersion('c1', 'observation', 'first', 2); // same as the newest
recordNoteVersion('c1', 'observation', ' ', 3); // blank
recordNoteVersion('c1', 'observation', 'second', 4);
expect(listNoteVersions('c1', 'observation').map((v) => v.text)).toEqual(['second', 'first']);
expect(listNoteVersions('c1', 'application')).toEqual([]);
expect(listNoteVersions('c2', 'observation')).toEqual([]);
});
test('only the latest versions are kept', () => {
for (let i = 0; i < MAX_VERSIONS + 5; i += 1) recordNoteVersion('c1', 'observation', `v${i}`, i);
const list = listNoteVersions('c1', 'observation');
expect(list).toHaveLength(MAX_VERSIONS);
expect(list[0].text).toBe(`v${MAX_VERSIONS + 4}`);
});
test('a damaged store reads as empty', () => {
localStorage.setItem('note-history:c1:observation', '{nope');
expect(listNoteVersions('c1', 'observation')).toEqual([]);
});