-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to verify EnroTest rule clean up issues, and updated Enro…
…Test/ConfigureNavigationHandleForPlugins to solve the reported bug
- Loading branch information
Showing
11 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
23 changes: 23 additions & 0 deletions
23
...pplication/src/androidTest/java/dev/enro/test/application/activity/SimpleActivityRobot.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,23 @@ | ||
package dev.enro.test.application.activity | ||
|
||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.performClick | ||
import dev.enro.test.application.waitForNavigationHandle | ||
import dev.enro.tests.application.activity.SimpleActivity | ||
|
||
class SimpleActivityRobot( | ||
private val composeRule: ComposeTestRule | ||
) { | ||
|
||
init { | ||
composeRule.waitForNavigationHandle { | ||
it.key is SimpleActivity | ||
} | ||
} | ||
|
||
fun close() { | ||
composeRule.onNode(hasText("Close Activity")) | ||
.performClick() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ation/src/androidTest/java/dev/enro/test/application/ruleinterop/FirstTestWithEnroRule.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,28 @@ | ||
package dev.enro.test.application.ruleinterop | ||
|
||
import android.content.Intent | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import dev.enro.core.NavigationInstruction | ||
import dev.enro.core.addOpenInstruction | ||
import dev.enro.core.close | ||
import dev.enro.test.assertClosed | ||
import dev.enro.test.extensions.getTestNavigationHandle | ||
import dev.enro.test.runEnroTest | ||
import dev.enro.tests.application.activity.SimpleActivity | ||
import dev.enro.tests.application.activity.SimpleActivityImpl | ||
import org.junit.Test | ||
|
||
class FirstTestWithEnroRule { | ||
@Test | ||
fun test() = runEnroTest { | ||
val scenario = ActivityScenario.launch<SimpleActivityImpl>( | ||
Intent(ApplicationProvider.getApplicationContext(), SimpleActivityImpl::class.java) | ||
.addOpenInstruction(NavigationInstruction.Present(SimpleActivity)) | ||
) | ||
val navigationHandle = scenario.getTestNavigationHandle<SimpleActivity>() | ||
navigationHandle.close() | ||
navigationHandle.assertClosed() | ||
} | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
...on/src/androidTest/java/dev/enro/test/application/ruleinterop/FirstTestWithoutEnroRule.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,19 @@ | ||
package dev.enro.test.application.ruleinterop | ||
|
||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import dev.enro.test.application.SelectDestinationRobot | ||
import dev.enro.tests.application.TestActivity | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class FirstTestWithoutEnroRule() { | ||
@get:Rule | ||
val composeRule = createAndroidComposeRule<TestActivity>() | ||
|
||
@Test | ||
fun test() { | ||
SelectDestinationRobot(composeRule) | ||
.openSimpleActivity() | ||
.close() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...pplication/src/androidTest/java/dev/enro/test/application/ruleinterop/README.md
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,6 @@ | ||
# Rule Interop Tests | ||
`EnroTest` (`EnroTestRule` or `runEnroTest`) are designed for testing screens in isolation. When using `EnroTest` functionality in instrumented tests (i.e. those in `src/androidTest`), the NavigationController configures NavigationHandles so that they don't launch any NavigationInstructions, but instead record the NavigationInstructions that were executed against a NavigationHandle, which can be verified against expected state without performing the navigation action. When the test is finished, the `EnroTest` functionality will revert this behaviour. | ||
|
||
When running instrumented tests without using `EnroTest` functionality, navigation is expected to occur as normal. | ||
|
||
The tests in this package are designed to be ran as a package (not as individual tests). A bug was reported where packages that mix isolated single screen tests using `EnroTest` and tests that do not use `EnroTest` (i.e. tests that perform "real" navigation). This bug would cause the tests not using `EnroTest` to fail, due to the clean up process of `EnroTest` being overeager and clearing NavigationBindings that should not have been cleared and needed to be accessed by the tests. Running the tests in this package together as a whole verifies that this bug is no longer present. |
27 changes: 27 additions & 0 deletions
27
...tion/src/androidTest/java/dev/enro/test/application/ruleinterop/SecondTestWithEnroRule.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,27 @@ | ||
package dev.enro.test.application.ruleinterop | ||
|
||
import android.content.Intent | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import dev.enro.core.NavigationInstruction | ||
import dev.enro.core.addOpenInstruction | ||
import dev.enro.core.close | ||
import dev.enro.test.assertClosed | ||
import dev.enro.test.extensions.getTestNavigationHandle | ||
import dev.enro.test.runEnroTest | ||
import dev.enro.tests.application.activity.SimpleActivity | ||
import dev.enro.tests.application.activity.SimpleActivityImpl | ||
import org.junit.Test | ||
|
||
class SecondTestWithEnroRule { | ||
@Test | ||
fun test() = runEnroTest { | ||
val scenario = ActivityScenario.launch<SimpleActivityImpl>( | ||
Intent(ApplicationProvider.getApplicationContext(), SimpleActivityImpl::class.java) | ||
.addOpenInstruction(NavigationInstruction.Present(SimpleActivity)) | ||
) | ||
val navigationHandle = scenario.getTestNavigationHandle<SimpleActivity>() | ||
navigationHandle.close() | ||
navigationHandle.assertClosed() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/src/androidTest/java/dev/enro/test/application/ruleinterop/SecondTestWithoutEnroRule.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,19 @@ | ||
package dev.enro.test.application.ruleinterop | ||
|
||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import dev.enro.test.application.SelectDestinationRobot | ||
import dev.enro.tests.application.TestActivity | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class SecondTestWithoutEnroRule() { | ||
@get:Rule | ||
val composeRule = createAndroidComposeRule<TestActivity>() | ||
|
||
@Test | ||
fun test() { | ||
SelectDestinationRobot(composeRule) | ||
.openSimpleActivity() | ||
.close() | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
tests/application/src/main/java/dev/enro/tests/application/activity/SimpleActivity.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,33 @@ | ||
package dev.enro.tests.application.activity | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Text | ||
import dev.enro.annotations.NavigationDestination | ||
import dev.enro.core.NavigationKey | ||
import dev.enro.core.navigationHandle | ||
import dev.enro.core.requestClose | ||
import dev.enro.tests.application.compose.common.TitledColumn | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
object SimpleActivity : NavigationKey.SupportsPresent | ||
|
||
@NavigationDestination(SimpleActivity::class) | ||
class SimpleActivityImpl : ComponentActivity() { | ||
|
||
private val navigation by navigationHandle<NavigationKey>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
TitledColumn(title = "Simple Activity") { | ||
Button(onClick = { navigation.requestClose() }) { | ||
Text(text = "Close Activity") | ||
} | ||
} | ||
} | ||
} | ||
} |