test(editor): cover saved preview and destination repairs

This commit is contained in:
Neil
2026-09-18 16:55:23 -07:00
parent 0909ef3966
commit 3bb3e4331d
2 changed files with 22 additions and 2 deletions
@@ -95,6 +95,7 @@ function openFile(
function renderEditPath({
content,
savedContent = '# Saved',
language = 'markdown',
viewMode = 'rich',
mode = 'edit',
@@ -102,6 +103,7 @@ function renderEditPath({
onOpenMarkdownPreview
}: {
content: string
savedContent?: string
language?: 'markdown' | 'typescript'
viewMode?: 'source' | 'rich' | 'preview'
mode?: 'edit' | 'markdown-preview'
@@ -110,7 +112,7 @@ function renderEditPath({
}) {
const activeFile = openFile(language, mode)
const fileContents = {
[activeFile.id]: { content: '# Saved', isBinary: false }
[activeFile.id]: { content: savedContent, isBinary: false }
}
const editorDrafts = { [activeFile.id]: content }
const model = getEditorPanelRenderModel({
@@ -310,7 +312,10 @@ describe('inline Markdown render classification', () => {
})
it('offers the Preview toggle once rich mode falls back to source for this content', () => {
const fallback = renderEditPath({ content: '[reference]: https://example.com' })
const fallback = renderEditPath({
content: '[reference]: https://example.com',
savedContent: '[reference]: https://example.com'
})
expect(fallback.model.availableEditorToggleModes).toEqual([
'source',
'rich',
@@ -326,6 +331,7 @@ describe('inline Markdown render classification', () => {
const content = '[reference]: https://example.com'
const result = renderEditPath({
content,
savedContent: content,
viewMode: 'source',
markdownRichModeFaultedContent: { [openFile().id]: content }
})
@@ -841,3 +841,17 @@ it('preserves code spacing inside a table across repeated saves', () => {
expect(once).toContain('`a b`')
expect(roundTripMarkdown(once)).toBe(once)
})
it('retains an unchanged raw destination while repairing nearby attributes', () => {
const source = '[a](b\\)c) and ![x](image.png "say \\"hi\\"")'
expect(roundTripMarkdown(source)).toBe(source)
})
it('encodes spaces in edited destinations', () => {
expect(markdownAfterDestinationEdit('[a](old)', 'link', 'docs/My File.md')).toBe(
'[a](docs/My%20File.md)'
)
expect(markdownAfterDestinationEdit('![a](old.png)', 'image', 'My Image.png')).toBe(
'![a](My%20Image.png)'
)
})