from src.ui.context import Context, _mergeMissing


def _defaults():
    return Context._defaultConfig()


def test_merge_fills_missing_healing_spell():
    config = {'healing': {'spells': {'criticalHealing': {'enabled': True}}}}

    changed = _mergeMissing(config, _defaults())

    assert changed is True
    # Vorhandene Werte bleiben, neue kommen dazu.
    assert config['healing']['spells']['criticalHealing']['enabled'] is True
    assert 'mediumHealing' in config['healing']['spells']
    assert 'ng_deathConfig' in config


def test_merge_keeps_existing_values_untouched():
    config = _defaults()
    config['auto_hur']['hotkey'] = 'x'
    config['healing']['potions']['firstHealthPotion']['slot'] = 7

    changed = _mergeMissing(config, _defaults())

    assert changed is False
    assert config['auto_hur']['hotkey'] == 'x'
    assert config['healing']['potions']['firstHealthPotion']['slot'] == 7


def test_merge_does_not_overwrite_lists():
    config = _defaults()
    config['ng_cave']['waypoints']['items'] = [{'label': 'hunt'}]

    _mergeMissing(config, _defaults())

    assert config['ng_cave']['waypoints']['items'] == [{'label': 'hunt'}]
