from pathlib import Path ROOT = Path(__file__).resolve().parents[1] APP = (ROOT / "ui_builder/static/app.js").read_text(encoding="utf-8") MAPPING = (ROOT / "hockey_data/mapping_context.py").read_text(encoding="utf-8") def test_side_penalty_mapping_context_is_derived_from_active_penalties_without_overwriting_manual_selection(): """Prepared penalties populate active_*; explicit selected side identifiers remain untouched.""" from tests.ui_contract_support import ui_contract ui_contract("side_context") def test_manual_side_penalty_selection_keeps_separate_mapping_identifiers(): start = APP.index("async function hockeySelectPenaltyForPreview") end = APP.index("function hockeyPenaltyCard", start) snippet = APP[start:end] for key in ( "selected_home_penalty_id", "selected_home_penalty_player_id", "selected_home_penalty_player_db_id", "selected_home_penalty_team_penalty", "selected_away_penalty_id", "selected_away_penalty_player_id", "selected_away_penalty_player_db_id", "selected_away_penalty_team_penalty", ): assert f"{key}:" in snippet assert key in MAPPING assert "const playerIds = hockeyPenaltyPlayerIdentifiers(component, event);" in snippet