Prayer journal: pinning, waiting/partial status, import, dashboard card
Build and Push Docker Image / build-and-push (push) Successful in 5m14s
Build and Push Docker Image / build-and-push (push) Successful in 5m14s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d647e8d8a
commit
1cf157be64
10 files changed
+365
-22
No files matched your search
@@ -68,3 +68,52 @@ test('the Markdown separates what is being prayed for from what was answered', (
|
||||
expect(md).toContain(': Hired!');
|
||||
expect(prayersToMarkdown([])).toContain('No prayers yet.');
|
||||
});
|
||||
|
||||
import { movePinned, parsePrayerImport, pinned, prayersToJson, setPinned, setStatus } from './prayers.js';
|
||||
|
||||
test('pinning orders prayers, moving swaps them, and answering unpins', () => {
|
||||
let list = ['a', 'b', 'c'].map((t, i) => newPrayer({ text: t }, T0 + i));
|
||||
const [a, b, c] = list.map((p) => p.id);
|
||||
list = setPinned(list, b, true, T0 + 10);
|
||||
list = setPinned(list, a, true, T0 + 11);
|
||||
expect(pinned(list).map((p) => p.id)).toEqual([b, a]);
|
||||
list = movePinned(list, a, -1, T0 + 12);
|
||||
expect(pinned(list).map((p) => p.id)).toEqual([a, b]);
|
||||
expect(movePinned(list, a, -1)).toBe(list); // already first
|
||||
expect(filterPrayers(list, { tab: 'open' }).map((p) => p.id)[0]).toBe(a);
|
||||
expect(filterPrayers(list, { tab: 'open' }).map((p) => p.id)).toEqual([a, b, c]);
|
||||
list = list.map((p) => (p.id === a ? markAnswered(p, '', T0 + 20) : p));
|
||||
expect(pinned(list).map((p) => p.id)).toEqual([b]);
|
||||
});
|
||||
|
||||
test('waiting and partly answered stay open; partial keeps a note; answering clears them', () => {
|
||||
let p = setStatus(newPrayer({ text: 'x' }, T0), 'partial', ' half way ', T0 + 1);
|
||||
expect(p).toMatchObject({ status: 'partial', answerNote: 'half way', answeredAt: null });
|
||||
p = setStatus(p, 'waiting', 'ignored', T0 + 2);
|
||||
expect(p).toMatchObject({ status: 'waiting', answerNote: '' });
|
||||
expect(setStatus(p, '', '', T0 + 3).status).toBe('');
|
||||
expect(markAnswered(p, 'done', T0 + 4)).toMatchObject({ status: '', answeredAt: T0 + 4 });
|
||||
});
|
||||
|
||||
test('import reads our markdown and JSON, and skips prayers already in the journal', () => {
|
||||
const src = [
|
||||
{ ...newPrayer({ text: 'Wisdom', forWhom: 'Sam', verses: [{ book: 'JAS', chapter: 1, verse: 5, label: 'James 1:5' }] }, T0), pinned: true, rank: 1, status: 'waiting' },
|
||||
markAnswered(newPrayer({ text: 'A job' }, T0), 'Hired', T0 + DAY),
|
||||
];
|
||||
const md = prayersToMarkdown(src, { date: new Date(T0) });
|
||||
const fromMd = parsePrayerImport(md, [], T0);
|
||||
expect(fromMd.prayers).toHaveLength(2);
|
||||
expect(fromMd.prayers[0]).toMatchObject({ text: 'Wisdom', forWhom: 'Sam', status: 'waiting', pinned: true, answeredAt: null });
|
||||
expect(fromMd.prayers[0].verses[0]).toMatchObject({ book: 'JAS', chapter: 1, verse: 5 });
|
||||
expect(fromMd.prayers[1]).toMatchObject({ text: 'A job', answerNote: 'Hired' });
|
||||
expect(fromMd.prayers[1].answeredAt).toBeTruthy();
|
||||
|
||||
const fromJson = parsePrayerImport(prayersToJson(src), [], T0);
|
||||
expect(fromJson.prayers.map((p) => p.id)).toEqual(src.map((p) => p.id));
|
||||
expect(fromJson.prayers[0]).toMatchObject({ pinned: true, status: 'waiting' });
|
||||
|
||||
expect(parsePrayerImport(prayersToJson(src), [src[0]], T0)).toMatchObject({ skipped: 1, prayers: [expect.objectContaining({ text: 'A job' })] });
|
||||
expect(parsePrayerImport(md, [src[0]], T0).prayers.map((p) => p.text)).toEqual(['A job']); // same words, same person
|
||||
expect(parsePrayerImport('{"nope":1}', []).error).toBeTruthy();
|
||||
expect(parsePrayerImport('', []).error).toBeTruthy();
|
||||
});
|
||||
Reference in new issue
Block a user