import pytest

from a11yviz import alt_text, audit


def test_audit_fails_alt_by_default():
    pytest.importorskip("plotly")
    import plotly.graph_objects as go

    fig = go.Figure()
    rows = audit(fig)
    alt_row = next(r for r in rows if r["check"] == "Alt text on figure")
    assert alt_row["status"] == "todo"


def test_audit_passes_alt_after_alt_text():
    pytest.importorskip("plotly")
    import plotly.graph_objects as go

    fig = go.Figure()
    fig = alt_text(fig, "An empty figure used in tests.")
    rows = audit(fig)
    alt_row = next(r for r in rows if r["check"] == "Alt text on figure")
    assert alt_row["status"] == "ok"


def test_aa_returns_8_rows_aaa_adds_one():
    pytest.importorskip("plotly")
    import plotly.graph_objects as go

    fig = go.Figure()
    assert len(audit(fig, level="AA")) == 8
    assert len(audit(fig, level="AAA")) == 9


def test_audit_columns():
    pytest.importorskip("plotly")
    import plotly.graph_objects as go

    fig = go.Figure()
    rows = audit(fig)
    assert set(rows[0].keys()) == {"source", "check", "status", "note"}


def test_source_is_wcag_only():
    pytest.importorskip("plotly")
    import plotly.graph_objects as go

    fig = go.Figure()
    assert {r["source"] for r in audit(fig)} == {"WCAG 2.1"}
