Commit 2867fdfd by likorn

Only the first answer is accepted

parent b1e5f2a7
......@@ -12,18 +12,16 @@ import androidx.core.view.get
import androidx.test.espresso.ViewAction
import androidx.test.espresso.UiController
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import junit.framework.Assert.assertTrue
import org.hamcrest.Matcher
import org.junit.Before
class MainActivityTest {
@get:Rule
val testRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
private lateinit var radioGroup: RadioGroup
@Before
fun init() {
radioGroup = testRule.activity.radio_group
......@@ -34,7 +32,9 @@ class MainActivityTest {
val correctAnswerIndex = getCorrectAnswerIndex()
val correctAnswerId = radioGroup[correctAnswerIndex].id
onView(withId(correctAnswerId)).perform(click())
onView(withId(R.id.response)).check(matches(withText(R.string.response_correct)))
assertTrue(testRule.activity.supportFragmentManager.fragments.size == 1)
assertTrue(testRule.activity.supportFragmentManager.fragments[0] is ResponseCorrectFragment)
}
@Test
......@@ -43,9 +43,20 @@ class MainActivityTest {
val wrongAnswerIndex = if (correctAnswerIndex == 3) 2 else 3
val wrongAnswerId = radioGroup[wrongAnswerIndex].id
onView(withId(wrongAnswerId)).perform(click())
onView(withId(R.id.response)).check(matches(withText(R.string.response_wrong)))
assertTrue(testRule.activity.supportFragmentManager.fragments.size == 1)
assertTrue(testRule.activity.supportFragmentManager.fragments[0] is ResponseWrongFragment)
}
@Test
fun only_fist_answer_accepted() {
onView(withId(radioGroup[0].id)).perform(click())
assertTrue(testRule.activity.supportFragmentManager.fragments.size == 1)
onView(withId(radioGroup[1].id)).perform(click())
assertTrue(testRule.activity.supportFragmentManager.fragments.size == 1)
}
private fun getCorrectAnswerIndex(): Int {
val options = getOptions()
val correctAnswer = findSecondMax(options)
......
......@@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
var numberSet = NumberSet(4, 3)
private var toAcceptAnswer = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -29,6 +30,9 @@ class MainActivity : AppCompatActivity() {
}
private fun processAnswer(answer: Int) {
if (!toAcceptAnswer)
return
toAcceptAnswer = false
val responseFragment:Fragment = if (numberSet.isCorrect(answer)) {
ResponseCorrectFragment.newInstance()
} else
......
......@@ -25,7 +25,6 @@
app:srcCompat="@drawable/ic_double_arrow" />
<TextView
android:id="@+id/response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
......
......@@ -11,7 +11,6 @@
app:layout_constraintStart_toStartOf="parent">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
......@@ -25,7 +24,6 @@
app:srcCompat="@drawable/ic_double_arrow" />
<TextView
android:id="@+id/response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment