Some checks are pending
CI / validate (push) Waiting to run
- lib-reviews.test.ts: 5 Tests — subIndex-Count, userId/cardId, leere Input-Liste, Initialzustand (reps=0, lapses=0), due ist Date - lib-url-fetch.test.ts: 6 Tests — mana-search Pfad, Fallback auf direktes Fetch, HTML-Stripping, Network-Fehler, leerer Content, Truncation auf 8000 Zeichen Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { makeInitialReviewRows } from '../src/lib/reviews.ts';
|
|
|
|
describe('makeInitialReviewRows', () => {
|
|
it('creates one row per subIndex', () => {
|
|
const now = new Date('2025-01-01T00:00:00Z');
|
|
const rows = makeInitialReviewRows({
|
|
userId: 'u-1',
|
|
cardId: 'c-1',
|
|
subIndices: [0, 1, 2],
|
|
now,
|
|
});
|
|
expect(rows).toHaveLength(3);
|
|
expect(rows[0].subIndex).toBe(0);
|
|
expect(rows[1].subIndex).toBe(1);
|
|
expect(rows[2].subIndex).toBe(2);
|
|
});
|
|
|
|
it('sets correct userId and cardId on each row', () => {
|
|
const now = new Date();
|
|
const rows = makeInitialReviewRows({
|
|
userId: 'u-test',
|
|
cardId: 'c-test',
|
|
subIndices: [0],
|
|
now,
|
|
});
|
|
expect(rows[0].userId).toBe('u-test');
|
|
expect(rows[0].cardId).toBe('c-test');
|
|
});
|
|
|
|
it('returns empty array for empty subIndices', () => {
|
|
const rows = makeInitialReviewRows({
|
|
userId: 'u-1',
|
|
cardId: 'c-1',
|
|
subIndices: [],
|
|
now: new Date(),
|
|
});
|
|
expect(rows).toHaveLength(0);
|
|
});
|
|
|
|
it('initial state has reps=0 and lapses=0', () => {
|
|
const rows = makeInitialReviewRows({
|
|
userId: 'u-1',
|
|
cardId: 'c-1',
|
|
subIndices: [0],
|
|
now: new Date(),
|
|
});
|
|
expect(rows[0].reps).toBe(0);
|
|
expect(rows[0].lapses).toBe(0);
|
|
});
|
|
|
|
it('due date is a Date instance', () => {
|
|
const now = new Date();
|
|
const rows = makeInitialReviewRows({
|
|
userId: 'u-1',
|
|
cardId: 'c-1',
|
|
subIndices: [0],
|
|
now,
|
|
});
|
|
expect(rows[0].due).toBeInstanceOf(Date);
|
|
});
|
|
});
|