// @vitest-environment jsdom
import {it,expect,vi,afterEach} from 'vitest'
vi.mock('@/utils/markdown',()=>({renderMarkdown:vi.fn().mockResolvedValue('
Heading
Tip
Body
python
')}))
vi.mock('./apiClient',()=>({apiClient:{post:vi.fn().mockResolvedValue({images:[],plots:[]})}}))
vi.mock('./mermaidService',()=>({mermaidThemeVariables:()=>({primaryColor:'#fff'})}))
vi.mock('@/stores/theme',()=>({useThemeStore:()=>({isDark:false})}))
vi.mock('@/stores/markdownPreferences',()=>({useMarkdownPreferencesStore:()=>({normalized:{wrapCode:true,lineNumbers:true,indent:4}})}))
vi.mock('@/stores/headingAppearance',()=>({useHeadingAppearanceStore:()=>({cssVariables:{'--heading-1-size':'37px'},preferences:{custom:true}})}))
vi.mock('@/components/common/MarkdownContent.vue',()=>({default:{}}))
vi.mock('@/features/editor/VisualMarkdownEditor.vue',()=>({default:{__scopeId:'data-v-editor'}}))
import {preparePdfSnapshot,preferWoff2FontSource} from './pdfSnapshotService'
import {apiClient} from './apiClient'
import {renderMarkdown} from '@/utils/markdown'
afterEach(()=>vi.clearAllMocks())
it('keeps only the WOFF2 source when preparing embedded print fonts',()=>{
const css='@font-face { font-family: "Demo"; src: url("data:font/woff2;base64,d09GMg==") format("woff2"), url("demo.woff") format("woff"), url("demo.ttf") format("truetype"); font-style: normal; }'
const compact=preferWoff2FontSource(css)
expect(compact).toContain('url("data:font/woff2;base64,d09GMg==") format("woff2")')
expect(compact).not.toContain('demo.woff"')
expect(compact).not.toContain('demo.ttf')
})
it('preserves actual theme CSS, pseudo elements, root attributes and heading preferences',async()=>{
const style=document.createElement('style');style.textContent='[data-theme="paper"] .ProseMirror::before { content:"tape"; transform:rotate(-3deg) }';document.head.append(style)
document.documentElement.dataset.theme='paper'
try {
const html=await preparePdfSnapshot('# Heading','',{theme_id:'paper',include_title:true,page_size:'A4'})
expect(html).toContain('transform: rotate(-3deg)')
expect(html).toContain('data-theme="paper"')
expect(html).toContain('data-v-editor')
expect(html).toContain('data-heading-style="custom"')
expect(html).toContain('--heading-1-size:37px')
expect(html).toContain('<Title>')
expect(html).toContain('')
expect(html).not.toContain('