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

fix failed test #797

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/screenshot-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions: { }

jobs:
screenshot-comparison:
runs-on: ubuntu-latest
runs-on: macos-latest
timeout-minutes: 60

permissions:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions: { }

jobs:
unit-test:
runs-on: ubuntu-latest
runs-on: macos-latest
timeout-minutes: 60

permissions:
Expand All @@ -33,7 +33,13 @@ jobs:
name: event-payload
path: ${{ github.event_path }}

- run: ./gradlew testDevDebugUnitTest testDebugUnitTest --stacktrace
- run: |
./gradlew \
testDevDebugUnitTest \
testDebugUnitTest \
:core:data:iosSimulatorArm64Test \
:core:model:iosSimulatorArm64Test \
--stacktrace

# Saving cost
# - run: ./gradlew koverHtmlReportDevDebug --stacktrace
Expand Down
1 change: 1 addition & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ kotlin {
commonTest {
dependencies {
implementation(projects.core.model)
implementation(projects.core.testing)
implementation(libs.kotlinTest)
implementation(libs.okIo)
implementation(libs.ktorKotlinxSerialization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package io.github.droidkaigi.confsched.data.profilecard

import io.github.droidkaigi.confsched.model.ProfileCard
import io.github.droidkaigi.confsched.model.ProfileCardType
import io.github.droidkaigi.confsched.testing.utils.readResourceFile
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okio.FileSystem
import okio.Path.Companion.toPath
import okio.SYSTEM
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFails
Expand Down Expand Up @@ -77,18 +76,17 @@ class ProfileCardJsonTest {

@Test
fun `throw exception when both theme and card_type are not exist`() {
val jsonString =
FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/invalid.json".toPath()) {
readUtf8()
}
val jsonString = readResourceFile("profilecard/invalid.json".toPath()) {
readUtf8()
}

assertFails {
Json.decodeFromString<ProfileCardJson>(jsonString).toModel()
}
}

private fun readJsonString(version: Int): String {
return FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/v$version.json".toPath()) {
return readResourceFile("profilecard/v$version.json".toPath()) {
readUtf8()
}
}
Expand All @@ -102,10 +100,9 @@ class ProfileCardJsonTest {
}

private fun assertSerializedJson(actual: String) {
val expected =
FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/v2.json".toPath()) {
readUtf8()
}
val expected = readResourceFile("profilecard/v2.json".toPath()) {
readUtf8()
}

assertEquals(expected.trim(), actual.trim())
}
Expand Down
85 changes: 52 additions & 33 deletions core/testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
plugins {
id("droidkaigi.primitive.android")
id("droidkaigi.primitive.android.kotlin")
id("droidkaigi.primitive.android.compose")
id("droidkaigi.primitive.android.hilt")
id("droidkaigi.primitive.kmp")
id("droidkaigi.primitive.kmp.android")
id("droidkaigi.primitive.kmp.android.hilt")
id("droidkaigi.primitive.kmp.compose")
id("droidkaigi.primitive.kmp.ios")
id("droidkaigi.primitive.detekt")
}

android.namespace = "io.github.droidkaigi.confsched.core.testing"

dependencies {
implementation(projects.core.model)
implementation(projects.core.designsystem)
implementation(projects.core.data)
implementation(projects.core.droidkaigiui)
implementation(projects.feature.main)
implementation(projects.feature.sessions)
implementation(projects.feature.profilecard)
implementation(projects.feature.about)
implementation(projects.feature.staff)
implementation(projects.feature.sponsors)
implementation(projects.feature.settings)
implementation(projects.feature.favorites)
implementation(projects.feature.eventmap)
implementation(projects.feature.contributors)
implementation(libs.daggerHiltAndroidTesting)
implementation(libs.roborazzi)
implementation(libs.kermit)
implementation(libs.coilTest)
api(projects.core.testingManifest)
api(libs.composeNavigation)
api(libs.roborazziRule)
api(libs.roborazziCompose)
api(libs.robolectric)
api(libs.composeUiTestJunit4)
implementation(libs.composeMaterialWindowSize)
implementation(libs.composablePreviewScanner)
implementation(libs.composablePreviewScannerJvm)
implementation(libs.roborazziPreviewScannerSupport)
kotlin {
sourceSets {
androidMain {
dependencies {
implementation(projects.core.model)
implementation(projects.core.designsystem)
implementation(projects.core.data)
implementation(projects.core.droidkaigiui)
implementation(projects.feature.main)
implementation(projects.feature.sessions)
implementation(projects.feature.profilecard)
implementation(projects.feature.about)
implementation(projects.feature.staff)
implementation(projects.feature.sponsors)
implementation(projects.feature.settings)
implementation(projects.feature.favorites)
implementation(projects.feature.eventmap)
implementation(projects.feature.contributors)
implementation(libs.daggerHiltAndroidTesting)
implementation(libs.roborazzi)
implementation(libs.kermit)
implementation(libs.coilTest)
api(projects.core.testingManifest)
api(libs.composeNavigation)
api(libs.roborazziRule)
api(libs.roborazziCompose)
api(libs.robolectric)
api(libs.composeUiTestJunit4)
implementation(libs.composeMaterialWindowSize)
implementation(libs.composablePreviewScanner)
implementation(libs.composablePreviewScannerJvm)
implementation(libs.roborazziPreviewScannerSupport)
}
}

commonMain {
dependencies {
implementation(libs.okIo)
}
}

iosMain {
dependencies {
implementation(libs.okIo)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.github.droidkaigi.confsched.testing.utils

expect inline fun <T> readResourceFile(filePath: okio.Path, block: okio.BufferedSource.() -> T): T
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.droidkaigi.confsched.testing.utils

import okio.BufferedSource
import okio.FileSystem
import okio.Path
import okio.Path.Companion.toPath
import platform.Foundation.NSBundle

actual inline fun <T> readResourceFile(filePath: Path, block: BufferedSource.() -> T): T {
return FileSystem.SYSTEM.read(
NSBundle.mainBundle.bundlePath.toPath().parent!!.parent!!.parent!!.parent!!
.div("src").div("commonTest").div("resources").div(filePath),
) {
block()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.droidkaigi.confsched.testing.utils

import okio.FileSystem
import okio.Path.Companion.toPath

actual inline fun <T> readResourceFile(filePath: okio.Path, block: okio.BufferedSource.() -> T): T {
return FileSystem.SYSTEM.read(
"src".toPath().div("commonTest").div("resources").div(filePath),
) {
block()
}
}
Loading