Skip to content

Commit

Permalink
Initial test setup for course
Browse files Browse the repository at this point in the history
  • Loading branch information
philipplackner committed Jul 29, 2023
1 parent fdd1b84 commit 2a3f657
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ dependencies {
implementation(project(":android:notifications"))
implementation(project(":core:exchange-provider"))
implementation(project(":core:domain"))
implementation(project(":core:persistence"))
implementation(project(":debug"))
implementation(project(":onboarding"))
implementation(project(":android:common"))
Expand All @@ -177,6 +178,9 @@ dependencies {

Networking(api = false)
Testing()
AndroidXTest()
Coroutines(api = false)
AssertK()

DataStore(api = false)

Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/com/ivy/buildsrc/IvyComposePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ abstract class IvyComposePlugin : IvyPlugin() {
override fun apply(project: Project) {
super.apply(project)

project.dependencies.add(
"debugImplementation",
"androidx.compose.ui:ui-test-manifest:${Versions.composeTestingManifest}"
)

val library = project.androidLibrary()
library.composeOptions {
kotlinCompilerExtensionVersion = Versions.composeCompilerVersion
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/com/ivy/buildsrc/IvyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class IvyPlugin : Plugin<Project> {
// }
// }

private fun test(project: Project) {
protected open fun test(project: Project) {
project.dependencies {
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.junitJupiter}")
Expand Down
18 changes: 18 additions & 0 deletions buildSrc/src/main/java/com/ivy/buildsrc/IvyTestPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ivy.buildsrc

import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

class IvyTestPlugin: IvyPlugin() {

override fun test(project: Project) {
project.dependencies {
implementation("org.junit.jupiter:junit-jupiter-api:${Versions.junitJupiter}")
implementation("org.junit.jupiter:junit-jupiter-params:${Versions.junitJupiter}")
implementation("com.willowtreeapps.assertk:assertk:${Versions.assertK}")
implementation("io.mockk:mockk:${Versions.mockk}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
implementation("app.cash.turbine:turbine:${Versions.turbine}")
}
}
}
6 changes: 4 additions & 2 deletions buildSrc/src/main/java/com/ivy/buildsrc/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object Versions {
// region Compose
//https://developer.android.com/jetpack/androidx/releases/compose
const val compose = "1.3.2"
const val composeTestingManifest = "1.3.0"

//https://developer.android.com/jetpack/androidx/releases/compose-material
const val composeMaterial = "1.3.1"
Expand Down Expand Up @@ -158,9 +159,9 @@ object Versions {

// region AndroidX Test
//https://developer.android.com/jetpack/androidx/releases/test
const val testCore = "1.4.0"
const val testCore = "1.3.0"
const val testJunitExt = "1.1.3"
const val testRunner = "1.4.0"
const val testRunner = "1.3.0"

// AssertK
const val assertK = "0.26.1"
Expand Down Expand Up @@ -496,6 +497,7 @@ fun DependencyHandler.JUnit5() {

fun DependencyHandler.AssertK() {
testImplementation("com.willowtreeapps.assertk:assertk:${Versions.assertK}")
androidTestImplementation("com.willowtreeapps.assertk:assertk:${Versions.assertK}")
}

fun DependencyHandler.MockK() {
Expand Down
3 changes: 2 additions & 1 deletion common/test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ plugins {
id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()
apply<com.ivy.buildsrc.IvyTestPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
implementation(project(":core:domain"))
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${com.ivy.buildsrc.Versions.junitJupiter}")
Testing(
// Prevent circular dependency
Expand Down
2 changes: 2 additions & 0 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.ivy.buildsrc.ComposeTesting
import com.ivy.buildsrc.Coroutines
import com.ivy.buildsrc.FunctionalProgramming
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Lifecycle
Expand All @@ -23,6 +24,7 @@ dependencies {
Lifecycle(api = false)
ComposeTesting(api = false) // for IdlingResource
Testing()
Coroutines(api = false)
}
android {
namespace = "com.ivy.core.domain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.ivy.core.domain.pure.mapping.entity.mapToTrnTagEntity
import com.ivy.core.domain.pure.transaction.validateTransaction
import com.ivy.core.domain.pure.util.beautify
import com.ivy.core.persistence.IvyWalletCoreDb
import com.ivy.core.persistence.algorithm.accountcache.AccountCacheDao
import com.ivy.core.persistence.dao.trn.SaveTrnData
import com.ivy.core.persistence.dao.trn.TransactionDao
import com.ivy.core.persistence.entity.trn.TrnMetadataEntity
Expand Down Expand Up @@ -49,7 +50,7 @@ class WriteTrnsAct @Inject constructor(
private val trnsSignal: TrnsSignal,
private val timeProvider: TimeProvider,
private val invalidateAccCacheAct: InvalidateAccCacheAct,
private val db: IvyWalletCoreDb,
private val accountCacheDao: AccountCacheDao,
) : Action<WriteTrnsAct.Input, Unit>() {

sealed interface Input {
Expand Down Expand Up @@ -199,7 +200,7 @@ class WriteTrnsAct @Inject constructor(
)

// Invalidate all account's cache
db.accountCacheDao().deleteAll()
accountCacheDao.deleteAll()
}
// endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.ivy.common.time.provider.TimeProvider
import com.ivy.common.time.toUtc
import com.ivy.core.domain.action.Action
import com.ivy.core.persistence.IvyWalletCoreDb
import com.ivy.core.persistence.algorithm.accountcache.AccountCacheDao
import com.ivy.data.transaction.TrnTime
import java.time.Instant
import javax.inject.Inject
Expand All @@ -14,7 +15,7 @@ import javax.inject.Inject
* https://github.com/Ivy-Apps/ivy-wallet/blob/develop/docs/algorithms/Account-Cache%20Algo.md
*/
class InvalidateAccCacheAct @Inject constructor(
private val db: IvyWalletCoreDb,
private val accountCacheDao: AccountCacheDao,
private val timeProvider: TimeProvider,
) : Action<InvalidateAccCacheAct.Input, Unit>() {
sealed interface Input {
Expand Down Expand Up @@ -58,7 +59,7 @@ class InvalidateAccCacheAct @Inject constructor(
}

private suspend fun ensureCacheConsistency(accountId: String, input: Input) {
val cacheTime = db.accountCacheDao().findTimestampById(accountId)
val cacheTime = accountCacheDao.findTimestampById(accountId)
if (cacheTime != null) {
val (oldTime, time) = when (input) {
is Input.OnCreateTrn -> null to input.time
Expand Down Expand Up @@ -100,6 +101,6 @@ class InvalidateAccCacheAct @Inject constructor(
}

private suspend fun invalidateCache(accountId: String) {
db.accountCacheDao().delete(accountId)
accountCacheDao.delete(accountId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = "ivy_wallet_datastore"
)

@Singleton
class IvyDataStore @Inject constructor(
@ApplicationContext private val appContext: Context
) {
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = "ivy_wallet_datastore"
)

suspend fun <T> put(
key: Preferences.Key<T>,
value: T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ivy.core.persistence.di

import android.content.Context
import com.ivy.core.persistence.IvyWalletCoreDb
import com.ivy.core.persistence.algorithm.accountcache.AccountCacheDao
import com.ivy.core.persistence.algorithm.calc.RatesDao
import com.ivy.core.persistence.dao.AttachmentDao
import com.ivy.core.persistence.dao.account.AccountDao
Expand Down Expand Up @@ -34,6 +35,10 @@ object CorePersistenceModuleDI {
@Singleton
fun provideAccountDao(db: IvyWalletCoreDb): AccountDao = db.accountDao()

@Provides
@Singleton
fun provideAccountCacheDao(db: IvyWalletCoreDb): AccountCacheDao = db.accountCacheDao()

@Provides
@Singleton
fun provideAccountFolderDao(db: IvyWalletCoreDb): AccountFolderDao = db.accountFolderDao()
Expand Down
2 changes: 2 additions & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.ivy.buildsrc.Coroutines
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.RoomDB
import com.ivy.buildsrc.Testing
Expand All @@ -20,6 +21,7 @@ dependencies {
implementation(project(":navigation"))
implementation(project(":math"))
RoomDB(api = false)
Coroutines(api = false)
Testing()
}
android {
Expand Down
3 changes: 2 additions & 1 deletion exchange-rates/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.ivy.buildsrc.Coroutines
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

Expand All @@ -19,7 +20,7 @@ dependencies {
implementation(project(":core:persistence"))
implementation(project(":common:main"))
Testing()

Coroutines(api = false)
}
android {
namespace = "com.ivy.exchangeRates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private fun ActionButton(
onClick: () -> Unit
) {
IvyButton(
modifier = Modifier.size(52.dp).testTag("Hello"),
modifier = Modifier.size(52.dp),
// modifier = Modifier.pointerInput(Unit) {
// detectDragGestures(
// onDragCancel = {
Expand Down
1 change: 1 addition & 0 deletions main/home/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ apply<com.ivy.buildsrc.IvyComposePlugin>()
dependencies {
Hilt()
implementation(project(":common:main"))
implementation(project(":common:android-test"))
implementation(project(":design-system"))
implementation(project(":core:ui"))
implementation(project(":core:data-model"))
Expand Down

0 comments on commit 2a3f657

Please sign in to comment.