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

Migrate to Jetpack Compose (WIP) #97

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
compose test POC
  • Loading branch information
ErickSumargo committed Nov 10, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit fdb730319abfd2763c7889cc0577881df7a159e6
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.bael.dads.feature.home.screen.home

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.test.onNodeWithText
import androidx.navigation.NavGraphBuilder
import com.bael.dads.feature.home.navigation.homeNavigation
import com.bael.dads.library.instrumentation.screen.BaseScreenTest
import com.google.accompanist.pager.ExperimentalPagerApi
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test

/**
* Created by ErickSumargo on 01/11/21.
*/

@ExperimentalAnimationApi
@ExperimentalFoundationApi
@ExperimentalPagerApi
@HiltAndroidTest
internal class ScreenTest : BaseScreenTest(destination = "home") {
override val NavGraphBuilder.navigation
get() = homeNavigation(sheetContent = {})

override val route: String = "/"

@Test
fun test() {
test(
onSetup = {},
onRun = { _, rule ->
rule.onNodeWithText(text = "Feed")
}
)
}
}
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ import com.google.accompanist.pager.ExperimentalPagerApi
@ExperimentalFoundationApi
@ExperimentalPagerApi
fun NavGraphBuilder.homeNavigation(sheetContent: (@Composable () -> Unit) -> Unit) {
navigation(startDestination = "main", route = "home") {
composable(route = "main") {
navigation(startDestination = "/", route = "home") {
composable(route = "/") {
HomeRoute(sheetContent)
}
}
16 changes: 16 additions & 0 deletions android/library/instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import Library.AndroidX.appCompat
import Library.AndroidX.archTesting
import Library.AndroidX.composeUiTest
import Library.AndroidX.navigationCompose
import Library.AndroidX.runner
import Library.AndroidX.uiAutomator
import Library.AndroidX.workTesting
import Library.Google.daggerTesting
import Library.Google.truth
import Library.KotlinX.coroutinesTest
import Version.AndroidX.compose as composeVersion

plugins {
id("androidLibrary")
}

android {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = composeVersion
}
}

dependencies {
// AndroidX
implementation(appCompat)
implementation(archTesting)
implementation(navigationCompose)
implementation(composeUiTest)
implementation(runner)
implementation(uiAutomator)
implementation(workTesting)
@@ -29,6 +44,7 @@ dependencies {

dependencies {
// Library
implementation(project(":android:library:presentation"))
implementation(project(":android:library:threading"))
implementation(project(":android:library:worker"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.bael.dads.library.instrumentation.screen

import android.content.Context
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import com.bael.dads.library.instrumentation.activity.MainTestActivity
import dagger.hilt.android.testing.HiltAndroidRule
import org.junit.Before
import org.junit.Rule

/**
* Created by ErickSumargo on 01/11/21.
*/

abstract class BaseScreenTest(private val destination: String) {
@get:Rule(order = 1)
internal val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 2)
val composeRule = createAndroidComposeRule<MainTestActivity>()

abstract val NavGraphBuilder.navigation: Unit

abstract val route: String

@Before
internal fun setup() {
hiltRule.inject()
}

protected fun test(
onSetup: () -> Unit = {},
onRun: (Context, ComposeTestRule) -> Unit
) {
onSetup()

composeRule.setContent {
NavHost(
navController = rememberNavController(),
startDestination = destination,
route = route,
builder = { navigation }
)
}

onRun(composeRule.activity, composeRule)
}
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ package com.bael.dads.library.preference.test

import com.bael.dads.library.preference.Preference
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
@@ -14,7 +15,7 @@ internal class FakePreference @Inject constructor() : Preference {
private val container: MutableMap<String, Any> = HashMap()

override fun <T> read(key: String, defaultValue: T): Flow<T> {
return container[key] as T ?: defaultValue
return flow { }
}

override suspend fun <T> write(key: String, value: T) {
3 changes: 3 additions & 0 deletions buildSrc/buildSrc/src/main/kotlin/Library.kt
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ object Library {
val composeMaterial: String
get() = "androidx.compose.material:material:$composeVersion"

val composeUiTest: String
get() = "androidx.compose.ui:ui-test-junit4:$composeVersion"

val composeUiTooling: String
get() = "androidx.compose.ui:ui-tooling:$composeVersion"

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ package plugin.android

import Application
import Library.AndroidX.composeMaterial
import Library.AndroidX.composeUiTest
import Library.AndroidX.composeUiTooling
import Library.AndroidX.hiltCompiler
import Library.AndroidX.hiltNavigationCompose
@@ -15,7 +16,6 @@ import Library.Google.daggerCompiler
import Library.Google.daggerTesting
import Library.Google.truth
import com.android.build.gradle.LibraryExtension
import dagger.hilt.android.plugin.HiltExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
@@ -138,6 +138,8 @@ class FeatureModulePlugin : Plugin<Project> {
add("implementation", lifecycle)
add("implementation", navigationCompose)

add("androidTestImplementation", composeUiTest)

// Google
add("implementation", dagger)
add("androidTestImplementation", daggerTesting)