diff --git a/src/hooks/frontmatterOps.test.ts b/src/hooks/frontmatterOps.test.ts new file mode 100644 index 00000000..117cfefa --- /dev/null +++ b/src/hooks/frontmatterOps.test.ts @@ -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() + }) +}) diff --git a/src/hooks/usePinnedProperties.test.ts b/src/hooks/usePinnedProperties.test.ts new file mode 100644 index 00000000..a9a36fe3 --- /dev/null +++ b/src/hooks/usePinnedProperties.test.ts @@ -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) + }) +})