"""Unit tests for ngsite.labels — type-code -> human label mapping, the
count-aware singular/plural rendering, and type aliasing used on the
browse read path.
"""
from ngsite import labels


def test_type_label_known_code():
    assert labels.type_label("strippedlower") == "Stripped Lowers"


def test_type_label_unknown_code_falls_back_to_code():
    assert labels.type_label("totally-made-up") == "totally-made-up"


def test_type_label_for_count_singular_vs_plural():
    # count==1 -> singular; count!=1 -> plural. (The "()" / "(0)" header
    # bug class lives near this logic — pin the contract.)
    singular = labels.type_label_for_count("strippedlower", 1)
    plural = labels.type_label_for_count("strippedlower", 2)
    assert singular != plural
    assert plural == "Stripped Lowers"


def test_type_label_for_count_zero_is_plural():
    assert labels.type_label_for_count("strippedlower", 0) == "Stripped Lowers"


def test_type_label_for_count_unknown_code():
    assert labels.type_label_for_count("nope", 1) == "nope"
    assert labels.type_label_for_count("nope", 3) == "nope"


def test_canonical_type_aliases_optics_to_optic():
    assert labels.canonical_type("optics") == "optic"


def test_canonical_type_passthrough_for_non_alias():
    assert labels.canonical_type("trigger") == "trigger"


def test_aliases_for_includes_canonical_and_variants():
    al = labels.aliases_for("optic")
    assert "optic" in al      # the canonical itself
    assert "optics" in al     # the scraper-side variant that aliases to it


def test_group_by_section_returns_dict():
    # Smoke: group_by_section should accept a by_type mapping and return a
    # section-keyed structure without raising.
    grouped = labels.group_by_section({"strippedlower": 2, "trigger": 1})
    assert isinstance(grouped, dict)
