Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import androidx.compose.ui.unit.dp
import org.groundplatform.android.R
import org.groundplatform.android.ui.theme.AppTheme

const val OPEN_NAV_DRAWER_TEST_TAG = "open_nav_drawer"
const val CHOOSE_MAP_TYPE_TEST_TAG = "choose_map_type"
const val LOCATION_LOCKED_TEST_TAG = "location_locked"
const val LOCATION_NOT_LOCKED_TEST_TAG = "location_not_locked"

@Composable
fun MapFloatingActionButton(
modifier: Modifier = Modifier,
Expand All @@ -55,24 +60,27 @@ sealed class MapFloatingActionButtonType(
val testTag: String,
) {
data object OpenNavDrawer :
MapFloatingActionButtonType(iconRes = R.drawable.baseline_menu_24, testTag = "open_nav_drawer")
MapFloatingActionButtonType(
iconRes = R.drawable.baseline_menu_24,
testTag = OPEN_NAV_DRAWER_TEST_TAG,
)

data object MapType :
MapFloatingActionButtonType(iconRes = R.drawable.map_layers, testTag = "choose_map_type")
MapFloatingActionButtonType(iconRes = R.drawable.map_layers, testTag = CHOOSE_MAP_TYPE_TEST_TAG)

// TODO: Consider adding another icon for representing "GPS disabled" state.
// Issue URL: https://github.com/google/ground-android/issues/1789
data class LocationLocked(override val iconTintRes: Int = R.color.md_theme_primary) :
MapFloatingActionButtonType(
iconRes = R.drawable.ic_gps_lock,
iconTintRes = iconTintRes,
testTag = "location_locked",
testTag = LOCATION_LOCKED_TEST_TAG,
)

data object LocationNotLocked :
MapFloatingActionButtonType(
iconRes = R.drawable.ic_gps_lock_not_fixed,
testTag = "location_not_locked",
testTag = LOCATION_NOT_LOCKED_TEST_TAG,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.groundplatform.android.ui.theme.AppTheme
const val MULTIPLE_CHOICE_ITEM_TEST_TAG = "multiple choice item test tag"
const val OTHER_INPUT_TEXT_TEST_TAG = "other input test tag"
const val SELECT_MULTIPLE_RADIO_TEST_TAG = "select multiple radio test tag"
const val SELECT_MULTIPLE_CHECKBOX_TEST_TAG = "select multiple checkbox test tag"

/**
* A composable function that displays a single item in a multiple-choice list.
Expand Down Expand Up @@ -95,7 +96,11 @@ fun MultipleChoiceItemView(
}

MultipleChoice.Cardinality.SELECT_MULTIPLE -> {
Checkbox(checked = item.isSelected, onCheckedChange = { toggleItem(item) })
Checkbox(
modifier = Modifier.testTag(SELECT_MULTIPLE_CHECKBOX_TEST_TAG),
checked = item.isSelected,
onCheckedChange = { toggleItem(item) },
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/date_task_frag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/user_response_text"
android:id="@+id/user_date_response_text"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:clickable="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/time_task_frag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/user_response_text"
android:id="@+id/user_time_response_text"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:clickable="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class DateTaskFragmentTest : BaseTaskFragmentTest<DateTaskFragment, DateTaskView
fun `default response is empty`() {
setupTaskFragment<DateTaskFragment>(job, task)

onView(withId(R.id.user_response_text))
onView(withId(R.id.user_date_response_text))
.check(matches(withText("")))
.check(matches(isDisplayed()))
.check(matches(isEnabled()))
Expand All @@ -89,7 +89,7 @@ class DateTaskFragmentTest : BaseTaskFragmentTest<DateTaskFragment, DateTaskView
view?.layoutParams = ViewGroup.LayoutParams(0, 1)

assertThat(fragment.getDatePickerDialog()).isNull()
onView(withId(R.id.user_response_text)).perform(click())
onView(withId(R.id.user_date_response_text)).perform(click())
assertThat(fragment.getDatePickerDialog()).isNotNull()
assertThat(fragment.getDatePickerDialog()?.isShowing).isTrue()
}
Expand All @@ -100,7 +100,7 @@ class DateTaskFragmentTest : BaseTaskFragmentTest<DateTaskFragment, DateTaskView

val view: View? = fragment.view?.findViewById(R.id.task_container)
view?.layoutParams = ViewGroup.LayoutParams(0, 1)
onView(withId(R.id.user_response_text)).perform(click())
onView(withId(R.id.user_date_response_text)).perform(click())
assertThat(fragment.getDatePickerDialog()?.isShowing).isTrue()

val hardcodedYear = 2024
Expand All @@ -121,7 +121,7 @@ class DateTaskFragmentTest : BaseTaskFragmentTest<DateTaskFragment, DateTaskView

val view: View? = fragment.view?.findViewById(R.id.task_container)
view?.layoutParams = ViewGroup.LayoutParams(0, 1)
onView(withId(R.id.user_response_text)).perform(click())
onView(withId(R.id.user_date_response_text)).perform(click())
assertThat(fragment.getDatePickerDialog()?.isShowing).isTrue()

val hardcodedYear = 2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TimeTaskFragmentTest : BaseTaskFragmentTest<TimeTaskFragment, TimeTaskView
fun `response when default is empty`() {
setupTaskFragment<TimeTaskFragment>(job, task)

onView(withId(R.id.user_response_text))
onView(withId(R.id.user_time_response_text))
.check(matches(withText("")))
.check(matches(isDisplayed()))
.check(matches(isEnabled()))
Expand All @@ -86,7 +86,7 @@ class TimeTaskFragmentTest : BaseTaskFragmentTest<TimeTaskFragment, TimeTaskView
view?.layoutParams = ViewGroup.LayoutParams(0, 1)

assertThat(fragment.getTimePickerDialog()).isNull()
onView(withId(R.id.user_response_text)).perform(click())
onView(withId(R.id.user_time_response_text)).perform(click())
assertThat(fragment.getTimePickerDialog()!!.isShowing).isTrue()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import kotlin.test.assertTrue
import org.groundplatform.android.BaseHiltTest
import org.groundplatform.android.FakeData.ADHOC_JOB
import org.groundplatform.android.R
import org.groundplatform.android.ui.components.LOCATION_LOCKED_TEST_TAG
import org.groundplatform.android.ui.components.LOCATION_NOT_LOCKED_TEST_TAG
import org.groundplatform.android.ui.components.MapFloatingActionButtonType
import org.groundplatform.android.ui.home.mapcontainer.jobs.AdHocDataCollectionButtonData
import org.groundplatform.android.ui.home.mapcontainer.jobs.JobMapComponentAction
Expand Down Expand Up @@ -75,14 +77,14 @@ class HomeScreenMapContainerScreenTest : BaseHiltTest() {
fun `Should display the correct icon when the location is not locked`() {
setContent(locationLockButtonType = MapFloatingActionButtonType.LocationNotLocked)

composeTestRule.onNodeWithTag("location_not_locked").assertIsDisplayed()
composeTestRule.onNodeWithTag(LOCATION_NOT_LOCKED_TEST_TAG).assertIsDisplayed()
}

@Test
fun `Should display the correct icon the location is locked`() {
setContent(locationLockButtonType = MapFloatingActionButtonType.LocationLocked())

composeTestRule.onNodeWithTag("location_locked").assertIsDisplayed()
composeTestRule.onNodeWithTag(LOCATION_LOCKED_TEST_TAG).assertIsDisplayed()
}

@Test
Expand Down