Skip to content

Commit

Permalink
Add client unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Dec 27, 2024
1 parent b105696 commit 8fccb04
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Run unit tests
run: ./gradlew jvmTest
run: ./gradlew desktopTest

180 changes: 93 additions & 87 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,118 +1,124 @@
import com.google.devtools.ksp.gradle.KspTask

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.ksp)
idea
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.ksp)
idea
}

kotlin {
js(IR) {
browser()
binaries.executable()
}
js(IR) {
browser()
binaries.executable()
}

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
}

jvm("desktop")
jvm("desktop")

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}

sourceSets {
commonMain {
kotlin.srcDirs("build/generated/ksp/commonMain/kotlin")
}
sourceSets {
commonMain {
kotlin.srcDirs("build/generated/ksp/commonMain/kotlin")
}
commonTest {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
dependencies {
ksp(libs.arrow.optics.ksp)
}

val desktopMain by getting
val desktopMain by getting

androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(projects.shared)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.kotlin.immutableCollections)
implementation(libs.thirdparty.lottieMultiplatform)
implementation(libs.thirdparty.kamel)
implementation(libs.bundles.arrow)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
}

dependencies {
ksp(libs.arrow.optics.ksp)
commonMain.dependencies {
implementation(projects.shared)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.kotlin.immutableCollections)
implementation(libs.thirdparty.lottieMultiplatform)
implementation(libs.thirdparty.kamel)
implementation(libs.bundles.arrow)
}
commonTest.dependencies {
implementation(libs.bundles.test.kmp)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
}
}

android {
namespace = "ivy.learn"
compileSdk = libs.versions.android.compileSdk.get().toInt()
namespace = "ivy.learn"
compileSdk = libs.versions.android.compileSdk.get().toInt()

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
applicationId = "ivy.learn"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
defaultConfig {
applicationId = "ivy.learn"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

compose.experimental {
web.application {}
web.application {}
}

// Configure KSP to output to the commonMain directory
tasks.withType<KspTask> {
doLast {
copy {
from("build/generated/ksp/js/jsMain/kotlin")
into("build/generated/ksp/commonMain/kotlin")
include("**/*.kt")
}
delete("build/generated/ksp/js/jsMain/kotlin")
doLast {
copy {
from("build/generated/ksp/js/jsMain/kotlin")
into("build/generated/ksp/commonMain/kotlin")
include("**/*.kt")
}
delete("build/generated/ksp/js/jsMain/kotlin")
delete("build/generated/ksp/desktop/desktopMain/kotlin")
}
}
37 changes: 37 additions & 0 deletions composeApp/src/commonTest/kotlin/AppConfigurationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import di.AppModule
import io.kotest.matchers.shouldBe
import ivy.di.Di
import kotlin.test.BeforeTest
import kotlin.test.Test

class AppConfigurationTest {
@BeforeTest
fun setup() {
Di.reset()
Di.init(AppModule)
}

@Test
fun fakes_should_be_disabled() {
// Given
val appConfiguration = Di.get<AppConfiguration>()

// When
val fakesEnabled = appConfiguration.fakesEnabled

// Then
fakesEnabled shouldBe false
}

@Test
fun should_not_use_local_server() {
// Given
val appConfiguration = Di.get<AppConfiguration>()

// When
val userLocalServer = appConfiguration.useLocalServer

// Then
userLocalServer shouldBe false
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package navigation

import kotlinx.coroutines.flow.StateFlow

class DesktopSystemNavigation : SystemNavigation {
override val currentRoute: StateFlow<Route>
get() = TODO("Not yet implemented")

override fun navigateTo(screen: Screen) {}
override fun navigateBack() {}
override fun setupUrlChangeListener(onUrlChange: (String, Map<String, String>) -> Unit) {}
override fun replaceWith(screen: Screen) {
TODO("Not yet implemented")
}

override fun navigateBack(): Boolean {
TODO("Not yet implemented")
}

}

actual fun systemNavigation(): SystemNavigation = DesktopSystemNavigation()
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ test = [
"kotest-assertions-arrow",
"kotlin-coroutines-test"
]
test-kmp = [
"kotlin-test",
"google-testparameterinjector",
"kotest-assertions",
"kotest-property",
"kotest-property-arrow",
"kotest-assertions-arrow",
"kotlin-coroutines-test"
]
ktor-client-common = [
"ktor-client-content-negotiation",
"ktor-serialization-json",
Expand Down

0 comments on commit 8fccb04

Please sign in to comment.