target-revenue/tests/test_guidance.py
tegwick f1109d54ee Add Control Plane bubble help and step-by-step guidance
Context ? help popovers, lifecycle checklist, and recommended-next-step
cards on login, dashboard, phase detail/new, and extensions. Pure
guidance helpers + CSS; deploy image 0.1.4.
2026-08-06 22:35:05 +02:00

88 lines
2.6 KiB
Python

"""Unit tests for Control Plane next-step guidance."""
from target_revenue.service import guidance
def test_dashboard_empty_operator_recommends_register():
steps = guidance.dashboard_guidance(
rights="operator",
phase_count=0,
pending_proposals=0,
root_path="/ui",
)
assert steps[0]["key"] == "register_phase"
assert steps[0]["priority"] == "recommended"
assert steps[0]["href"] == "/ui/phases/new"
def test_dashboard_with_phase_opens_first():
steps = guidance.dashboard_guidance(
rights="viewer",
phase_count=1,
pending_proposals=0,
root_path="/ui",
first_phase_id="trsl:phase:demo",
)
assert steps[0]["key"] == "open_phase"
assert "trsl:phase:demo" in steps[0]["href"]
def test_phase_empty_ledger_recommends_credit_or_remission():
metrics = {
"facts": {
"is_converted": False,
"cumulative_development_credit": 0,
"cumulative_remission_credit": 0,
"initial_target_currency": "EUR",
},
"forecasts": {"remission_if_applied_now": 12.5, "next_scheduled_remission_at": None},
}
steps = guidance.phase_guidance(
rights="operator",
root_path="/ui",
phase_id="trsl:phase:demo",
metrics=metrics,
ledger_len=0,
extension_count=1,
has_attestation=False,
)
keys = [s["key"] for s in steps]
assert "apply_remission" in keys
assert keys[0] == "apply_remission" # material remission first
def test_phase_converted_done_hint():
metrics = {
"facts": {"is_converted": True, "cumulative_development_credit": 1, "cumulative_remission_credit": 0},
"forecasts": {},
}
steps = guidance.phase_guidance(
rights="operator",
root_path="/ui",
phase_id="trsl:phase:demo",
metrics=metrics,
ledger_len=2,
extension_count=1,
has_attestation=True,
)
assert steps[0]["key"] == "converted"
assert steps[0]["priority"] == "done_hint"
def test_lifecycle_checklist_progress():
metrics = {
"facts": {
"is_converted": False,
"cumulative_development_credit": 10,
"cumulative_remission_credit": 0,
}
}
items = guidance.phase_lifecycle_checklist(
ledger_len=1, metrics=metrics, has_attestation=False
)
by_id = {i["id"]: i["done"] for i in items}
assert by_id["declared"] is True
assert by_id["activity"] is True
assert by_id["dev_credit"] is True
assert by_id["remission"] is False
assert by_id["converted"] is False