@@ -18,6 +18,7 @@ package com.ichi2.anki
1818import android.app.Application
1919import android.content.Intent
2020import android.view.Menu
21+ import android.view.View
2122import androidx.annotation.CheckResult
2223import androidx.core.content.edit
2324import androidx.core.os.BundleCompat
@@ -52,6 +53,7 @@ import com.ichi2.anki.observability.undoableOp
5253import com.ichi2.anki.preferences.PreferenceTestUtils
5354import com.ichi2.anki.preferences.sharedPrefs
5455import com.ichi2.anki.reviewer.ActionButtonStatus
56+ import com.ichi2.anki.snackbar.showSnackbar
5557import com.ichi2.testutils.common.Flaky
5658import com.ichi2.testutils.common.OS
5759import junit.framework.TestCase.assertEquals
@@ -62,6 +64,7 @@ import org.hamcrest.Matchers.containsString
6264import org.hamcrest.Matchers.empty
6365import org.hamcrest.Matchers.equalTo
6466import org.hamcrest.Matchers.not
67+ import org.hamcrest.Matchers.nullValue
6568import org.json.JSONArray
6669import org.junit.Assume.assumeTrue
6770import org.junit.Ignore
@@ -154,6 +157,38 @@ class ReviewerTest : RobolectricTest() {
154157 assertEquals(" Animation from swipe should be inverse to the finishing one" , expectedAnimation, actualAnimation)
155158 }
156159
160+ @Test
161+ fun `baseSnackbarBuilder has no anchor when answer buttons are hidden` () {
162+ addBasicNote()
163+ val reviewer = startReviewer()
164+ val answerButtons = reviewer.findViewById<View >(R .id.answer_options_layout)
165+ answerButtons.visibility = View .GONE
166+
167+ val snackbar = reviewer.showSnackbar(" test" )
168+
169+ assertThat(
170+ " anchorView must be null when answer buttons layout is not visible" ,
171+ snackbar?.anchorView,
172+ nullValue(),
173+ )
174+ }
175+
176+ @Test
177+ fun `baseSnackbarBuilder anchors to answer buttons when visible` () {
178+ addBasicNote()
179+ val reviewer = startReviewer()
180+ val answerButtons = reviewer.findViewById<View >(R .id.answer_options_layout)
181+ answerButtons.visibility = View .VISIBLE
182+
183+ val snackbar = reviewer.showSnackbar(" test" )
184+
185+ assertThat(
186+ " anchorView is the answer buttons layout when visible" ,
187+ snackbar?.anchorView,
188+ equalTo(answerButtons),
189+ )
190+ }
191+
157192 @Test
158193 fun noErrorShouldOccurIfSoundFileNotPresent () {
159194 addBasicNote(" [[sound:not_on_file_system.mp3]]" , " World" )
0 commit comments