Skip to content

Commit

Permalink
core: Skip BaseViewTests on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed May 17, 2020
1 parent a7a1766 commit f1610e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/src/test/common/org/isoron/DependencyResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum class Locale {
}

expect object DependencyResolver {
val ignoreViewTests: Boolean
suspend fun getFileOpener(): FileOpener
suspend fun getDatabase(): Database
fun getDateFormatter(locale: Locale): LocalDateFormatter
Expand Down
13 changes: 10 additions & 3 deletions core/src/test/common/org/isoron/uhabits/BaseViewTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ open class BaseViewTest {
height: Int,
expectedPath: String,
component: Component) {

if (DependencyResolver.ignoreViewTests) {
println("WARN: Ignoring BaseViewTest assertion")
return
}
val canvas = DependencyResolver.createCanvas(width, height)
component.draw(canvas)
assertRenders(expectedPath, canvas)
}

suspend fun assertRenders(path: String,
canvas: Canvas) {

if (DependencyResolver.ignoreViewTests) {
println("WARN: Ignoring BaseViewTest assertion")
return
}
val actualImage = canvas.toImage()
val failedActualPath = "/tmp/failed/${path}"
val failedExpectedPath = failedActualPath.replace(".png", ".expected.png")
val failedExpectedPath = failedActualPath.replace(".png",
".expected.png")
val failedDiffPath = failedActualPath.replace(".png", ".diff.png")
val fileOpener = DependencyResolver.getFileOpener()
val expectedFile = fileOpener.openResourceFile(path)
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/ios/org/isoron/DependencyResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import platform.CoreGraphics.*
import platform.UIKit.*

actual object DependencyResolver {
actual val ignoreViewTests = true

actual suspend fun getFileOpener(): FileOpener = IosFileOpener()

actual fun getDateFormatter(locale: Locale): LocalDateFormatter {
Expand All @@ -53,5 +55,4 @@ actual object DependencyResolver {
db.migrateTo(LOOP_DATABASE_VERSION, fileOpener, log)
return db
}

}
2 changes: 2 additions & 0 deletions core/src/test/js/org/isoron/DependencyResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.w3c.dom.*
import kotlin.browser.*

actual object DependencyResolver {
actual val ignoreViewTests = false

var fileOpener: JsFileOpener? = null

actual suspend fun getFileOpener(): FileOpener {
Expand Down
6 changes: 2 additions & 4 deletions core/src/test/jvm/org/isoron/DependencyResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import org.isoron.platform.io.*
import org.isoron.platform.time.*
import org.isoron.uhabits.*
import java.awt.image.*
import java.io.*
import java.lang.Math.*
import java.nio.file.*
import javax.imageio.*

actual object DependencyResolver {
actual val ignoreViewTests = false

actual suspend fun getFileOpener(): FileOpener = JavaFileOpener()

actual suspend fun getDatabase(): Database {
Expand Down

0 comments on commit f1610e6

Please sign in to comment.