fix: sync sidebar types with live vault state

This commit is contained in:
lucaronin
2026-04-21 10:45:39 +02:00
parent fb1265e088
commit 4cd5baeb55
5 changed files with 121 additions and 20 deletions

View File

@@ -113,6 +113,16 @@ describe('buildDynamicSections', () => {
const entries: VaultEntry[] = [
{ ...baseEntry, title: 'Daily Log', isA: 'Journal' },
]
const sections = buildDynamicSections(entries, {})
expect(sections.map((section) => section.type)).not.toContain('Journal')
})
it('includes Journal when a real Journal type definition exists', () => {
const entries: VaultEntry[] = [
{ ...baseEntry, title: 'Daily Log', isA: 'journal' },
]
const typeEntryMap: Record<string, VaultEntry> = {
Journal: { ...baseEntry, title: 'Journal', isA: 'Type' },
journal: { ...baseEntry, title: 'Journal', isA: 'Type' },
@@ -120,7 +130,7 @@ describe('buildDynamicSections', () => {
const sections = buildDynamicSections(entries, typeEntryMap)
expect(sections.map((section) => section.type)).not.toContain('Journal')
expect(sections.filter((section) => section.type === 'Journal')).toHaveLength(1)
})
})

View File

@@ -517,11 +517,17 @@ describe('Sidebar', () => {
})
describe('type visibility via visible property', () => {
const makeTypeEntry = (title: string, visible: boolean | null): VaultEntry => ({
path: `/vault/${title.toLowerCase()}.md`,
filename: `${title.toLowerCase()}.md`,
title,
isA: 'Type',
const makeSidebarEntry = (overrides: {
path: string
filename: string
title: string
isA: string
visible?: boolean | null
}): VaultEntry => ({
path: overrides.path,
filename: overrides.filename,
title: overrides.title,
isA: overrides.isA,
aliases: [],
belongsTo: [],
relatedTo: [],
@@ -542,11 +548,19 @@ describe('Sidebar', () => {
template: null,
sort: null,
view: null,
visible,
visible: overrides.visible ?? null,
outgoingLinks: [],
properties: {},
})
const makeTypeEntry = (title: string, visible: boolean | null): VaultEntry => makeSidebarEntry({
path: `/vault/${title.toLowerCase()}.md`,
filename: `${title.toLowerCase()}.md`,
title,
isA: 'Type',
visible,
})
it('hides a section when its Type entry has visible: false', () => {
const entries: VaultEntry[] = [
...mockEntries,
@@ -620,6 +634,34 @@ describe('Sidebar', () => {
expect(screen.getByLabelText('Toggle Topics')).toBeInTheDocument()
})
it('updates the sidebar type picker when Journal becomes a real type while the app stays open', () => {
const journalEntries: VaultEntry[] = [
...mockEntries,
makeSidebarEntry({
path: '/vault/april-21.md',
filename: 'april-21.md',
title: 'April 21',
isA: 'journal',
}),
]
const { rerender } = render(<Sidebar entries={journalEntries} selection={defaultSelection} onSelect={() => {}} />)
fireEvent.click(screen.getByTitle('Customize sections'))
expect(screen.queryByLabelText('Toggle Journals')).not.toBeInTheDocument()
rerender(
<Sidebar
entries={[...journalEntries, makeTypeEntry('Journal', null)]}
selection={defaultSelection}
onSelect={() => {}}
/>,
)
expect(screen.getByLabelText('Toggle Journals')).toBeInTheDocument()
rerender(<Sidebar entries={journalEntries} selection={defaultSelection} onSelect={() => {}} />)
expect(screen.queryByLabelText('Toggle Journals')).not.toBeInTheDocument()
})
it('preserves custom section colors in the customize popover', () => {
const entries: VaultEntry[] = [
...mockEntries,