-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'CORE/refactor/add-compose-tests' into 'main'
add compose routing tests See merge request veepee/offerdiscovery/products/front-mobile/android/link-router!16
- Loading branch information
Showing
14 changed files
with
296 additions
and
6 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
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
113 changes: 113 additions & 0 deletions
113
library/src/test/java/com/veepee/vpcore/route/composable/ComposableLinkRouterTest.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,113 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.veepee.vpcore.route.composable.feature.TestComposablesNameMapper | ||
import com.veepee.vpcore.route.composable.route.TestComposableALink | ||
import com.veepee.vpcore.route.composable.route.TestComposableBLink | ||
import com.veepee.vpcore.route.composable.route.TestComposableBParameter | ||
import com.veepee.vpcore.route.link.compose.ComposableLink | ||
import com.veepee.vpcore.route.link.compose.ComposableLinkRouterImpl | ||
import com.veepee.vpcore.route.link.compose.ComposableName | ||
import com.veepee.vpcore.route.link.compose.ComposableNameMapper | ||
import com.veepee.vpcore.route.link.compose.NoComposableNameMapperException | ||
import com.veepee.vpcore.route.link.compose.chain.ComposableLinkInterceptor | ||
import com.veepee.vpcore.route.link.interceptor.Chain | ||
import com.veepee.vpcore.route.link.interceptor.ChainFactoryImpl | ||
import org.junit.Assert | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config( | ||
instrumentedPackages = ["androidx.loader.content"] | ||
) | ||
class ComposableLinkRouterTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
private val mappers: Set<ComposableNameMapper<out ComposableName>> = | ||
setOf(TestComposablesNameMapper) | ||
|
||
@Test | ||
fun `should fail to route due to missing composable name mapper`() { | ||
val router = ComposableLinkRouterImpl(emptySet(), ChainFactoryImpl(emptyList())) | ||
Assert.assertThrows(NoComposableNameMapperException::class.java) { | ||
composeTestRule.setContent { | ||
router.ComposeFor(TestComposableALink()) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `should route and display text within composable`() { | ||
val router = ComposableLinkRouterImpl(mappers, ChainFactoryImpl(emptyList())) | ||
|
||
composeTestRule.setContent { | ||
router.ComposeFor(TestComposableALink()) | ||
} | ||
|
||
composeTestRule | ||
.onNodeWithText("Hello World") | ||
.assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun `should route and display text given to composable`() { | ||
val router = ComposableLinkRouterImpl(mappers, ChainFactoryImpl(emptyList())) | ||
|
||
composeTestRule.setContent { | ||
router.ComposeFor(TestComposableBLink(TestComposableBParameter("message"))) | ||
} | ||
|
||
composeTestRule | ||
.onNodeWithText("message") | ||
.assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun `should intercept route and display other composable`() { | ||
val router = ComposableLinkRouterImpl( | ||
mappers, | ||
ChainFactoryImpl(listOf(object : ComposableLinkInterceptor { | ||
override fun intercept( | ||
chain: Chain<ComposableNameMapper<out ComposableName>, ComposableLink<ComposableName>>, | ||
mapper: ComposableNameMapper<out ComposableName>, | ||
link: ComposableLink<ComposableName> | ||
): ComposableLink<ComposableName> { | ||
if (link is TestComposableBLink) { | ||
return TestComposableALink() | ||
} | ||
return chain.next(mapper, link) | ||
} | ||
})) | ||
) | ||
|
||
composeTestRule.setContent { | ||
router.ComposeFor(TestComposableBLink(TestComposableBParameter("message"))) | ||
} | ||
|
||
composeTestRule | ||
.onNodeWithText("Hello World") | ||
.assertIsDisplayed() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
library/src/test/java/com/veepee/vpcore/route/composable/feature/TestComposableA.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,25 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.feature | ||
|
||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun TestComposableA(modifier: Modifier) { | ||
BasicText(text = "Hello World", modifier) | ||
} |
25 changes: 25 additions & 0 deletions
25
library/src/test/java/com/veepee/vpcore/route/composable/feature/TestComposableB.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,25 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.feature | ||
|
||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun TestComposableB(message: String, modifier: Modifier) { | ||
BasicText(text = message, modifier) | ||
} |
39 changes: 39 additions & 0 deletions
39
...ary/src/test/java/com/veepee/vpcore/route/composable/feature/TestComposablesNameMapper.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,39 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.feature | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.veepee.vpcore.route.composable.route.TestComposableALink | ||
import com.veepee.vpcore.route.composable.route.TestComposableBLink | ||
import com.veepee.vpcore.route.composable.route.TestComposableName | ||
import com.veepee.vpcore.route.link.compose.ComposableLink | ||
import com.veepee.vpcore.route.link.compose.ComposableNameMapper | ||
|
||
object TestComposablesNameMapper : ComposableNameMapper<TestComposableName> { | ||
override val supportedNames: Array<TestComposableName> = TestComposableName.values() | ||
|
||
@Composable | ||
override fun Map(composableLink: ComposableLink<TestComposableName>, modifier: Modifier) { | ||
when (composableLink) { | ||
is TestComposableALink -> TestComposableA(modifier = modifier) | ||
is TestComposableBLink -> TestComposableB( | ||
composableLink.parameter.message, | ||
modifier = modifier | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
library/src/test/java/com/veepee/vpcore/route/composable/route/TestComposableALink.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,24 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.route | ||
|
||
import com.veepee.vpcore.route.link.compose.ComposableLink | ||
import com.veepee.vpcore.route.link.compose.ComposableParameter | ||
|
||
class TestComposableALink : ComposableLink<TestComposableName> { | ||
override val composableName: TestComposableName = TestComposableName.TestComposableA | ||
override val parameter: ComposableParameter? = null | ||
} |
27 changes: 27 additions & 0 deletions
27
library/src/test/java/com/veepee/vpcore/route/composable/route/TestComposableBLink.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 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.route | ||
|
||
import com.veepee.vpcore.route.link.compose.ComposableLink | ||
import com.veepee.vpcore.route.link.compose.ComposableParameter | ||
|
||
class TestComposableBLink( | ||
override val parameter: TestComposableBParameter | ||
) : ComposableLink<TestComposableName> { | ||
override val composableName: TestComposableName = TestComposableName.TestComposableB | ||
} | ||
|
||
data class TestComposableBParameter(val message: String) : ComposableParameter |
23 changes: 23 additions & 0 deletions
23
library/src/test/java/com/veepee/vpcore/route/composable/route/TestComposableName.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 @@ | ||
/** | ||
* Copyright (c) 2021, Veepee | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose | ||
* with or without fee is hereby granted, provided that the above copyright notice | ||
* and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
* THIS SOFTWARE. | ||
*/ | ||
package com.veepee.vpcore.route.composable.route | ||
|
||
import com.veepee.vpcore.route.link.compose.ComposableName | ||
|
||
enum class TestComposableName : ComposableName { | ||
TestComposableA, | ||
TestComposableB, | ||
} |
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