from pathlib import Path


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

    assert 'const UI_NAVIGATION_ACTION_ID = "ui_navigation";' in js
    assert 'Все вкладки и внутренние статусы' in js
    assert 'function uiNavigationCatalog()' in js
    assert 'function triggerUsesNavigationItem(trigger = {})' in js
    assert 'function triggerNavigationItemOptions(selected = "", sourceActionId = UI_NAVIGATION_ACTION_ID)' in js
    assert 'Вкладка / статус<select data-path="item_id">' in js


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

    for scope in [
        '"view", "Раздел статистики"',
        '"team_mode", "Командная → Вид"',
        '"team_segment", "Командная → Период"',
        '"events_period", "События → Период"',
        '"events_type", "События → Тип"',
        '"players_filter", "Игроки → Команда"',
        '"season_filter", "Сезон → Команда"',
        '"powerplay_section", "Большинство → Раздел"',
        '"rank_section", "Рейтинг → Раздел"',
        '"shots_period", "Карта бросков → Период"',
        '"shots_side", "Карта бросков → Команда"',
    ]:
        assert scope in js


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

    assert 'function rememberUiNavigationState(' in js
    assert 'emitVirtualInteraction(UI_NAVIGATION_ACTION_ID, "tab_change", eventDetail);' in js
    assert 'emitInteraction(component, "tab_change", {' in js
    assert 'navigation: clone(state.uiNavigationStates)' in js


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

    for scope in [
        '"schedule_view", "Вид"',
        '"schedule_status", "Матчи команд → Статус"',
        '"schedule_venue", "Матчи команд → Площадка"',
        '"schedule_sort", "Матчи команд → Сортировка"',
        '"standings_view", "Вид таблицы"',
        '"shootout_size", "Основная серия"',
    ]:
        assert scope in js
    assert '"hockey_play_by_play", "Игра → Play-by-play", "period"' in js
