-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from agstack/feature/tests
Feature/tests
- Loading branch information
Showing
121 changed files
with
8,639 additions
and
3,958 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
49 changes: 49 additions & 0 deletions
49
...c/androidTest/java/org/technoserve/farmcollector/ui/components/KeepPolygonDialogKtTest.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.technoserve.farmcollector.ui.components | ||
|
||
import org.junit.Assert.* | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
class FakeMapViewModel : ViewModel() { | ||
var coordinatesCleared = false | ||
|
||
fun clearCoordinates() { | ||
coordinatesCleared = true | ||
} | ||
} | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class KeepPolygonDialogIntegrationTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testKeepPolygonDialogClearsCoordinatesAndCapturesNew() { | ||
val fakeViewModel = FakeMapViewModel() | ||
|
||
composeTestRule.setContent { | ||
KeepPolygonDialog( | ||
onDismiss = {}, | ||
onKeepExisting = {}, | ||
onCaptureNew = { | ||
fakeViewModel.clearCoordinates() | ||
} | ||
) | ||
} | ||
|
||
// Click the "Capture New" button | ||
composeTestRule.onNodeWithText("Capture New").performClick() | ||
|
||
// Assert that coordinates were cleared | ||
assert(fakeViewModel.coordinatesCleared) | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
app/src/androidTest/java/org/technoserve/farmcollector/ui/composes/AreaDialogKtTest.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.technoserve.farmcollector.ui.composes | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Assert.* | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@HiltAndroidTest | ||
@RunWith(AndroidJUnit4::class) | ||
class AreaDialogTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val calculatedArea = 123.456789 | ||
private val enteredArea = 100.0 | ||
private val threshold = enteredArea * 0.30 | ||
|
||
@Test | ||
fun dialogDisplaysCorrectTextAndButtons() { | ||
composeTestRule.setContent { | ||
AreaDialog( | ||
showDialog = true, | ||
onDismiss = {}, | ||
onConfirm = {}, | ||
calculatedArea = calculatedArea, | ||
enteredArea = enteredArea | ||
) | ||
} | ||
|
||
// Check dialog title | ||
composeTestRule.onNodeWithText("Choose Area") // Replace with localized string if using resources | ||
.assertExists() | ||
|
||
// Check warning message visibility | ||
val difference = Math.abs(calculatedArea - enteredArea) | ||
if (difference > threshold) { | ||
composeTestRule.onNodeWithText("Warning: Difference is $difference") // Replace with localized string | ||
.assertExists() | ||
} else { | ||
composeTestRule.onNodeWithText("Warning: Difference is $difference") // Replace with localized string | ||
.assertDoesNotExist() | ||
} | ||
|
||
// Verify buttons | ||
composeTestRule.onNodeWithText("Cancel") // Replace with localized string | ||
.assertExists() | ||
|
||
composeTestRule.onNodeWithText("Calculated Area: 123.456789") // Replace with localized string | ||
.assertExists() | ||
|
||
composeTestRule.onNodeWithText("Entered Area: 100.00") // Replace with localized string | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun confirmButtonCallsOnConfirmWithCalculatedAreaOption() { | ||
var confirmedOption: String? = null | ||
|
||
composeTestRule.setContent { | ||
AreaDialog( | ||
showDialog = true, | ||
onDismiss = {}, | ||
onConfirm = { confirmedOption = it }, | ||
calculatedArea = calculatedArea, | ||
enteredArea = enteredArea | ||
) | ||
} | ||
|
||
// Click the calculated area button | ||
composeTestRule.onNodeWithText("Calculated Area: 123.456789") // Replace with localized string | ||
.performClick() | ||
|
||
// Verify the onConfirm callback was called with the correct option | ||
assertEquals(CALCULATED_AREA_OPTION, confirmedOption) | ||
} | ||
|
||
@Test | ||
fun dismissButtonCallsOnDismiss() { | ||
var dismissed = false | ||
|
||
composeTestRule.setContent { | ||
AreaDialog( | ||
showDialog = true, | ||
onDismiss = { dismissed = true }, | ||
onConfirm = {}, | ||
calculatedArea = calculatedArea, | ||
enteredArea = enteredArea | ||
) | ||
} | ||
|
||
// Click the dismiss button | ||
composeTestRule.onNodeWithText("Cancel") // Replace with localized string | ||
.performClick() | ||
|
||
// Verify the onDismiss callback was called | ||
assertTrue(dismissed) | ||
} | ||
} |
Oops, something went wrong.