from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def test_odoo_status_panel_added_to_opportunity_detail():
    page = (ROOT / "app/admin_ui/pages/opportunities.py").read_text()
    assert '<a href="#odoo">Odoo</a>' in page
    assert '<div id="odoo">{odoo_status_panel_html(opportunity_id)}</div>' in page
    assert '@router.get("/opportunities/{opportunity_id}/partials/odoo-status"' in page
    assert '@router.post("/opportunities/{opportunity_id}/odoo/sync-status")' in page
    assert '@router.post("/opportunities/{opportunity_id}/odoo/link-candidate/{item_id}")' in page
    assert 'hx-target="#odoo-status-panel"' in page


def test_odoo_panel_is_manual_and_does_not_call_odoo_on_render():
    page = (ROOT / "app/admin_ui/pages/opportunities.py").read_text()
    assert 'def odoo_status_panel_html' in page
    panel_block = page.split('def odoo_status_panel_html', 1)[1].split('@router.get', 1)[0]
    assert 'Estado Odoo' in panel_block
    assert 'Sincronizar Odoo agora' in panel_block
    assert 'Vendas Odoo ligadas/candidatas' in panel_block
    assert 'sync_opportunity_odoo_status(' not in panel_block
    assert 'reconciliation_items' in page
    assert 'operation_links' in page
