use super::*;

#[test]
fn render_stats_keeps_stats_summary_by_default() {
    let out = generate_markdown(&stats_docs(), &markdown_typedoc_options());

    assert!(out.get("index.md").unwrap().contains("symbols ·"));
    assert!(out.get("default/index.md").unwrap().contains("symbols ·"));
}

#[test]
fn render_stats_false_omits_stats_summary() {
    let options = MarkdownDocsOptions { render_stats: false, ..markdown_typedoc_options() };
    let out = generate_markdown(&stats_docs(), &options);
    let root = out.get("index.md").unwrap();
    let module_index = out.get("default/index.md").unwrap();

    assert!(!root.contains("symbols ·"));
    assert!(!module_index.contains("symbols ·"));
    // The gate also drops the trailing separator, so no stray blank line is
    // left where the stats summary used to be.
    assert!(!root.contains("\n\n\n"));
    assert!(!module_index.contains("\n\n\n"));
}

#[test]
fn render_stats_false_omits_html_stats_block() {
    let options = MarkdownDocsOptions {
        path_strategy: MarkdownPathStrategy::TypeDoc,
        render_style: MarkdownRenderStyle::Html,
        render_stats: false,
        ..MarkdownDocsOptions::default()
    };
    let out = generate_markdown(&stats_docs(), &options);

    // The option also gates the HTML render style's stats block.
    assert!(!out.get("index.md").unwrap().contains("ox-api-stats"));
    assert!(!out.get("default/index.md").unwrap().contains("ox-api-stats"));
}

#[test]
fn render_generated_by_keeps_attribution_by_default() {
    let markdown_out = generate_markdown(&stats_docs(), &markdown_typedoc_options());
    let html_out = generate_markdown(&stats_docs(), &html_typedoc_options());

    assert!(markdown_out
        .get("index.md")
        .unwrap()
        .contains("Generated by [Ox Content](https://github.com/ubugeeei-prod/ox-content)"));
    assert!(html_out
        .get("index.md")
        .unwrap()
        .contains("Generated by [Ox Content](https://github.com/ubugeeei-prod/ox-content)"));
}

#[test]
fn render_generated_by_false_omits_typedoc_root_attribution() {
    let options = MarkdownDocsOptions {
        render_generated_by: false,
        render_stats: false,
        ..markdown_typedoc_options()
    };
    let out = generate_markdown(&stats_docs(), &options);
    let root = out.get("index.md").unwrap();

    assert!(!root.contains("Generated by [Ox Content]"));
    assert!(root.starts_with("# API Documentation\n\n## Modules\n\n"));
    assert!(!root.contains("\n\n\n"));
}

#[test]
fn render_generated_by_false_keeps_stats_summary_when_enabled() {
    let options = MarkdownDocsOptions {
        render_generated_by: false,
        render_stats: true,
        ..markdown_typedoc_options()
    };
    let out = generate_markdown(&stats_docs(), &options);
    let root = out.get("index.md").unwrap();

    assert!(!root.contains("Generated by [Ox Content]"));
    assert!(root.contains("symbols ·"));
}

#[test]
fn render_generated_by_false_omits_flat_and_category_root_attribution() {
    let flat_options =
        MarkdownDocsOptions { render_generated_by: false, ..MarkdownDocsOptions::default() };
    let flat_out = generate_markdown(&stats_docs(), &flat_options);
    let flat_root = flat_out.get("index.md").unwrap();

    assert!(!flat_root.contains("Generated by [Ox Content]"));
    assert!(
        flat_root.starts_with("# API Documentation\n\n> Use search scopes like `@api transform`")
    );

    let category_options = MarkdownDocsOptions {
        group_by: "category".to_string(),
        render_style: MarkdownRenderStyle::Markdown,
        render_generated_by: false,
        render_stats: false,
        ..MarkdownDocsOptions::default()
    };
    let category_out = generate_markdown(&stats_docs(), &category_options);
    let category_root = category_out.get("index.md").unwrap();

    assert!(!category_root.contains("Generated by [Ox Content]"));
    assert!(category_root.starts_with("# API Documentation\n\n## [Functions]"));
}
