from pathlib import Path


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

    assert 'function triggerUsesTabItem(trigger = {})' in js
    assert '["tab_change", "tab_enter", "tab_leave"]' in js
    assert 'function triggerTabItemOptions(selected = "")' in js
    assert '— любая вкладка —' in js
    assert '${escapeHtml(label)} · ${escapeHtml(id)}' in js
    assert 'function triggerItemIdFieldHtml(trigger = {})' in js
    assert '<label>Вкладка<select data-path="item_id">' in js
    assert 'выберите вкладку из списка' in js


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

    assert 'if (["source_action_id", "event"].includes(path)) {' in js
    assert 'rerender();' in js
