Skip to content

Commit

Permalink
Merge pull request #92 from bumble-tech/spotlight-crash
Browse files Browse the repository at this point in the history
Spotlight Next and Previous operations crash fix.
  • Loading branch information
Andrey authored Aug 19, 2022
2 parents 00d2e04 + 3d5f808 commit 106a05e
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Pending changes

- [#83](https://github.com/bumble-tech/appyx/issues/83)**Breaking change**: `RoutingSource` renamed to `NavModel`. All subclasses, fields, package names, etc., any mentions of the word follow suit.

- [#91](https://github.com/bumble-tech/appyx/pull/91)**Fixed**: Spotlight next and previous operations crash fix

## 1.0-alpha04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.parcelize.Parcelize
class Next<T : Any> : SpotlightOperation<T> {

override fun isApplicable(elements: RoutingElements<T, TransitionState>) =
elements.any { it.fromState == INACTIVE_AFTER }
elements.any { it.fromState == INACTIVE_AFTER && it.targetState == INACTIVE_AFTER }

override fun invoke(elements: RoutingElements<T, TransitionState>): RoutingElements<T, TransitionState> {
val nextKey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.parcelize.Parcelize
class Previous<T : Any> : SpotlightOperation<T> {

override fun isApplicable(elements: RoutingElements<T, Spotlight.TransitionState>) =
elements.any { it.fromState == INACTIVE_BEFORE }
elements.any { it.fromState == INACTIVE_BEFORE && it.targetState == INACTIVE_BEFORE }

override fun invoke(
elements: RoutingElements<T, Spotlight.TransitionState>
Expand Down
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
)
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)
}

}
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)
}

}
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()
}

0 comments on commit 106a05e

Please sign in to comment.