diff --git a/src/hooks/useNoteActions.test.ts b/src/hooks/useNoteActions.test.ts index 5a68fcf8..dcee1309 100644 --- a/src/hooks/useNoteActions.test.ts +++ b/src/hooks/useNoteActions.test.ts @@ -468,6 +468,24 @@ describe('contentToEntryPatch', () => { const content = '---\ntype: Note\ncustom: value\n---\n' expect(contentToEntryPatch(content)).toEqual({ isA: 'Note' }) }) + + it('preserves _favorite_index as a number (not null)', () => { + const content = '---\n_favorite: true\n_favorite_index: 2\n---\nBody' + const patch = contentToEntryPatch(content) + expect(patch.favorite).toBe(true) + expect(patch.favoriteIndex).toBe(2) + }) + + it('preserves _favorite_index: 0 as number 0', () => { + const content = '---\n_favorite: true\n_favorite_index: 0\n---\nBody' + const patch = contentToEntryPatch(content) + expect(patch.favoriteIndex).toBe(0) + }) + + it('preserves order as a number', () => { + const content = '---\ntype: Type\norder: 3\n---\n' + expect(contentToEntryPatch(content)).toEqual({ isA: 'Type', order: 3 }) + }) }) describe('todayDateString', () => { diff --git a/src/utils/frontmatter.test.ts b/src/utils/frontmatter.test.ts index 6d274945..99706349 100644 --- a/src/utils/frontmatter.test.ts +++ b/src/utils/frontmatter.test.ts @@ -2,6 +2,33 @@ import { describe, it, expect } from 'vitest' import { parseFrontmatter, detectFrontmatterState } from './frontmatter' describe('parseFrontmatter', () => { + describe('numeric values', () => { + it('parses integer values as numbers', () => { + const fm = parseFrontmatter('---\n_favorite_index: 2\n---\nBody') + expect(fm['_favorite_index']).toBe(2) + }) + + it('parses zero as number 0', () => { + const fm = parseFrontmatter('---\n_favorite_index: 0\n---\nBody') + expect(fm['_favorite_index']).toBe(0) + }) + + it('parses float values as numbers', () => { + const fm = parseFrontmatter('---\norder: 3.5\n---\nBody') + expect(fm['order']).toBe(3.5) + }) + + it('parses negative numbers', () => { + const fm = parseFrontmatter('---\norder: -1\n---\nBody') + expect(fm['order']).toBe(-1) + }) + + it('does not parse quoted numbers as numbers', () => { + const fm = parseFrontmatter('---\nversion: "42"\n---\nBody') + expect(fm['version']).toBe('42') + }) + }) + describe('boolean-like Yes/No values', () => { it('parses Archived: Yes as true', () => { const fm = parseFrontmatter('---\nArchived: Yes\n---\nBody') diff --git a/src/utils/frontmatter.ts b/src/utils/frontmatter.ts index 8a6e78fd..81fc7dc9 100644 --- a/src/utils/frontmatter.ts +++ b/src/utils/frontmatter.ts @@ -26,6 +26,7 @@ function parseScalar(value: string): FrontmatterValue { const lower = clean.toLowerCase() if (lower === 'true' || lower === 'yes') return true if (lower === 'false' || lower === 'no') return false + if (clean === value && /^-?\d+(\.\d+)?$/.test(clean)) return Number(clean) return clean }