import { describe, expect, it } from 'vitest';
import { analyzeContent, extractHeadings } from '../../seo/analysis.js';
import { countH1 } from '../../seo/score.js';
/**
 * Regression coverage for markdown-bodied content. The heading checks used to
 * match only HTML `<h1>`/`<h2>` tags, so every markdown post was wrongly flagged
 * with "No H1 heading found" and "no subheadings". These tests lock in that both
 * HTML and Markdown headings are recognised.
 */
describe('extractHeadings (markdown-aware)', () => {
    it('extracts ATX markdown headings at the requested level', () => {
        const md = '# Title\n\nIntro.\n\n## Section A\n\n## Section B\n';
        expect(extractHeadings(md, 1)).toEqual(['Title']);
        expect(extractHeadings(md, 2)).toEqual(['Section A', 'Section B']);
    });
    it('extracts Setext markdown headings', () => {
        const md = 'Big Title\n=========\n\nA Subhead\n---------\n';
        expect(extractHeadings(md, 1)).toEqual(['Big Title']);
        expect(extractHeadings(md, 2)).toEqual(['A Subhead']);
    });
    it('still extracts HTML headings', () => {
        const html = '<h1>HTML Title</h1><h2>Sub</h2>';
        expect(extractHeadings(html, 1)).toEqual(['HTML Title']);
        expect(extractHeadings(html, 2)).toEqual(['Sub']);
    });
    it('ignores `#` inside fenced code blocks', () => {
        const md = '# Real Title\n\n```\n# not a heading\n```\n';
        expect(extractHeadings(md, 1)).toEqual(['Real Title']);
    });
    it('does not treat a higher-level ATX heading as a lower one', () => {
        expect(extractHeadings('### Deep', 1)).toEqual([]);
        expect(extractHeadings('### Deep', 3)).toEqual(['Deep']);
    });
});
describe('countH1 (markdown-aware)', () => {
    it('counts HTML h1 tags', () => {
        expect(countH1('<h1>a</h1>')).toBe(1);
        expect(countH1('<H1>a</H1><h1>b</h1>')).toBe(2);
    });
    it('counts markdown h1 headings', () => {
        expect(countH1('# Only One\n\nbody')).toBe(1);
        expect(countH1('# One\n\n# Two')).toBe(2);
        expect(countH1('## Not an h1')).toBe(0);
    });
});
describe('analyzeContent h1-present for markdown bodies', () => {
    it('passes the H1 check when the markdown body has exactly one H1', () => {
        const result = analyzeContent({
            title: 'My Post',
            slug: 'my-post',
            content: '# My Post\n\nSome intro text.\n\n## Details\n\nMore text here.',
        });
        const h1Check = result.checks.find((c) => c.id === 'h1-present');
        expect(h1Check?.status).toBe('good');
    });
});
//# sourceMappingURL=analysis-markdown.test.js.map