-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix PermanentChild behaviour in test environment #268
Merged
CherryPerry
merged 3 commits into
bumble-tech:1.x
from
CherryPerry:permanent-child-test-fix
Nov 8, 2022
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
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
77 changes: 77 additions & 0 deletions
77
libraries/core/src/androidTest/kotlin/com/bumble/appyx/core/node/PermanentChildTest.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,77 @@ | ||
package com.bumble.appyx.core.node | ||
|
||
import android.os.Parcelable | ||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.test.hasTestTag | ||
import com.bumble.appyx.core.AppyxTestScenario | ||
import com.bumble.appyx.core.children.nodeOrNull | ||
import com.bumble.appyx.core.modality.BuildContext | ||
import com.bumble.appyx.core.navigation.EmptyNavModel | ||
import kotlinx.parcelize.Parcelize | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class PermanentChildTest { | ||
|
||
@get:Rule | ||
val rule = AppyxTestScenario { buildContext -> | ||
TestParentNode(buildContext) | ||
} | ||
|
||
@Test | ||
fun permanent_child_is_rendered() { | ||
rule.start() | ||
|
||
rule.onNode(hasTestTag(TestParentNode.NavTarget::class.java.name)).assertExists() | ||
} | ||
|
||
@Test | ||
fun permanent_child_is_reused_when_visibility_switched() { | ||
rule.start() | ||
rule.node.renderPermanentChild = false | ||
val childNodes = rule.node.children.value.values.map { it.nodeOrNull } | ||
|
||
rule.onNode(hasTestTag(TestParentNode.NavTarget::class.java.name)).assertDoesNotExist() | ||
|
||
rule.node.renderPermanentChild = true | ||
|
||
rule.onNode(hasTestTag(TestParentNode.NavTarget::class.java.name)).assertExists() | ||
assertEquals(childNodes, rule.node.children.value.values.map { it.nodeOrNull }) | ||
} | ||
|
||
class TestParentNode( | ||
buildContext: BuildContext, | ||
) : ParentNode<TestParentNode.NavTarget>( | ||
buildContext = buildContext, | ||
navModel = EmptyNavModel<NavTarget, Any>(), | ||
) { | ||
|
||
@Parcelize | ||
object NavTarget : Parcelable | ||
|
||
var renderPermanentChild by mutableStateOf(true) | ||
|
||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node = | ||
node(buildContext) { modifier -> | ||
BasicText( | ||
text = navTarget.toString(), | ||
modifier = modifier.testTag(NavTarget::class.java.name), | ||
) | ||
} | ||
|
||
@Composable | ||
override fun View(modifier: Modifier) { | ||
if (renderPermanentChild) { | ||
PermanentChild(NavTarget) | ||
} | ||
} | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
...e/src/main/kotlin/com/bumble/appyx/core/navigation/model/permanent/operation/AddUnique.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,35 @@ | ||
package com.bumble.appyx.core.navigation.model.permanent.operation | ||
|
||
import com.bumble.appyx.core.navigation.NavElement | ||
import com.bumble.appyx.core.navigation.NavElements | ||
import com.bumble.appyx.core.navigation.NavKey | ||
import com.bumble.appyx.core.navigation.model.permanent.PermanentNavModel | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.parcelize.RawValue | ||
|
||
@Parcelize | ||
data class AddUnique<NavTarget : Any>( | ||
private val navTarget: @RawValue NavTarget, | ||
) : PermanentOperation<NavTarget> { | ||
|
||
override fun isApplicable(elements: NavElements<NavTarget, Int>): Boolean = | ||
!elements.any { it.key.navTarget == navTarget } | ||
|
||
override fun invoke( | ||
elements: NavElements<NavTarget, Int> | ||
): NavElements<NavTarget, Int> = | ||
if (elements.any { it.key.navTarget == navTarget }) { | ||
elements | ||
} else { | ||
elements + NavElement( | ||
key = NavKey(navTarget), | ||
fromState = 0, | ||
targetState = 0, | ||
operation = this, | ||
) | ||
} | ||
} | ||
|
||
fun <NavTarget : Any> PermanentNavModel<NavTarget>.addUnique(navTarget: NavTarget) { | ||
accept(AddUnique(navTarget)) | ||
} |
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
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.
Is this expected to be called by library users? otherwise internal? if it should be public, add some Javadoc? Maybe add some either way?
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.
I think it is more useful than regular
Add
.