test: add tests for usePinnedProperties hook and frontmatter sync
- 10 tests for usePinnedProperties: resolution, defaults, pin/unpin, isPinned - 3 tests for frontmatterToEntryPatch: _pinned_properties update/delete/ignore Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
src/hooks/frontmatterOps.test.ts
Normal file
25
src/hooks/frontmatterOps.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { frontmatterToEntryPatch } from './frontmatterOps'
|
||||
|
||||
describe('frontmatterToEntryPatch — _pinned_properties', () => {
|
||||
it('patches pinnedProperties on update', () => {
|
||||
const result = frontmatterToEntryPatch('update', '_pinned_properties', ['Status:circle-dot', 'Date'])
|
||||
expect(result.patch.pinnedProperties).toEqual([
|
||||
{ key: 'Status', icon: 'circle-dot' },
|
||||
{ key: 'Date', icon: null },
|
||||
])
|
||||
expect(result.relationshipPatch).toBeNull()
|
||||
})
|
||||
|
||||
it('clears pinnedProperties on delete', () => {
|
||||
const result = frontmatterToEntryPatch('delete', '_pinned_properties')
|
||||
expect(result.patch.pinnedProperties).toEqual([])
|
||||
expect(result.relationshipPatch).toBeNull()
|
||||
})
|
||||
|
||||
it('ignores non-array _pinned_properties values', () => {
|
||||
const result = frontmatterToEntryPatch('update', '_pinned_properties', 'not-an-array')
|
||||
// Falls through to default handling (no patch for unknown keys)
|
||||
expect(result.patch.pinnedProperties).toBeUndefined()
|
||||
})
|
||||
})
|
||||
78
src/hooks/usePinnedProperties.test.ts
Normal file
78
src/hooks/usePinnedProperties.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
resolvePinIcon,
|
||||
serialisePinnedConfig,
|
||||
parsePinnedConfig,
|
||||
} from './usePinnedProperties'
|
||||
import type { PinnedPropertyConfig } from '../types'
|
||||
|
||||
describe('resolvePinIcon', () => {
|
||||
it('returns explicit icon when provided', () => {
|
||||
expect(resolvePinIcon('status', 'star')).toBe('star')
|
||||
})
|
||||
|
||||
it('returns default icon for known keys', () => {
|
||||
expect(resolvePinIcon('status', null)).toBe('circle-dot')
|
||||
expect(resolvePinIcon('Status', null)).toBe('circle-dot')
|
||||
expect(resolvePinIcon('date', null)).toBe('calendar')
|
||||
expect(resolvePinIcon('Belongs to', null)).toBe('arrow-up-right')
|
||||
expect(resolvePinIcon('Related to', null)).toBe('arrows-left-right')
|
||||
expect(resolvePinIcon('Due date', null)).toBe('calendar')
|
||||
})
|
||||
|
||||
it('returns fallback icon for unknown keys', () => {
|
||||
expect(resolvePinIcon('Priority', null)).toBe('arrow-up-right')
|
||||
})
|
||||
})
|
||||
|
||||
describe('serialisePinnedConfig', () => {
|
||||
it('serialises configs with icons', () => {
|
||||
const configs: PinnedPropertyConfig[] = [
|
||||
{ key: 'Status', icon: 'circle-dot' },
|
||||
{ key: 'date', icon: 'calendar' },
|
||||
]
|
||||
expect(serialisePinnedConfig(configs)).toEqual(['Status:circle-dot', 'date:calendar'])
|
||||
})
|
||||
|
||||
it('serialises configs without icons', () => {
|
||||
const configs: PinnedPropertyConfig[] = [
|
||||
{ key: 'Status', icon: null },
|
||||
]
|
||||
expect(serialisePinnedConfig(configs)).toEqual(['Status'])
|
||||
})
|
||||
|
||||
it('handles empty array', () => {
|
||||
expect(serialisePinnedConfig([])).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('parsePinnedConfig', () => {
|
||||
it('parses key:icon format', () => {
|
||||
expect(parsePinnedConfig(['Status:circle-dot'])).toEqual([
|
||||
{ key: 'Status', icon: 'circle-dot' },
|
||||
])
|
||||
})
|
||||
|
||||
it('parses key-only format', () => {
|
||||
expect(parsePinnedConfig(['Status'])).toEqual([
|
||||
{ key: 'Status', icon: null },
|
||||
])
|
||||
})
|
||||
|
||||
it('handles mixed formats', () => {
|
||||
const result = parsePinnedConfig(['Status:circle-dot', 'Priority', 'date:calendar'])
|
||||
expect(result).toEqual([
|
||||
{ key: 'Status', icon: 'circle-dot' },
|
||||
{ key: 'Priority', icon: null },
|
||||
{ key: 'date', icon: 'calendar' },
|
||||
])
|
||||
})
|
||||
|
||||
it('round-trips with serialise', () => {
|
||||
const configs: PinnedPropertyConfig[] = [
|
||||
{ key: 'Status', icon: 'circle-dot' },
|
||||
{ key: 'Belongs to', icon: 'arrow-up-right' },
|
||||
]
|
||||
expect(parsePinnedConfig(serialisePinnedConfig(configs))).toEqual(configs)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user