mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-22 11:04:56 +01:00
- Show search results in the right notebook or All Notes list - Scroll to the selected note and highlight matching text - Keep unsaved edits safe and ignore old or cancelled searches - Show save errors with a Retry button - Run graph and vault statistics scans in the background - Fix folder checks when counting vault files - Keep desktop window-close code out of mobile builds
75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
const { restoreTitleHeading, stripTitleHeading } = await import(
|
|
new URL('../src/lib/editor/titleVisibility.ts', import.meta.url)
|
|
);
|
|
|
|
test('keeps a hidden title through source to rich to source and save', () => {
|
|
const persisted = '# Note title\n\n## Something else\n\nBody\n';
|
|
const body = '## Something else\n\nBody\n';
|
|
|
|
const initialSource = stripTitleHeading(persisted, 'Note title', true);
|
|
const rich = stripTitleHeading(
|
|
restoreTitleHeading(initialSource.markdown, initialSource.hiddenTitle),
|
|
'Note title',
|
|
true
|
|
);
|
|
const toggledSource = stripTitleHeading(
|
|
restoreTitleHeading(rich.markdown, rich.hiddenTitle),
|
|
'Note title',
|
|
true
|
|
);
|
|
|
|
assert.equal(rich.markdown, body);
|
|
assert.equal(toggledSource.markdown, body);
|
|
assert.equal(restoreTitleHeading(toggledSource.markdown, toggledSource.hiddenTitle), persisted);
|
|
});
|
|
|
|
test('keeps a title-only note visually empty and saves one title heading', () => {
|
|
const initialSource = stripTitleHeading('# Note title\n', 'Note title', true);
|
|
const rich = stripTitleHeading(
|
|
restoreTitleHeading(initialSource.markdown, initialSource.hiddenTitle),
|
|
'Note title',
|
|
true
|
|
);
|
|
const saved = restoreTitleHeading(rich.markdown, rich.hiddenTitle);
|
|
|
|
assert.equal(initialSource.markdown, '');
|
|
assert.equal(rich.markdown, '');
|
|
assert.equal((saved.match(/^# Note title$/gm) ?? []).length, 1);
|
|
});
|
|
|
|
test('replaces hidden title state when an unrelated note loads', () => {
|
|
const markdown = '## Something else\n\nOther body\n';
|
|
|
|
assert.deepEqual(stripTitleHeading(markdown, 'Another note', true), {
|
|
markdown,
|
|
hiddenTitle: null
|
|
});
|
|
});
|
|
|
|
test('leaves the title visible when title hiding is disabled', () => {
|
|
const persisted = '# Note title\n\n## Something else\n';
|
|
|
|
assert.deepEqual(stripTitleHeading(persisted, 'Note title', false), {
|
|
markdown: persisted,
|
|
hiddenTitle: null
|
|
});
|
|
});
|
|
|
|
test('reports the exact contiguous range removed without changing leading blank behavior', () => {
|
|
for (const [markdown, expected, removedRange] of [
|
|
['# Note title\n\nBody', 'Body', { from: 0, to: 14 }],
|
|
['\n# Note title\nBody', '\nBody', { from: 1, to: 14 }],
|
|
['\n\n# Note title', '\n', { from: 1, to: 14 }],
|
|
['\n\n# Note title\n', '\n', { from: 1, to: 15 }],
|
|
['# Note title\r\n\r\nBody', 'Body', { from: 0, to: 16 }],
|
|
]) {
|
|
const stripped = stripTitleHeading(markdown, 'Note title', true);
|
|
assert.equal(stripped.markdown, expected);
|
|
assert.deepEqual(stripped.removedRange, removedRange);
|
|
assert.equal(markdown.slice(0, removedRange.from) + markdown.slice(removedRange.to), expected);
|
|
}
|
|
});
|