from pathlib import Path


def test_close_opportunity_primary_button_posts_delivered_operation():
    text = Path('app/admin_ui/pages/opportunities.py').read_text()
    assert 'action_code_upper == "CLOSE_OPPORTUNITY"' in text
    assert '/operations/delivered' in text
    assert '<button class="btn btn-success" type="submit">Concluir oportunidade</button>' in text
    assert 'clientflow_next_action' in text


def test_operation_cockpit_prefers_central_decision_for_close():
    text = Path('app/admin_dashboard.py').read_text()
    assert 'central_next_action = opportunity.get("clientflow_next_action")' in text
    assert 'central_action_code == "CLOSE_OPPORTUNITY"' in text or 'action_code == "CLOSE_OPPORTUNITY"' in text
    assert 'stale legacy plan' in text
    assert '/operations/delivered' in text
