Skip to content
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

Added the test case -- when the route changes where the old route is … #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: android
sudo: required
jdk: oraclejdk8
jdk: openjdk8

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A declarative router for [ReKotlin](https://github.com/GeoThings/ReKotlin). Allows developers to declare routes in a similar manner as URLs are used on the web.

Using ReKotlinRouter you can navigate your app by defining the target location in the form of a URL-like sequence of identifiers:
Using ReKotlinRouter you can navigate your app by defining the target location in the form of a URL-like sequence of identifiers:-

```Kotlin
val routes = arrayListOf(loginRoute, repoListRoute, repoDetailRoute)
Expand Down Expand Up @@ -237,4 +237,4 @@ You can find all the details on how to get started in the [Contributing Guide](/
## Credits

- Many thanks to [Benjamin Encz](https://github.com/Ben-G) and other ReSwift contributors for buidling original [ReSwift](https://github.com/ReSwift/ReSwift) that we really enjoyed working with.
- Also huge thanks to [Dan Abramov](https://github.com/gaearon) for building [Redux](https://github.com/reactjs/redux) - all ideas in here and many implementation details were provided by his library.
- Also huge thanks to [Dan Abramov](https://github.com/gaearon) for building [Redux](https://github.com/reactjs/redux) - all ideas in here and many implementation details were provided by his library.
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
kapt.incremental.apt=true
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import org.junit.Test

internal class ReKotlinRouterUnitTests {

val mainActivityIdentifier = "MainActivity"
val counterActivityIdentifier = "CounterActivity"
val statsActivityIdentifier = "StatsActivity"
val infoActivityIdentifier = "InfoActivity"
private val mainActivityIdentifier = "MainActivity"
private val counterActivityIdentifier = "CounterActivity"
private val statsActivityIdentifier = "StatsActivity"
private val infoActivityIdentifier = "InfoActivity"

@Test
//@DisplayName("calculates transitions from an empty route to a multi segment route")
Expand Down Expand Up @@ -112,6 +112,44 @@ internal class ReKotlinRouterUnitTests {
assertThat(routingActions.count()).isEqualTo(2)
}

@Test
// @DisplayName("generates a Change action on the last common subroute, also for routes of different length, old route is longer than new route")
fun test_change_action_on_last_common_sub_route_plus_routes_of_different_length_old_route_is_longer_than_new_route() {

// Given
val oldRoute = arrayListOf(mainActivityIdentifier, statsActivityIdentifier, infoActivityIdentifier)
val newRoute = arrayListOf(mainActivityIdentifier, counterActivityIdentifier)

// When
val routingActions = Router.routingActionsForTransitionFrom(oldRoute, newRoute)

// Then
var action1Correct = false
var action2Correct = false

routingActions.forEach { routingAction ->
when (routingAction) {
is pop -> {
if (routingAction.responsibleRoutableIndex == 2 && routingAction.segmentToBePopped == infoActivityIdentifier) {
action1Correct = true
}

}
is change -> {
if (routingAction.responsibleRoutableIndex == 1
&& routingAction.segmentToBeReplaced == statsActivityIdentifier
&& routingAction.newSegment == counterActivityIdentifier) {
action2Correct = true
}
}
}
}

assertThat(action1Correct).isTrue()
assertThat(action2Correct).isTrue()
assertThat(routingActions.count()).isEqualTo(2)
}

@Test
// @DisplayName("generates a Change action on root when root element changes")
fun test_change_action_on_root_when_root_element_changes() {
Expand Down