from pathlib import Path


def test_runtime_tab_switches_enter_trigger_engine():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")

    assert 'const PROJECT_TABS_ACTION_ID = "ui_tabs"' in js
    assert 'function emitRuntimeTabLifecycle(previousTab, nextTab, source = "runtime")' in js
    assert 'emitVirtualInteraction(PROJECT_TABS_ACTION_ID, "tab_change", detail)' in js
    assert 'emitInteraction(component, "tab_enter", detail)' in js
    assert 'emitInteraction(component, "tab_leave"' in js
    assert 'activateRuntimeTab(tab.id, { source: "runtime-tabs" })' in js
    assert 'activateRuntimeTab(tab.id, { source: "tab-bar" })' in js


def test_trigger_editor_exposes_project_tabs_and_tab_enter_leave():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")

    assert 'function triggerSourceOptions(selected = "")' in js
    assert 'Вкладки проекта · ${PROJECT_TABS_ACTION_ID}' in js
    assert '["tab_enter","tab_enter — вкладка открыта"]' in js
    assert '["tab_leave","tab_leave — вкладка закрыта"]' in js
    assert 'выберите вкладку из списка' in js


def test_prematch_button_editor_is_fullscreen():
    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 '{ className: "modal-prematch-full" }' in js
    assert '.modal-card.modal-prematch-full' in css
    assert 'width: calc(100vw - 20px);' in css
    assert 'height: calc(100vh - 20px);' in css
    assert 'grid-template-rows: auto minmax(0, 1fr) auto;' in css
