test: unit and end-to-end suites
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27fafa0bcd
commit
9b00e21c44
49 files changed
+6694
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// Where daily notes go.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { cleanFolder, autoFolder, dailyId, DEFAULT_FOLDER } from '../src/lib/daily.js';
|
||||
|
||||
const page = (id, exists = true) => ({ id, title: id.slice(id.lastIndexOf('/') + 1), exists });
|
||||
|
||||
test('a typed folder path is tidied', () => {
|
||||
assert.equal(cleanFolder('Private/Daily'), 'Private/Daily');
|
||||
assert.equal(cleanFolder(' /Private//Daily/ '), 'Private/Daily');
|
||||
assert.equal(cleanFolder('Private\\Daily'), 'Private/Daily');
|
||||
assert.equal(cleanFolder('../../etc'), 'etc', 'no way out of the notes folder');
|
||||
assert.equal(cleanFolder('a/./b'), 'a/b');
|
||||
assert.equal(cleanFolder('We: "ird"?'), 'We- -ird--');
|
||||
assert.equal(cleanFolder(' '), '');
|
||||
assert.equal(cleanFolder(null), '');
|
||||
});
|
||||
|
||||
test('with nothing chosen, an existing Daily is found where it is', () => {
|
||||
assert.equal(autoFolder([]), DEFAULT_FOLDER);
|
||||
assert.equal(autoFolder([page('Daily'), page('Private/Daily')]), 'Daily', 'the top-level one wins');
|
||||
assert.equal(autoFolder([page('Private'), page('Private/Daily'), page('Private/Daily/2026-01-01')]), 'Private/Daily');
|
||||
assert.equal(autoFolder([page('A/Daily'), page('B/Daily')]), 'Daily', 'two candidates: not guessing');
|
||||
assert.equal(autoFolder([page('Private/Daily', false)]), 'Daily', 'a folder with no page of its own does not count');
|
||||
assert.equal(autoFolder([page('Maps/Daily.canvas')]), 'Daily');
|
||||
});
|
||||
|
||||
test('the id of a day\'s note', () => {
|
||||
const d = new Date(2026, 0, 5);
|
||||
assert.equal(dailyId('Private/Daily', d), 'Private/Daily/2026-01-05');
|
||||
assert.equal(dailyId('', d), 'Daily/2026-01-05');
|
||||
assert.equal(dailyId('Daily', new Date(2026, 11, 31)), 'Daily/2026-12-31');
|
||||
});
|
||||
Reference in new issue
Block a user