-
Notifications
You must be signed in to change notification settings - Fork 142
Fix issue 3541, Can't complete polygon after getting an interception error popup #3606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hassan-nsubuga
wants to merge
22
commits into
master
Choose a base branch
from
bugfix/3541
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9556c93
Fix isse 3541, reset hasSelfIntersection to false in updateVertices a…
hassan-nsubuga 5cb0e85
Add tests to DrawAreaTaskViewModelTest to convert resetting of hasSel…
hassan-nsubuga 520a374
Bump com.google.maps.android:android-maps-utils from 4.1.0 to 4.1.1 (…
dependabot[bot] 951c359
fix codecov failing dependabot CI (#3612)
andreia-ferreira 6f8ee64
Migrate home screen drawer to Compose (#3554)
gino-m a2ed615
Refactor DrawAreaTaskViewModel, change showSelfIntersectionDialog an…
hassan-nsubuga 8bc5523
Refactor DrawAreaTaskViewModelTest to add more tests to cover the cha…
hassan-nsubuga 7f56a0f
Merge branch 'master' into bugfix/3541
hassan-nsubuga daa7cd4
Remove `imageUrl` binding adapter from `BindingAdapters` (#3620)
shobhitagarwal1612 4aeda4f
Fix firebase emulator failing CI (#3613)
andreia-ferreira 7975a9e
Migrate TaskView to compose (#3617)
shobhitagarwal1612 750b1d6
Refactor HomeDrawer to use Material 3 typography (#3623)
shobhitagarwal1612 3744ab3
Bump kotlinVersion from 2.3.10 to 2.3.20 (#3616)
dependabot[bot] 5b53d01
Bump androidx.compose:compose-bom from 2026.02.01 to 2026.03.00 (#3609)
dependabot[bot] 62380f9
fix delete loi called on every started lifecycle event (#3618)
andreia-ferreira 7a14f2f
Bump gradle-wrapper from 9.4.0 to 9.4.1 (#3626)
dependabot[bot] 69dbdc8
Refactor DrawAreaTaskViewModel, change showSelfIntersectionDialog an…
hassan-nsubuga 838c8b2
Refactor, rename method to showSelfIntersectionDialog, make it priva…
hassan-nsubuga 258a133
Refactor, add tearDown method to reset dispatcher and prevent possibl…
hassan-nsubuga 8ef5d61
Collect showSelfIntersectionDialog using collectAsStateWithLifecycle,…
hassan-nsubuga af69b35
Format code in DrawAreaTaskFragment
hassan-nsubuga fb2f968
Merge branch 'master' into bugfix/3541
hassan-nsubuga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,17 @@ import kotlin.test.assertEquals | |
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertNotNull | ||
| import kotlin.test.assertTrue | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.filterNotNull | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.merge | ||
| import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
| import kotlinx.coroutines.test.advanceUntilIdle | ||
| import kotlinx.coroutines.test.resetMain | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlinx.coroutines.test.setMain | ||
| import org.groundplatform.android.BaseHiltTest | ||
| import org.groundplatform.android.data.local.LocalValueStore | ||
| import org.groundplatform.android.model.job.Job | ||
|
|
@@ -53,6 +58,7 @@ import org.groundplatform.domain.model.geometry.Coordinates | |
| import org.groundplatform.domain.model.geometry.LineString | ||
| import org.groundplatform.domain.model.geometry.LinearRing | ||
| import org.groundplatform.domain.model.geometry.Polygon | ||
| import org.junit.After | ||
| import org.junit.Assert.assertThrows | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
@@ -72,6 +78,7 @@ class DrawAreaTaskViewModelTest : BaseHiltTest() { | |
|
|
||
| override fun setUp() { | ||
| super.setUp() | ||
| Dispatchers.setMain(UnconfinedTestDispatcher()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when overriding the main test dispatcher, it should be reset otherwise it may leak into other tests. I suggest adding the following to the test file to prevent it: |
||
| mergedFeatureFlow = merge(viewModel.draftArea.filterNotNull(), viewModel.draftUpdates) | ||
|
|
||
| mergedFeatureLiveData = mergedFeatureFlow.asLiveData() | ||
|
|
@@ -620,6 +627,95 @@ class DrawAreaTaskViewModelTest : BaseHiltTest() { | |
| assertThat(viewModel.isMarkedComplete()).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `checkVertexIntersection sets hasSelfIntersection and showSelfIntersectionDialog to true`() = | ||
| runWithTestDispatcher { | ||
| setupViewModel() | ||
|
|
||
| // Create a path: (0,0) -> (10,10) -> (0,10) | ||
| updateLastVertexAndAdd(COORDINATE_1) | ||
| updateLastVertexAndAdd(COORDINATE_2) | ||
| updateLastVertexAndAdd(COORDINATE_6) | ||
|
|
||
| // Move cursor to a point that crosses the first segment: (10,0) | ||
| updateLastVertex(COORDINATE_5) | ||
|
|
||
| // Trigger ADD_POINT which calls checkVertexIntersection | ||
| viewModel.onButtonClick(ButtonAction.ADD_POINT) | ||
| advanceUntilIdle() | ||
|
|
||
| assertThat(viewModel.hasSelfIntersection.value).isTrue() | ||
| assertThat(viewModel.showSelfIntersectionDialog.value).isTrue() | ||
| // offending vertex should be dropped | ||
| assertGeometry(4, isLineString = true) | ||
| } | ||
|
|
||
| @Test | ||
| fun `dismissSelfIntersectionDialog resets both flag and dialog visibility`() = | ||
| runWithTestDispatcher { | ||
| setupViewModel() | ||
|
|
||
| // Force an intersection state | ||
| updateLastVertexAndAdd(COORDINATE_1) | ||
| updateLastVertexAndAdd(COORDINATE_2) | ||
| updateLastVertexAndAdd(COORDINATE_6) | ||
| updateLastVertex(COORDINATE_5) | ||
| viewModel.onButtonClick(ButtonAction.ADD_POINT) | ||
| advanceUntilIdle() | ||
|
|
||
| viewModel.dismissSelfIntersectionDialog() | ||
| assertThat(viewModel.hasSelfIntersection.value).isFalse() | ||
| assertThat(viewModel.showSelfIntersectionDialog.value).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `taskActionButtonStates re-enables COMPLETE button after intersection is dismissed`() = | ||
| runTest(UnconfinedTestDispatcher()) { // Use Unconfined to trigger emissions immediately | ||
| setupViewModel() | ||
|
|
||
| viewModel.taskActionButtonStates.test { | ||
| // 1. Initial State: Create a closed non-intersecting square | ||
| updateLastVertexAndAdd(COORDINATE_1) | ||
| updateLastVertexAndAdd(COORDINATE_2) | ||
| updateLastVertexAndAdd(COORDINATE_3) | ||
| // Set state to be near first vertex to enable COMPLETE | ||
| updateLastVertex(COORDINATE_1, isNearFirstVertex = true) | ||
|
|
||
| // 2. Trigger Intersection Logic | ||
| // Clear state (Simulated) | ||
| while (viewModel.getLastVertex() != null) { | ||
| viewModel.removeLastVertex() | ||
| } | ||
|
|
||
| updateLastVertexAndAdd(COORDINATE_1) | ||
| updateLastVertexAndAdd(COORDINATE_2) | ||
| updateLastVertexAndAdd(COORDINATE_6) | ||
| updateLastVertexAndAdd(COORDINATE_5) | ||
| updateLastVertex(COORDINATE_1, isNearFirstVertex = true) | ||
|
|
||
| // Trigger validation | ||
| viewModel.onButtonClick(ButtonAction.COMPLETE) | ||
|
|
||
| // 3. Assert: Button should eventually become disabled due to intersection | ||
| // We look for the emission where COMPLETE is disabled | ||
| expectMostRecentItem().let { latestStates -> | ||
| val completeAction = latestStates.find { it.action == ButtonAction.COMPLETE } | ||
| assertThat(completeAction?.isEnabled).isFalse() | ||
| } | ||
|
|
||
| // 4. Act: Dismiss and Verify | ||
| viewModel.dismissSelfIntersectionDialog() | ||
|
|
||
| // 5. Assert: Button is enabled again | ||
| expectMostRecentItem().let { latestStates -> | ||
| val completeAction = latestStates.find { it.action == ButtonAction.COMPLETE } | ||
| assertThat(completeAction?.isEnabled).isTrue() | ||
| } | ||
|
|
||
| cancelAndIgnoreRemainingEvents() | ||
| } | ||
| } | ||
|
|
||
| private fun assertGeometry( | ||
| expectedVerticesCount: Int, | ||
| isLineString: Boolean = false, | ||
|
|
@@ -679,6 +775,8 @@ class DrawAreaTaskViewModelTest : BaseHiltTest() { | |
| private val COORDINATE_2 = Coordinates(10.0, 10.0) | ||
| private val COORDINATE_3 = Coordinates(20.0, 20.0) | ||
| private val COORDINATE_4 = Coordinates(30.0, 30.0) | ||
| private val COORDINATE_5 = Coordinates(10.0, 0.0) | ||
| private val COORDINATE_6 = Coordinates(0.0, 10.0) | ||
|
|
||
| private val TASK = | ||
| Task( | ||
|
|
@@ -690,4 +788,9 @@ class DrawAreaTaskViewModelTest : BaseHiltTest() { | |
| ) | ||
| private val JOB = Job("job", Style("#112233")) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| Dispatchers.resetMain() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only used inside the VM so it can be private