diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 77735082..74b082ec 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers +import android.view.KeyEvent import android.view.inputmethod.InputConnection import android.widget.Button import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -71,6 +72,26 @@ class KeyboardTest { verify(exactly = 1) { mockInputConnection.deleteSurroundingText(1, 0) } } + @Test + fun testEnterKeyInsertsNewLine() { + every { mockIME.currentState } returns ScribeState.IDLE + // Simulate the IME behavior for Enter key: sending ACTION_DOWN and ACTION_UP events. + every { mockIME.handleKeycodeEnter() } answers { + mockInputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)) + mockInputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)) + } + + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + verify(exactly = 1) { mockIME.handleKeycodeEnter() } + verify(exactly = 1) { + mockInputConnection.sendKeyEvent(match { it.action == KeyEvent.ACTION_DOWN && it.keyCode == KeyEvent.KEYCODE_ENTER }) + } + verify(exactly = 1) { + mockInputConnection.sendKeyEvent(match { it.action == KeyEvent.ACTION_UP && it.keyCode == KeyEvent.KEYCODE_ENTER }) + } + } + @Test fun processSuggestions() { every { mockIME.findGenderForLastWord(any(), "in") } returns listOf("Neuter")