Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion scripts/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Personalizer, collectThemes, normalizeTheme } from '../src/personalize.js';
import { SearchIndex, tokenize, snippet } from '../src/search.js';
import { asMovements, monthByNumber, movementOf, mirrorOf, currentMonth, neighbors } from '../src/journey.js';
import { asMovements, monthByNumber, monthsOfMovement, movementOf, mirrorOf, currentMonth, neighbors } from '../src/journey.js';

const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const { articles } = JSON.parse(
Expand Down Expand Up @@ -57,6 +57,14 @@ check('collectThemes returns a sorted, de-duplicated set', () => {
assert.deepEqual(themes, [...new Set(themes)].sort());
});

check('collectThemes deduplicates themes that differ only by case', () => {
const themes = collectThemes([
{ themes: ['Vedanta', 'Sadhana'] },
{ themes: ['vedanta'] }, // normalises to the same key as 'Vedanta'
]);
assert.deepEqual(themes, ['sadhana', 'vedanta']); // 2 items, not 3
});

console.log('search.js');

check('finds a distinctive term in the right article', () => {
Expand Down Expand Up @@ -111,6 +119,12 @@ check('neighbors are the adjacent months, with no wraparound', () => {
assert.equal(neighbors(arc, 12).next, null);
});

check('monthsOfMovement returns months in calendar order for a movement', () => {
const months = monthsOfMovement(arc, 'ground');
assert.equal(months.length, 5); // January through May
assert.deepEqual(months.map((m) => m.number), [1, 2, 3, 4, 5]);
});

console.log('personalize.js (more)');

check('reading an article adds the seen penalty and reason', () => {
Expand Down Expand Up @@ -145,6 +159,11 @@ check('snippet falls back to the start of the text when nothing matches', () =>
assert.ok(s.startsWith('Gratitude'));
});

check('snippet with no terms falls back to the start of the text', () => {
const s = snippet({ summary: 'Aspiration is the flame lit on the ground of gratitude.' });
assert.ok(s.startsWith('Aspiration'));
});

check('search matches an author name', () => {
const idx = new SearchIndex().build([
{ title: 'On stillness', themes: ['Silence'], author: 'Nirodbaran', summary: 'x', body: 'y' },
Expand Down
Loading