2026-04-08 20:40:14 +02:00
|
|
|
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', () => ({
|
2026-04-27 10:10:58 +02:00
|
|
|
BreadcrumbBar: ({ noteLayout }: { noteLayout?: string }) => <div data-testid="breadcrumb-bar" data-note-layout={noteLayout} />,
|
2026-04-08 20:40:14 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('../ArchivedNoteBanner', () => ({
|
|
|
|
|
ArchivedNoteBanner: () => <div data-testid="archived-banner" />,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('../ConflictNoteBanner', () => ({
|
|
|
|
|
ConflictNoteBanner: () => <div data-testid="conflict-banner" />,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('../RawEditorView', () => ({
|
|
|
|
|
RawEditorView: () => <div data-testid="raw-editor-view" />,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('../SingleEditorView', () => ({
|
|
|
|
|
SingleEditorView: () => <div data-testid="single-editor-view" />,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('../DiffView', () => ({
|
|
|
|
|
DiffView: () => <div data-testid="diff-view" />,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
function createModel(overrides: Record<string, unknown> = {}) {
|
|
|
|
|
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<HTMLDivElement>(),
|
|
|
|
|
wordCount: 12,
|
|
|
|
|
vaultPath: '/vault',
|
|
|
|
|
cssVars: {},
|
|
|
|
|
onNavigateWikilink: vi.fn(),
|
|
|
|
|
onEditorChange: vi.fn(),
|
|
|
|
|
isDeletedPreview: false,
|
|
|
|
|
rawLatestContentRef: { current: null },
|
2026-04-27 10:10:58 +02:00
|
|
|
noteLayout: 'centered',
|
|
|
|
|
onToggleNoteLayout: vi.fn(),
|
2026-04-08 20:40:14 +02:00
|
|
|
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', () => {
|
2026-04-11 23:51:58 +02:00
|
|
|
it('never renders the legacy title section', () => {
|
2026-04-08 20:40:14 +02:00
|
|
|
const { container } = render(<EditorContentLayout {...createModel()} />)
|
|
|
|
|
|
2026-04-11 23:51:58 +02:00
|
|
|
expect(container.querySelector('.title-section')).toBeNull()
|
|
|
|
|
expect(screen.queryByTestId('title-field-input')).not.toBeInTheDocument()
|
|
|
|
|
expect(screen.getByTestId('single-editor-view')).toBeInTheDocument()
|
2026-04-08 20:40:14 +02:00
|
|
|
})
|
2026-04-09 12:20:03 +02:00
|
|
|
|
|
|
|
|
it('shows the loading skeleton instead of stale editor chrome while switching tabs', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<EditorContentLayout
|
|
|
|
|
{...createModel({
|
|
|
|
|
activeTab: null,
|
|
|
|
|
isLoadingNewTab: true,
|
|
|
|
|
})}
|
|
|
|
|
/>,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(container.querySelector('.animate-pulse')).not.toBeNull()
|
|
|
|
|
expect(screen.queryByTestId('title-field-input')).not.toBeInTheDocument()
|
|
|
|
|
})
|
2026-04-26 04:41:18 +02:00
|
|
|
|
2026-04-27 10:10:58 +02:00
|
|
|
it('marks the editor content root and breadcrumb with the note layout preference', () => {
|
|
|
|
|
const { container } = render(<EditorContentLayout {...createModel({ noteLayout: 'left' })} />)
|
2026-04-26 04:41:18 +02:00
|
|
|
|
2026-04-27 10:10:58 +02:00
|
|
|
expect(container.firstElementChild).toHaveClass('editor-content-layout--left')
|
|
|
|
|
expect(screen.getByTestId('breadcrumb-bar')).toHaveAttribute('data-note-layout', 'left')
|
2026-04-26 04:41:18 +02:00
|
|
|
})
|
2026-04-08 20:40:14 +02:00
|
|
|
})
|