From 44677de97bc945c1c5952efdc83df243205382e4 Mon Sep 17 00:00:00 2001 From: bhanu-dev82 Date: Thu, 22 Jan 2026 21:23:43 +0530 Subject: [PATCH 1/2] Test: Add unit test for Enter key behavior in KeyboardTest (#440) --- .../kotlin/be/scri/helpers/KeyboardTest.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 77735082..824d9a22 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,29 @@ class KeyboardTest { verify(exactly = 1) { mockInputConnection.deleteSurroundingText(1, 0) } } + @Test + fun testEnterKeyInsertsNewLine() { + // Arrange + 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)) + } + + // Act + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + // Assert + 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") From 3f97da0b9047f6e7a8568a46841ce2c33eaf8318 Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Fri, 23 Jan 2026 21:11:45 +0100 Subject: [PATCH 2/2] Clean up comments for enter key press test --- app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 824d9a22..74b082ec 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -74,18 +74,15 @@ class KeyboardTest { @Test fun testEnterKeyInsertsNewLine() { - // Arrange every { mockIME.currentState } returns ScribeState.IDLE - // Simulate the IME behavior for Enter key: sending ACTION_DOWN and ACTION_UP events + // 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)) } - // Act keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") - // Assert verify(exactly = 1) { mockIME.handleKeycodeEnter() } verify(exactly = 1) { mockInputConnection.sendKeyEvent(match { it.action == KeyEvent.ACTION_DOWN && it.keyCode == KeyEvent.KEYCODE_ENTER })