Files
tolaria/src/components/TypeCustomizePopover.test.tsx

179 lines
5.5 KiB
TypeScript
Raw Normal View History

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { TypeCustomizePopover } from './TypeCustomizePopover'
import { resolveIcon, ICON_OPTIONS } from '../utils/iconRegistry'
describe('resolveIcon', () => {
it('returns the correct icon component for known name', () => {
const Icon = resolveIcon('wrench')
expect(Icon).toBeDefined()
// wrench should not be the default fallback (file-text)
const fileTextIcon = resolveIcon('file-text')
expect(Icon).not.toBe(fileTextIcon)
})
it('returns FileText fallback for null', () => {
const Icon = resolveIcon(null)
expect(Icon).toBeDefined()
})
it('returns FileText fallback for unknown name', () => {
const Icon = resolveIcon('nonexistent-icon')
expect(Icon).toBeDefined()
})
})
describe('ICON_OPTIONS', () => {
it('contains 200+ icons', () => {
expect(ICON_OPTIONS.length).toBeGreaterThanOrEqual(200)
})
it('has unique names', () => {
const names = ICON_OPTIONS.map((o) => o.name)
expect(new Set(names).size).toBe(names.length)
})
it('uses kebab-case names', () => {
for (const option of ICON_OPTIONS) {
expect(option.name).toMatch(/^[a-z][a-z0-9-]*$/)
}
})
})
describe('TypeCustomizePopover', () => {
const onChangeIcon = vi.fn()
const onChangeColor = vi.fn()
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
const onChangeTemplate = vi.fn()
const onClose = vi.fn()
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
const renderPopover = (overrides: Partial<Parameters<typeof TypeCustomizePopover>[0]> = {}) =>
render(
<TypeCustomizePopover
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
currentIcon={null}
currentColor={null}
currentTemplate={null}
onChangeIcon={onChangeIcon}
onChangeColor={onChangeColor}
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
onChangeTemplate={onChangeTemplate}
onClose={onClose}
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
{...overrides}
/>
)
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
beforeEach(() => {
vi.clearAllMocks()
})
it('renders color, icon, and template sections', () => {
renderPopover()
expect(screen.getByText('Color')).toBeInTheDocument()
expect(screen.getByText('Icon')).toBeInTheDocument()
expect(screen.getByText('Template')).toBeInTheDocument()
expect(screen.getByText('Done')).toBeInTheDocument()
})
it('renders search input', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
expect(screen.getByPlaceholderText('Search icons…')).toBeInTheDocument()
})
it('filters icons by search query', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
const searchInput = screen.getByPlaceholderText('Search icons…')
fireEvent.change(searchInput, { target: { value: 'book' } })
// Should show book-related icons
expect(screen.getByTitle('book')).toBeInTheDocument()
expect(screen.getByTitle('book-open')).toBeInTheDocument()
// Should not show unrelated icons
expect(screen.queryByTitle('wrench')).not.toBeInTheDocument()
})
it('shows empty state when no icons match search', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
const searchInput = screen.getByPlaceholderText('Search icons…')
fireEvent.change(searchInput, { target: { value: 'zzzznonexistent' } })
expect(screen.getByText('No icons found')).toBeInTheDocument()
})
it('calls onChangeColor when a color is clicked', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
const colorButtons = screen.getAllByTitle(/red|blue|green|purple|yellow|orange|teal|pink/i)
fireEvent.click(colorButtons[0])
expect(onChangeColor).toHaveBeenCalled()
})
it('calls onChangeIcon when an icon is clicked', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
fireEvent.click(screen.getByTitle('wrench'))
expect(onChangeIcon).toHaveBeenCalledWith('wrench')
})
it('calls onClose when Done is clicked', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
fireEvent.click(screen.getByText('Done'))
expect(onClose).toHaveBeenCalled()
})
it('renders all color options including teal and pink', () => {
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
renderPopover()
expect(screen.getByTitle('Teal')).toBeInTheDocument()
expect(screen.getByTitle('Pink')).toBeInTheDocument()
})
feat: note templates per type (💡 Note templates per tipo) (#170) * feat: add template field to type entries and template-aware note creation - Rust: add template field to Frontmatter, VaultEntry, SKIP_KEYS - Rust: support YAML block scalar (|) for multi-line strings in frontmatter - Rust: fix value continuation detection to handle block scalars properly - TypeScript: add template to VaultEntry, buildNewEntry, frontmatterToEntryPatch - Add DEFAULT_TEMPLATES for Project, Person, Responsibility, Experiment - resolveNewNote/buildNoteContent accept optional template parameter - handleCreateNote and handleCreateNoteImmediate look up type template - Tests for all new behavior (Rust + TypeScript) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire template UI through Sidebar and App, add TypeCustomizePopover template section - Add template textarea with debounced save to TypeCustomizePopover - Wire handleUpdateTypeTemplate through useEntryActions → Sidebar → App - Add useDebouncedCallback hook for 500ms template save debounce - Add tests for handleUpdateTypeTemplate and TypeCustomizePopover template UI - Create design/note-templates.pen placeholder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: useRef type arg + template field in bulk mock entries * style: rustfmt --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-02 08:37:06 +01:00
// --- Template tests ---
it('renders template textarea', () => {
renderPopover()
expect(screen.getByTestId('template-textarea')).toBeInTheDocument()
})
it('shows placeholder when template is empty', () => {
renderPopover()
expect(screen.getByPlaceholderText('Markdown template for new notes of this type…')).toBeInTheDocument()
})
it('displays current template value', () => {
renderPopover({ currentTemplate: '## Objective\n\n## Notes' })
const textarea = screen.getByTestId('template-textarea') as HTMLTextAreaElement
expect(textarea.value).toBe('## Objective\n\n## Notes')
})
it('updates template text on user input', () => {
renderPopover()
const textarea = screen.getByTestId('template-textarea')
fireEvent.change(textarea, { target: { value: '## New Template' } })
expect((textarea as HTMLTextAreaElement).value).toBe('## New Template')
})
it('calls onChangeTemplate after debounce', async () => {
vi.useFakeTimers()
renderPopover()
const textarea = screen.getByTestId('template-textarea')
fireEvent.change(textarea, { target: { value: '## Debounced' } })
// Should not be called immediately
expect(onChangeTemplate).not.toHaveBeenCalled()
// Fast-forward past debounce
vi.advanceTimersByTime(600)
expect(onChangeTemplate).toHaveBeenCalledWith('## Debounced')
vi.useRealTimers()
})
it('treats null template as empty string', () => {
renderPopover({ currentTemplate: null })
const textarea = screen.getByTestId('template-textarea') as HTMLTextAreaElement
expect(textarea.value).toBe('')
})
})