import { describe, expect, it } from 'vitest';
import { documentToMarkdown, htmlToMarkdown } from '../../seo/content-markdown.js';
describe('htmlToMarkdown', () => {
    it('converts headings, emphasis, links, and lists', () => {
        const md = htmlToMarkdown('<h2>Title</h2><p>Some <strong>bold</strong> and <a href="https://x.test">link</a>.</p><ul><li>one</li><li>two</li></ul>');
        expect(md).toContain('## Title');
        expect(md).toContain('**bold**');
        expect(md).toContain('[link](https://x.test)');
        expect(md).toMatch(/-\s+one/);
        expect(md).toMatch(/-\s+two/);
    });
    it('passes plain text through untouched', () => {
        expect(htmlToMarkdown('just text')).toBe('just text');
    });
    it('returns empty string for nullish input', () => {
        expect(htmlToMarkdown(null)).toBe('');
        expect(htmlToMarkdown(undefined)).toBe('');
    });
});
describe('documentToMarkdown', () => {
    it('renders title, takeaway intro, and a rich-text body field', () => {
        const md = documentToMarkdown({
            title: 'My Post',
            data: {
                keyTakeaway: 'A concise summary.',
                body: '<p>First paragraph.</p><p>Second paragraph.</p>',
            },
        });
        expect(md.startsWith('# My Post')).toBe(true);
        expect(md).toContain('A concise summary.');
        expect(md).toContain('First paragraph.');
        expect(md).toContain('Second paragraph.');
    });
    it('walks sections, converting rich-text slots and prose/heading keys', () => {
        const md = documentToMarkdown({
            title: 'Landing',
            data: {
                sections: [
                    {
                        sectionType: 'hero',
                        visible: true,
                        content: { heading: 'Welcome', subtitle: 'We build things' },
                    },
                    {
                        sectionType: 'article-body',
                        visible: true,
                        content: { body: '<p>Body <em>copy</em> here.</p>' },
                    },
                ],
            },
        });
        expect(md).toContain('## Welcome');
        expect(md).toContain('We build things');
        expect(md).toContain('Body _copy_ here.');
    });
    it('skips hidden sections', () => {
        const md = documentToMarkdown({
            title: 'X',
            data: {
                sections: [
                    { sectionType: 'hero', visible: false, content: { heading: 'Hidden' } },
                    { sectionType: 'hero', visible: true, content: { heading: 'Shown' } },
                ],
            },
        });
        expect(md).toContain('Shown');
        expect(md).not.toContain('Hidden');
    });
    it('renders FAQ-style item arrays (question/answer)', () => {
        const md = documentToMarkdown({
            title: 'Help',
            data: {
                sections: [
                    {
                        sectionType: 'faq',
                        visible: true,
                        content: {
                            items: [
                                { question: 'How?', answer: 'Like this.' },
                                { question: 'Why?', answer: 'Because.' },
                            ],
                        },
                    },
                ],
            },
        });
        expect(md).toContain('## How?');
        expect(md).toContain('Like this.');
        expect(md).toContain('## Why?');
        expect(md).toContain('Because.');
    });
    it('falls back to plainText when no structured content exists', () => {
        const md = documentToMarkdown({
            title: 'Bare',
            data: {},
            plainText: 'Just the extracted text.',
        });
        expect(md).toContain('# Bare');
        expect(md).toContain('Just the extracted text.');
    });
    it('does not leak non-content keys like urls or ids', () => {
        const md = documentToMarkdown({
            title: 'Clean',
            data: {
                sections: [
                    {
                        sectionType: 'hero',
                        visible: true,
                        content: {
                            heading: 'Hi',
                            ctaLink: 'https://secret.example/admin',
                            image: 'https://cdn.example/x.jpg',
                            id: 'abc123',
                        },
                    },
                ],
            },
        });
        expect(md).toContain('Hi');
        expect(md).not.toContain('secret.example');
        expect(md).not.toContain('abc123');
    });
});
//# sourceMappingURL=content-markdown.test.js.map