Skip to content

Commit

Permalink
feat(test): Add regression test for 8923
Browse files Browse the repository at this point in the history
Even if a media delay is provided, there should be no auto answer
if the times are set to 0s
  • Loading branch information
david-allison authored and mikehardy committed Oct 13, 2021
1 parent 9b33f44 commit 9c41742
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.ichi2.anki.reviewer

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.reviewer.AutomaticAnswer.AutomaticallyAnswered
import com.ichi2.testutils.EmptyApplication
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -31,9 +32,8 @@ class AutomaticAnswerTest {

@Test
fun stopAllWorks() {
val target: AutomaticAnswer.AutomaticallyAnswered = mock()
val answer = AutomaticAnswer(
target = target,
target = automaticallyAnsweredMock(),
settings = AutomaticAnswerSettings(
useTimer = true,
questionDelaySeconds = 10,
Expand All @@ -50,4 +50,26 @@ class AutomaticAnswerTest {

assertThat(answer.timeoutHandler.hasMessages(0), equalTo(false))
}

@Test
fun noExecutionIfTimerIsZero_issue8923() {
val answer = AutomaticAnswer(
target = automaticallyAnsweredMock(),
settings = AutomaticAnswerSettings(
useTimer = true,
questionDelaySeconds = 0,
answerDelaySeconds = 0
)
)

answer.scheduleAutomaticDisplayQuestion(10)

assertThat("no messages even if delay provided", answer.timeoutHandler.hasMessages(0), equalTo(false))

answer.scheduleAutomaticDisplayAnswer(10)

assertThat("no messages even if delay provided", answer.timeoutHandler.hasMessages(0), equalTo(false))
}

private fun automaticallyAnsweredMock(): AutomaticallyAnswered = mock()
}

0 comments on commit 9c41742

Please sign in to comment.