from src.gameplay.core.tasks.useSlotItem import UseSlotItemTask


def test_clicks_detected_slot_center(mocker):
    context = {'ng_screenshot': []}
    mocker.patch(
        'src.gameplay.core.tasks.useSlotItem.getSlotCenter',
        return_value=(120, 130))
    clickSpy = mocker.patch('src.gameplay.core.tasks.useSlotItem.leftClick')
    pressSpy = mocker.patch('src.utils.keyboard.press')

    task = UseSlotItemTask(3, fallbackHotkey='F1')

    assert task.name == 'useSlotItem'
    assert task.do(context) == context
    clickSpy.assert_called_once_with((120, 130))
    pressSpy.assert_not_called()


def test_falls_back_to_hotkey_without_action_bar(mocker):
    context = {'ng_screenshot': []}
    mocker.patch(
        'src.gameplay.core.tasks.useSlotItem.getSlotCenter', return_value=None)
    clickSpy = mocker.patch('src.gameplay.core.tasks.useSlotItem.leftClick')
    pressSpy = mocker.patch('src.utils.keyboard.press')

    task = UseSlotItemTask(3, fallbackHotkey='F1')
    task.do(context)

    clickSpy.assert_not_called()
    pressSpy.assert_called_once_with('F1')
