from src.repositories.chat import core


def test_message_container_requires_detected_chat_status(mocker):
    mocker.patch.object(core, 'getLeftArrowPosition', return_value=(10, 20, 5, 5))
    mocker.patch.object(core, 'getChatMenuPosition', return_value=(200, 300, 5, 5))
    mocker.patch.object(core, 'getChatStatus', return_value=(None, True))

    assert core.getChatMessagesContainerPosition(object()) is None


def test_unknown_chat_status_defaults_to_off(mocker):
    mocker.patch.object(core, 'getChatOffPosition', return_value=None)
    mocker.patch.object(core, 'locate', return_value=None)

    assert core.getChatStatus(object()) == (None, False)


def test_transient_chat_on_label_uses_relaxed_match(mocker):
    screenshot = object()
    position = (1497, 1060, 64, 16)
    mocker.patch.object(core, 'getChatOffPosition', return_value=None)
    locate = mocker.patch.object(core, 'locate', return_value=position)

    assert core.getChatStatus(screenshot) == (position, True)
    locate.assert_called_once_with(screenshot, core.chatOnImgTemp, confidence=0.85)
