-
Notifications
You must be signed in to change notification settings - Fork 61
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 #92 from bumble-tech/spotlight-crash
Spotlight Next and Previous operations crash fix.
- Loading branch information
Showing
7 changed files
with
137 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
core/src/test/java/com/bumble/appyx/navmodel/spotlight/SpotlightTestHelper.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 com.bumble.appyx.navmodel.spotlight | ||
|
||
import com.bumble.appyx.core.navigation.Operation | ||
import com.bumble.appyx.core.navigation.RoutingKey | ||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState | ||
import com.bumble.appyx.navmodel.spotlight.operation.Routing | ||
|
||
internal fun <T : Routing> spotlightElement( | ||
element: T, | ||
key: RoutingKey<T> = RoutingKey(routing = element), | ||
fromState: TransitionState, | ||
targetState: TransitionState, | ||
operation: Operation<T, TransitionState> = Operation.Noop() | ||
) = SpotlightElement( | ||
key = key, | ||
fromState = fromState, | ||
targetState = targetState, | ||
operation = operation | ||
) |
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/bumble/appyx/navmodel/spotlight/operation/NextTest.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,54 @@ | ||
package com.bumble.appyx.navmodel.spotlight.operation | ||
|
||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.ACTIVE | ||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.INACTIVE_AFTER | ||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.INACTIVE_BEFORE | ||
import com.bumble.appyx.navmodel.spotlight.operation.Routing.Routing1 | ||
import com.bumble.appyx.navmodel.spotlight.spotlightElement | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
internal class NextTest { | ||
|
||
@Test | ||
fun `Given last element is in transition When next called Then operation is not applicable`() { | ||
val firstElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = INACTIVE_AFTER, | ||
targetState = INACTIVE_BEFORE, | ||
) | ||
val lastElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = INACTIVE_AFTER, | ||
targetState = ACTIVE, | ||
) | ||
val elements = listOf(firstElement, lastElement) | ||
val operation = Next<Routing>() | ||
|
||
val applicable = operation.isApplicable(elements) | ||
|
||
assertFalse(applicable) | ||
} | ||
|
||
@Test | ||
fun `Given last element is not in transition When next called Then operation is applicable`() { | ||
val firstElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = ACTIVE, | ||
targetState = ACTIVE, | ||
) | ||
val lastElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = INACTIVE_AFTER, | ||
targetState = INACTIVE_AFTER, | ||
) | ||
val elements = listOf(firstElement, lastElement) | ||
val operation = Next<Routing>() | ||
|
||
val applicable = operation.isApplicable(elements) | ||
|
||
assertTrue(applicable) | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/bumble/appyx/navmodel/spotlight/operation/PreviousTest.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,54 @@ | ||
package com.bumble.appyx.navmodel.spotlight.operation | ||
|
||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.ACTIVE | ||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.INACTIVE_AFTER | ||
import com.bumble.appyx.navmodel.spotlight.Spotlight.TransitionState.INACTIVE_BEFORE | ||
import com.bumble.appyx.navmodel.spotlight.operation.Routing.Routing1 | ||
import com.bumble.appyx.navmodel.spotlight.spotlightElement | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
internal class PreviousTest { | ||
|
||
@Test | ||
fun `Given first element is in transition When previous called Then operation is not applicable`() { | ||
val firstElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = INACTIVE_AFTER, | ||
targetState = INACTIVE_BEFORE, | ||
) | ||
val lastElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = ACTIVE, | ||
targetState = INACTIVE_BEFORE, | ||
) | ||
val elements = listOf(firstElement, lastElement) | ||
val operation = Previous<Routing>() | ||
|
||
val applicable = operation.isApplicable(elements) | ||
|
||
assertFalse(applicable) | ||
} | ||
|
||
@Test | ||
fun `Given first element is not in transition When previous called Then operation is applicable`() { | ||
val firstElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = ACTIVE, | ||
targetState = ACTIVE, | ||
) | ||
val lastElement = spotlightElement<Routing>( | ||
element = Routing1, | ||
fromState = INACTIVE_BEFORE, | ||
targetState = INACTIVE_BEFORE, | ||
) | ||
val elements = listOf(firstElement, lastElement) | ||
val operation = Previous<Routing>() | ||
|
||
val applicable = operation.isApplicable(elements) | ||
|
||
assertTrue(applicable) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
core/src/test/java/com/bumble/appyx/navmodel/spotlight/operation/Routing.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,7 @@ | ||
package com.bumble.appyx.navmodel.spotlight.operation | ||
|
||
internal sealed class Routing { | ||
object Routing1 : Routing() | ||
object Routing2 : Routing() | ||
object Routing3 : Routing() | ||
} |