import { describe, it, expect } from 'vitest';
import { buildSeoFixBriefMarkdown, filterFixBriefIssues, fixBriefFilename, isManualHandoffIssue, adminPathForIssue, } from '../../seo/fix-brief-export.js';
const baseIssue = {
    id: 'issue-1',
    type: 'thin-content',
    title: 'Content below 300 words',
    description: 'Thin pages tend to rank poorly.',
    impact: 'Low',
    recommendation: 'Add more useful content or an FAQ section.',
    severity: 'info',
    category: 'content',
    status: 'open',
    entityType: 'page',
    entityId: 'page-1',
    entityTitle: 'Contact Support',
    url: '/support',
    fixActionType: 'edit-content',
    fixable: false,
};
describe('isManualHandoffIssue', () => {
    it('includes thin content and heading issues', () => {
        expect(isManualHandoffIssue(baseIssue)).toBe(true);
        expect(isManualHandoffIssue({ ...baseIssue, type: 'missing-h1', fixActionType: 'edit-content' })).toBe(true);
    });
    it('excludes inline metadata fixes', () => {
        expect(isManualHandoffIssue({
            ...baseIssue,
            type: 'meta-description-length',
            fixActionType: 'edit-metadata',
            fixable: true,
        })).toBe(false);
    });
    it('includes broken link issues', () => {
        expect(isManualHandoffIssue({
            ...baseIssue,
            type: 'broken-internal-link',
            fixActionType: 'fix-link',
            fixable: true,
        })).toBe(true);
    });
});
describe('buildSeoFixBriefMarkdown', () => {
    it('groups issues by page and includes handoff instructions', () => {
        const md = buildSeoFixBriefMarkdown({
            siteName: 'UpChat',
            siteUrl: 'https://upchat.example',
            auditDate: '2024-06-27T11:20:48.000Z',
            auditRunId: 'run-1',
            issues: [
                baseIssue,
                {
                    ...baseIssue,
                    id: 'issue-2',
                    type: 'missing-h1',
                    title: 'Missing H1 heading',
                    recommendation: 'Add a single descriptive H1 heading to the content.',
                },
                {
                    ...baseIssue,
                    id: 'issue-3',
                    type: 'meta-title-length',
                    title: 'Meta title too long',
                    fixActionType: 'edit-metadata',
                    fixable: true,
                },
            ],
        });
        expect(md).toContain('# SEO Content Fix Brief');
        expect(md).toContain('**Site:** UpChat');
        expect(md).toContain('Re-run **SEO → Run audit**');
        expect(md).toContain('## 1. Contact Support');
        expect(md).toContain('Missing H1 heading');
        expect(md).toContain('Content below 300 words');
        expect(md).not.toContain('Meta title too long');
        expect(md).toContain('`/pages/page-1`');
        expect(md).toContain('`issue-1`');
    });
    it('returns empty-state message when no issues match', () => {
        const md = buildSeoFixBriefMarkdown({
            siteName: 'Test',
            issues: [
                {
                    ...baseIssue,
                    type: 'missing-meta-title',
                    fixActionType: 'edit-metadata',
                    fixable: true,
                },
            ],
        });
        expect(md).toContain('No issues match this export filter');
    });
    it('embeds cached content briefs in issue blocks', () => {
        const md = buildSeoFixBriefMarkdown({
            siteName: 'UpChat',
            issues: [
                {
                    ...baseIssue,
                    contentBrief: {
                        issueType: 'thin-content',
                        entityId: 'page-1',
                        fingerprint: 'x',
                        generatedAt: '2024-01-01T00:00:00.000Z',
                        summary: 'Expand with support channels and FAQs.',
                        suggestedH1: 'Contact UpChat Support',
                        targetWordCount: 450,
                        topics: ['Email', 'Chat hours'],
                        sections: [],
                        keyTakeawayDraft: 'Reach UpChat support by email or chat.',
                        geoNote: null,
                    },
                },
            ],
        });
        expect(md).toContain('Content brief');
        expect(md).toContain('Contact UpChat Support');
        expect(md).toContain('Reach UpChat support by email or chat.');
    });
});
describe('filterFixBriefIssues', () => {
    it('respects manualOnly=false', () => {
        const issues = [
            baseIssue,
            {
                ...baseIssue,
                id: 'm1',
                type: 'missing-meta-title',
                fixActionType: 'edit-metadata',
                fixable: true,
            },
        ];
        expect(filterFixBriefIssues(issues, true)).toHaveLength(1);
        expect(filterFixBriefIssues(issues, false)).toHaveLength(2);
    });
});
describe('fixBriefFilename', () => {
    it('builds a safe download name', () => {
        expect(fixBriefFilename('Up Chat!', '2024-06-27T00:00:00.000Z')).toBe('Up-Chat-seo-fix-brief-2024-06-27.md');
    });
});
describe('adminPathForIssue', () => {
    it('links pages to the page editor', () => {
        expect(adminPathForIssue(baseIssue)).toBe('/pages/page-1');
    });
    it('links redirect issues to the redirects tab', () => {
        expect(adminPathForIssue({
            ...baseIssue,
            entityId: null,
            fixActionType: 'fix-link',
            type: 'broken-internal-link',
        })).toBe('/seo?tab=redirects');
    });
});
//# sourceMappingURL=fix-brief-export.test.js.map