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 @@ -130,10 +130,7 @@ internal constructor(
/** [Feature] clicked by the user. */
val featureClicked: MutableStateFlow<Feature?> = MutableStateFlow(null)

/**
* List of [Job]s which allow LOIs to be added during field collection, populated only when zoomed
* in far enough.
*/
/** List of [Job]s which allow LOIs to be added during field collection. */
private val adHocLoiJobs: Flow<List<Job>>

private val showJobSelectionModal = MutableStateFlow(false)
Expand Down Expand Up @@ -179,8 +176,8 @@ internal constructor(
.stateIn(viewModelScope, SharingStarted.Lazily, listOf())

adHocLoiJobs =
activeSurvey.combine(isZoomedInFlow) { survey, isZoomedIn ->
if (survey == null || !isZoomedIn) listOf()
activeSurvey.map { survey ->
if (survey == null) listOf()
else survey.jobs.filter { it.canDataCollectorsAddLois && it.getAddLoiTask() != null }
Comment on lines +180 to 181

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: can be slightly simplified with

Suggested change
if (survey == null) listOf()
else survey.jobs.filter { it.canDataCollectorsAddLois && it.getAddLoiTask() != null }
survey?.jobs?.filter { it.canDataCollectorsAddLois && it.getAddLoiTask() != null } ?: listOf()

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.groundplatform.android.FakeData.LOCATION_OF_INTEREST_LOI_REPORT
import org.groundplatform.android.FakeData.SURVEY
import org.groundplatform.android.FakeData.USER
import org.groundplatform.android.R
import org.groundplatform.android.common.Constants.CLUSTERING_ZOOM_THRESHOLD
import org.groundplatform.android.data.remote.FakeRemoteDataStore
import org.groundplatform.android.di.LocationOfInterestRepositoryModule
import org.groundplatform.android.system.auth.FakeAuthenticationManager
Expand Down Expand Up @@ -158,6 +159,20 @@ class HomeScreenMapContainerViewModelTest : BaseHiltTest() {
assertThat(addLoiState.jobs.map { it.job }).containsExactly(ADHOC_JOB)
}

@Test
fun `job component state is AddLoiButton below clustering threshold`() = runWithTestDispatcher {
viewModel.onMapCameraMoved(
CAMERA_POSITION.copy(zoomLevel = CLUSTERING_ZOOM_THRESHOLD - 1f)
)
advanceUntilIdle()

val state = viewModel.processJobMapComponentState().first()

assertThat(state).isInstanceOf(JobMapComponentState.AddLoiButton::class.java)
assertThat((state as JobMapComponentState.AddLoiButton).jobs.map { it.job })
.containsExactly(ADHOC_JOB)
}

@Test
fun `setJobSelectionModalVisibility hides map actions when modal is shown`() =
runWithTestDispatcher {
Expand Down
Loading