import { createRef } from 'react'
import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { EditorContentLayout } from './EditorContentLayout'
vi.mock('../BreadcrumbBar', () => ({
BreadcrumbBar: () =>
,
}))
vi.mock('../TitleField', () => ({
TitleField: () => ,
}))
vi.mock('../NoteIcon', () => ({
NoteIcon: ({ icon }: { icon: string | null }) => (
icon
?
:
),
}))
vi.mock('../ArchivedNoteBanner', () => ({
ArchivedNoteBanner: () => ,
}))
vi.mock('../ConflictNoteBanner', () => ({
ConflictNoteBanner: () => ,
}))
vi.mock('../RawEditorView', () => ({
RawEditorView: () => ,
}))
vi.mock('../SingleEditorView', () => ({
SingleEditorView: () => ,
}))
vi.mock('../DiffView', () => ({
DiffView: () => ,
}))
function createModel(overrides: Record = {}) {
return {
activeTab: {
entry: {
path: '/vault/project/demo.md',
filename: 'demo.md',
title: 'Demo Note',
},
content: 'Body',
},
isLoadingNewTab: false,
entries: [],
editor: {},
diffMode: false,
diffContent: null,
diffLoading: false,
onToggleDiff: vi.fn(),
effectiveRawMode: false,
onToggleRaw: vi.fn(),
onRawContentChange: vi.fn(),
onSave: vi.fn(),
showEditor: true,
isArchived: false,
onUnarchiveNote: undefined,
path: '/vault/project/demo.md',
isConflicted: false,
onKeepMine: vi.fn(),
onKeepTheirs: vi.fn(),
breadcrumbBarRef: createRef(),
wordCount: 12,
titleSectionRef: createRef(),
showTitleSection: true,
hasDisplayIcon: false,
entryIcon: null,
vaultPath: '/vault',
onTitleChange: vi.fn(),
cssVars: {},
onNavigateWikilink: vi.fn(),
onEditorChange: vi.fn(),
isDeletedPreview: false,
rawLatestContentRef: { current: null },
forceRawMode: false,
showAIChat: false,
onToggleAIChat: vi.fn(),
inspectorCollapsed: true,
onToggleInspector: vi.fn(),
showDiffToggle: false,
onToggleFavorite: vi.fn(),
onToggleOrganized: vi.fn(),
onDeleteNote: vi.fn(),
onArchiveNote: vi.fn(),
...overrides,
} as never
}
describe('EditorContentLayout', () => {
it('does not render a standalone add-icon row when the note has no icon', () => {
const { container } = render()
expect(container.querySelector('.title-section__add-icon')).toBeNull()
expect(container.querySelector('.title-section__inline-add-icon')).not.toBeNull()
expect(screen.getByTestId('note-icon-add')).toBeInTheDocument()
})
it('keeps the existing icon and title inside the same title row', () => {
const { container } = render(
,
)
const titleRow = container.querySelector('.title-section__row')
expect(titleRow?.querySelector('[data-testid="note-icon-display"]')).not.toBeNull()
expect(titleRow?.querySelector('[data-testid="title-field-input"]')).not.toBeNull()
})
})