"""Tests des visualisations des couleurs de têtes de minifigs."""

import matplotlib
from pathlib import Path

from lib.plots.minifig_heads import plot_global_shares, plot_shares_by_year


matplotlib.use("Agg")


def test_plot_minifig_heads(tmp_path: Path) -> None:
    """Produit les graphes part par année et global."""
    heads_path = tmp_path / "minifig_heads_by_year.csv"
    milestones_path = tmp_path / "milestones.csv"
    shares_dest = tmp_path / "figures" / "step16" / "minifig_heads_shares.png"
    global_dest = tmp_path / "figures" / "step16" / "minifig_heads_global.png"
    heads_path.write_text(
        "year,color_rgb,is_translucent,color_name,quantity\n"
        "2020,FFE1BD,false,Light Flesh,2\n"
        "2020,FFFF00,false,Yellow,1\n"
        "2021,FFE1BD,false,Light Flesh,1\n"
        "2021,E7B68F,false,Medium Dark Flesh,3\n"
    )
    milestones_path.write_text("year,description\n2020,Jalon Test\n")

    plot_shares_by_year(heads_path, shares_dest, milestones_path=milestones_path)
    plot_global_shares(heads_path, global_dest)

    assert shares_dest.exists()
    assert shares_dest.stat().st_size > 0
    assert global_dest.exists()
    assert global_dest.stat().st_size > 0
