Repository navigation
Expand file tree
/
Copy pathslideLibrary.test.ts
More file actions
77 lines (64 loc) · 2.62 KB
/
Copy pathslideLibrary.test.ts
File metadata and controls
77 lines (64 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import fs from 'fs/promises';
import os from 'os';
import path from 'path';
import { SlideLibrary } from './slideLibrary.ts';
describe('SlideLibrary', () => {
let dir: string;
let filePath: string;
beforeEach(async () => {
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'slide-lib-'));
filePath = path.join(dir, 'library.json');
});
afterEach(async () => {
await fs.rm(dir, { recursive: true, force: true });
});
it('treats a missing file as an empty library', async () => {
const lib = new SlideLibrary(filePath);
await lib.load();
expect(lib.list()).toEqual([]);
expect(lib.lookup('French', 'anything')).toBeUndefined();
});
it('upserts a reviewed entry and looks it up by normalized text', async () => {
const lib = new SlideLibrary(filePath);
await lib.load();
await lib.upsert({ language: 'French', sourceText: 'Praise the Lord', text: 'Louez le Seigneur' });
const entry = lib.lookup('French', ' Praise the Lord ');
expect(entry?.text).toBe('Louez le Seigneur');
expect(entry?.status).toBe('reviewed');
expect(entry?.provenance).toBe('human');
expect(entry?.reviewedAt).toBeTypeOf('number');
});
it('persists across reloads from a fresh instance', async () => {
const lib = new SlideLibrary(filePath);
await lib.load();
await lib.upsert({
language: 'French',
sourceText: 'Psalm 23:1',
text: 'Le Seigneur est mon berger',
provenance: 'bible',
});
const reloaded = new SlideLibrary(filePath);
await reloaded.load();
const entry = reloaded.lookup('French', 'Psalm 23:1');
expect(entry?.text).toBe('Le Seigneur est mon berger');
expect(entry?.provenance).toBe('bible');
});
it('replaces an existing entry on re-upsert', async () => {
const lib = new SlideLibrary(filePath);
await lib.load();
await lib.upsert({ language: 'French', sourceText: 'Amen', text: 'first' });
await lib.upsert({ language: 'French', sourceText: 'Amen', text: 'second' });
expect(lib.lookup('French', 'Amen')?.text).toBe('second');
expect(lib.list()).toHaveLength(1);
});
it('keeps separate entries per language', async () => {
const lib = new SlideLibrary(filePath);
await lib.load();
await lib.upsert({ language: 'French', sourceText: 'Amen', text: 'Amen (fr)' });
await lib.upsert({ language: 'Spanish', sourceText: 'Amen', text: 'Amén (es)' });
expect(lib.lookup('French', 'Amen')?.text).toBe('Amen (fr)');
expect(lib.lookup('Spanish', 'Amen')?.text).toBe('Amén (es)');
expect(lib.list()).toHaveLength(2);
});
});