from src.utils import mouse


def _arduino(mocker):
    mocker.patch.object(mouse, '_focusTibia')
    return mocker.patch.object(mouse, 'sendCommandArduino', return_value=True)


def test_drag_uses_only_arduino_hid(mocker):
    send = _arduino(mocker)
    mouse.drag((1, 2), (3, 4))
    assert send.call_args_list == [
        mocker.call('moveTo,1,2'), mocker.call('dragStart'),
        mocker.call('moveTo,3,4'), mocker.call('dragEnd'),
    ]


def test_clicks_use_arduino_hid(mocker):
    send = _arduino(mocker)
    mouse.leftClick((3, 4))
    mouse.rightClick((5, 6))
    assert send.call_args_list == [
        mocker.call('moveTo,3,4'), mocker.call('leftClick'),
        mocker.call('moveTo,5,6'), mocker.call('rightClick'),
    ]


def test_modified_clicks_release_modifier(mocker):
    send = _arduino(mocker)
    mouse.useClick((3, 4))
    mouse.attackClick((5, 6))
    assert send.call_args_list == [
        mocker.call('moveTo,3,4'), mocker.call('keyDown,128'),
        mocker.call('leftClick'), mocker.call('keyUp,128'),
        mocker.call('moveTo,5,6'), mocker.call('keyDown,130'),
        mocker.call('leftClick'), mocker.call('keyUp,130'),
    ]


def test_move_and_scroll_use_arduino_hid(mocker):
    send = _arduino(mocker)
    mouse.moveTo((3, 4))
    mouse.scroll(5)
    assert send.call_args_list == [
        mocker.call('moveTo,3,4'), mocker.call('scroll,5'),
    ]
