from pathlib import Path


def test_trigger_editor_has_collapse_controls_and_explicit_save():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    css = Path("ui_builder/static/styles.css").read_text(encoding="utf-8")
    assert "triggerEditorOpenIds: new Set()" in js
    assert 'data-toggle-trigger' in js
    assert 'data-save-triggers' in js
    assert 'toast("Триггеры сохранены")' in js
    assert '.trigger-card.is-collapsed' in css
    assert '.trigger-collapse-btn' in css


def test_operator_trigger_save_endpoint_only_updates_triggers():
    app = Path("app.py").read_text(encoding="utf-8")
    assert '"/api/hockey/ui/triggers"' in app
    assert 'draft_config["triggers"] = triggers' in app
    assert 'published_config["triggers"] = saved_draft.get("triggers", [])' in app
    assert 'dependencies=[Depends(hockey_auth.require_user)]' in app


def test_quick_panel_on_air_tracking_has_ack_confirmed_fallback():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    assert "quickPanelOnAirSequences: new Set()" in js
    assert "function setQuickPanelSequenceOnAir" in js
    assert "state.quickPanelOnAirSequences.has(id)" in js
    assert "Boolean(state.shortcutSequenceOverlayState.get(id))" in js
    assert 'fn.toLowerCase() === "overlayinputalloff"' in js
    assert 'normalized.match(/(?:^|[^a-z0-9])OverlayInput([1-4])' in js
    assert 'refreshQuickPanelOnAirClasses()' in js
