1313 */
1414package com.ichi2.anki
1515
16+ import android.text.InputType
1617import androidx.core.content.edit
1718import androidx.test.espresso.Espresso.onView
1819import androidx.test.espresso.action.ViewActions.click
@@ -21,6 +22,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2122import androidx.test.espresso.matcher.ViewMatchers.withId
2223import androidx.test.ext.junit.rules.ActivityScenarioRule
2324import androidx.test.ext.junit.runners.AndroidJUnit4
25+ import com.google.android.material.textfield.TextInputEditText
2426import com.ichi2.anki.libanki.Collection
2527import com.ichi2.anki.preferences.sharedPrefs
2628import com.ichi2.anki.tests.InstrumentedTest
@@ -40,6 +42,7 @@ import org.junit.Rule
4042import org.junit.Test
4143import org.junit.runner.RunWith
4244import java.util.concurrent.TimeUnit
45+ import kotlin.time.Duration.Companion.seconds
4346
4447@RunWith(AndroidJUnit4 ::class )
4548class ReviewerFragmentTest : InstrumentedTest () {
@@ -118,6 +121,55 @@ class ReviewerFragmentTest : InstrumentedTest() {
118121 ensureAnswerButtonsAreDisplayed()
119122 }
120123
124+ @Test
125+ fun testSelectedKeyboardType () {
126+ setNewReviewer()
127+ closeGetStartedScreenIfExists()
128+ closeBackupCollectionDialogIfExists()
129+
130+ val inputTypeNumber =
131+ InputType .TYPE_CLASS_NUMBER or InputType .TYPE_NUMBER_FLAG_DECIMAL or InputType .TYPE_NUMBER_FLAG_SIGNED
132+ val inputTypeText = InputType .TYPE_CLASS_TEXT
133+
134+ val testValues: List <Pair <String , Int >> =
135+ listOf (
136+ " 123" to inputTypeNumber,
137+ " -123.45" to inputTypeNumber,
138+ " 123.45" to inputTypeNumber,
139+ " 123,45" to inputTypeNumber,
140+ " <b>123</b>" to inputTypeNumber,
141+ " AnkiDroid" to inputTypeText,
142+ " 123abc" to inputTypeText,
143+ " " to inputTypeText,
144+ )
145+
146+ testValues.forEachIndexed { index, (typedAnswer, _) ->
147+ addTypedAnswerNote(answer = typedAnswer).firstCard(col).update {
148+ did = col.decks.id(" Default$index " )
149+ }
150+ }
151+
152+ // Check decks after adding all notes to ensure that the deck list is updated with the new cards
153+ testValues.forEachIndexed { index, (_, expectedInputType) ->
154+ // Ensures that we are in the deckpicker screen to make reviewDeckWithName work
155+ if (index > 0 ) onView(withId(R .id.back_button)).perform(click())
156+ checkInputType(expectedInputType, index)
157+ }
158+ }
159+
160+ fun checkInputType (
161+ expectedInputType : Int ,
162+ index : Int ,
163+ ) {
164+ reviewDeckWithName(" Default$index " )
165+ ensureKeyboardIsDisplayed()
166+ onView(withId(R .id.type_answer_edit_text)).check { view, _ ->
167+ val editText = view as TextInputEditText
168+ val inputType = editText.inputType
169+ assertThat(inputType, equalTo(expectedInputType))
170+ }
171+ }
172+
121173 private fun clickShowAnswerAndAnswerGood () {
122174 clickShowAnswer()
123175 ensureAnswerButtonsAreDisplayed()
@@ -128,6 +180,14 @@ class ReviewerFragmentTest : InstrumentedTest() {
128180 onView(withId(R .id.show_answer)).perform(click())
129181 }
130182
183+ private fun ensureKeyboardIsDisplayed () {
184+ onView(withId(R .id.type_answer_edit_text)).checkWithTimeout(
185+ matches(isDisplayed()),
186+ 100 ,
187+ 30 .seconds.inWholeMilliseconds,
188+ )
189+ }
190+
131191 private fun ensureAnswerButtonsAreDisplayed () {
132192 // We need to wait for the card to fully load to allow enough time for
133193 // the messages to be passed in and out of the WebView when evaluating
0 commit comments