Skip to content
Prev Previous commit
Add test for InfoContent done action
  • Loading branch information
grzesiek2010 committed Jan 29, 2026
commit 69a034f9a136701ff5608238be1c223ce5e3f7f8
35 changes: 29 additions & 6 deletions geo/src/test/java/org/odk/collect/geo/geopoly/InfoContentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import android.app.Application
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -28,7 +31,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = true, {})
InfoContent(viewModel, fromSnackbar = true) {}
}

assertInfo(
Expand All @@ -48,7 +51,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = false, {})
InfoContent(viewModel, fromSnackbar = false) {}
}

assertInfo(
Expand All @@ -68,7 +71,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = true, {})
InfoContent(viewModel, fromSnackbar = true) {}
}

assertInfo(
Expand All @@ -88,7 +91,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = false, {})
InfoContent(viewModel, fromSnackbar = false) {}
}

assertInfo(
Expand All @@ -109,7 +112,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = true, {})
InfoContent(viewModel, fromSnackbar = true) {}
}

assertInfo(
Expand All @@ -129,7 +132,7 @@ class InfoContentTest {
}

composeTestRule.setContent {
InfoContent(viewModel, fromSnackbar = false, {})
InfoContent(viewModel, fromSnackbar = false) {}
}

assertInfo(
Expand All @@ -143,6 +146,26 @@ class InfoContentTest {
)
}

@Test
fun `calls onDone when Done button is clicked`() {
val viewModel = mock<GeoPolyViewModel>().apply {
whenever(recordingMode).thenReturn(GeoPolyViewModel.RecordingMode.PLACEMENT)
}

var onDoneCalled = false

composeTestRule.setContent {
InfoContent(viewModel, false) { onDoneCalled = true }
}

composeTestRule
.onNodeWithText(context.getString(org.odk.collect.strings.R.string.done))
.assertIsDisplayed()
.performClick()

assertThat(onDoneCalled, equalTo(true))
}

private fun assertInfo(items: List<Int>) {
items.forEach {
composeTestRule
Expand Down