from pathlib import Path

JS = Path('ui_builder/static/app.js').read_text(encoding='utf-8')
CSS = Path('ui_builder/static/styles.css').read_text(encoding='utf-8')


def test_settings_modals_are_locked_fullscreen_workspaces():
    assert 'function showSettingsModal' in JS
    assert 'locked: true' in JS
    assert 'modal-settings-full' in JS
    for title in ('Таймеры', 'Нижняя панель · кнопки', 'Шорткаты и сценарии', 'События и триггеры', 'Резервные копии'):
        assert f'showSettingsModal("{title}"' in JS
    assert '.modal-card.modal-settings-full' in CSS
    assert 'height: calc(100vh - 12px)' in CSS


def test_nested_trigger_select_is_wide_and_wraps_full_text():
    assert 'css-select-popover-wide' in JS
    assert 'select.dataset.path === "item_id"' in JS
    assert 'css-select-group-label' in JS
    assert '.css-select-popover-wide .css-select-option-label' in CSS
    assert 'white-space: normal' in CSS
    assert 'overflow-wrap: anywhere' in CSS


def test_locked_modal_does_not_close_on_backdrop_or_escape():
    assert 'if (!locked && event.target.classList.contains("modal-backdrop")) closeModal();' in JS
    assert 'if (!state.modalLocked) closeModal();' in JS
    assert 'Несохранённые изменения могут быть потеряны' in JS
