diff --git a/src/renderer/src/components/editor/editor-panel-render-model.test.ts b/src/renderer/src/components/editor/editor-panel-render-model.test.ts index 018f016b87b..e8c1830a60d 100644 --- a/src/renderer/src/components/editor/editor-panel-render-model.test.ts +++ b/src/renderer/src/components/editor/editor-panel-render-model.test.ts @@ -1,10 +1,14 @@ -import { describe, expect, it } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' +import * as htmlValidation from './markdown-rich-html-validation' +import * as roundTrip from './markdown-round-trip' import type { OpenFile } from '@/store/slices/editor' import { RICH_MARKDOWN_MAX_SIZE_BYTES } from '../../../../shared/constants' import type { GitStatusEntry } from '../../../../shared/git-status-types' import type { FileContent } from './editor-panel-content-types' import { getEditorPanelRenderModel } from './editor-panel-render-model' +afterEach(() => vi.restoreAllMocks()) + function markdownFile(overrides: Partial = {}): OpenFile { return { id: '/repo/README.md', @@ -63,6 +67,23 @@ function htmlFile(overrides: Partial = {}): OpenFile { } describe('getEditorPanelRenderModel rich-mode fallback toggle', () => { + it('skips HTML validation round trips for source mode', () => { + const htmlValidationSpy = vi.spyOn(htmlValidation, 'getRichMarkdownHtmlValidationOutput') + const roundTripSpy = vi.spyOn(roundTrip, 'getRichMarkdownRoundTripOutput') + + const model = renderModel({ + markdownViewMode: { '/repo/README.md': 'source' }, + fileContents: { + '/repo/README.md': textContent({ content: 'source-mode-only\n' }) + } + }) + + expect(model.mdViewMode).toBe('source') + expect(model.inlineMarkdownRenderState?.renderMode).toBe('source') + expect(htmlValidationSpy).not.toHaveBeenCalled() + expect(roundTripSpy).not.toHaveBeenCalled() + }) + it('offers Preview once rich mode falls back for this content', () => { const model = renderModel({ fileContents: {