Skip to content

Commit

Permalink
Add new targets to core, -compose and -flow modules
Browse files Browse the repository at this point in the history
Compose module now supports macos and ios targets,
while core and flow modules support additionally linux
  • Loading branch information
Aruziell committed Jun 9, 2023
1 parent 2f12ee7 commit 6d4d50b
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
kotlin.code.style=official

android.useAndroidX=true

kotlin.native.cacheKind=none

org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[versions]
compose = "1.2.1"
kotlin = "1.7.20"
compose = "1.4.0"
kotlin = "1.8.20"

[libraries]
android-gradle = { group = "com.android.tools.build", name = "gradle", version = "7.2.2" }
android-gradle = { group = "com.android.tools.build", name = "gradle", version = "7.4.0" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.6.4" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.7.1" }
mockk = { group = "io.mockk", name = "mockk", version = "1.13.2" }
rxjava2-rxkotlin = { group = "io.reactivex.rxjava2", name = "rxkotlin", version = "2.4.0" }
rxjava3-rxkotlin = { group = "io.reactivex.rxjava3", name = "rxkotlin", version = "3.0.1" }
testng = { group = "org.testng", name = "testng", version = "7.6.1" }
assertk = { group = "com.willowtreeapps.assertk", name = "assertk", version = "0.26.1" }

[plugins]
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 18 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
25 changes: 11 additions & 14 deletions remotedata-androidlayout/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@ plugins {
}

group = "com.carelesscoyotes.remotedata"
version = "0.1"
version = "0.2"

android {
compileSdk = 32
compileSdk = 33

namespace = "remotedata.androidlayout"

defaultConfig {
@Suppress("UnstableApiUsage")
minSdk = 21
@Suppress("UnstableApiUsage")
targetSdk = 32

@Suppress("UnstableApiUsage")
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
@Suppress("UnstableApiUsage")
consumerProguardFiles("consumer-rules.pro")
}

compileOptions {
@Suppress("UnstableApiUsage")
sourceCompatibility = JavaVersion.VERSION_1_8
@Suppress("UnstableApiUsage")
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

publishing {
Expand All @@ -40,6 +33,10 @@ android {
}
}

kotlin {
jvmToolchain(11)
}

repositories {
mavenCentral()
google()
Expand Down
2 changes: 1 addition & 1 deletion remotedata-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "com.carelesscoyotes.remotedata"
version = "0.3"
version = "0.4"

repositories {
mavenCentral()
Expand Down
14 changes: 10 additions & 4 deletions remotedata-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.carelesscoyotes.remotedata"
version = "0.1"
version = "0.2"

repositories {
google()
Expand All @@ -17,20 +17,24 @@ repositories {

kotlin {
jvm()
macosX64()
macosArm64()
ios()
iosSimulatorArm64()

sourceSets {
named("commonMain") {
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(compose.runtime)
implementation(compose.foundation)
api(project(":remotedata"))
}
}
named("commonTest") {
commonTest {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(libs.mockk)
}
}

Expand All @@ -42,6 +46,8 @@ kotlin {
}
}
}

jvmToolchain(11)
}

signing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package remotedata.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import org.junit.Rule
import org.junit.Test

Expand All @@ -11,6 +13,11 @@ internal fun ComposeContentTestRule.testContext() =
override fun setContent(composable: @Composable () -> Unit) {
this@testContext.setContent(composable = composable)
}

override fun assertExistsSingle(testTag: String) {
onAllNodesWithTag(testTag, useUnmergedTree = true)
.assertCountEquals(1)
}
}

class RemoteDataViewDesktopTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,89 +1,83 @@
package remotedata.compose

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import io.mockk.mockk
import io.mockk.verify
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import remotedata.RemoteData
import remotedata.RemoteData.Companion.failure
import remotedata.RemoteData.Companion.success
import kotlin.test.fail

interface ComposeTestContext {
fun setContent(composable: @Composable () -> Unit)
fun assertExistsSingle(testTag: String)
}

fun ComposeTestContext.testNotAsked() {
val rd = RemoteData.NotAsked
val notAsked: () -> Unit = mockk(relaxed = true)
val tag = "not asked"

setContent {
RemoteDataView(
remoteData = rd,
notAsked = { notAsked() },
notAsked = { Box(modifier = Modifier.testTag(tag)) },
loading = { fail() },
failure = { fail() },
success = { fail() },
)
}

verify(exactly = 1) {
notAsked()
}
assertExistsSingle(testTag = tag)
}

fun ComposeTestContext.testLoading() {
val rd = RemoteData.Loading
val loading: () -> Unit = mockk(relaxed = true)
val tag = "loading"

setContent {
RemoteDataView(
remoteData = rd,
notAsked = { fail() },
loading = { loading() },
loading = { Box(modifier = Modifier.testTag(tag)) },
failure = { fail() },
success = { fail() },
)
}

verify(exactly = 1) {
loading()
}
assertExistsSingle(testTag = tag)
}

fun ComposeTestContext.testFailure() {
val rd = "test error".failure()
val failure: () -> Unit = mockk(relaxed = true)
val tag = "failure"

setContent {
RemoteDataView(
remoteData = rd,
notAsked = { fail() },
loading = { fail() },
failure = { failure() },
failure = { Box(modifier = Modifier.testTag(tag = tag)) },
success = { fail() },
)
}

verify(exactly = 1) {
failure()
}
assertExistsSingle(testTag = tag)
}

fun ComposeTestContext.testSuccess() {
val rd = "test data".success()
val success: () -> Unit = mockk(relaxed = true)
val tag = "success"

setContent {
RemoteDataView(
remoteData = rd,
notAsked = { fail() },
loading = { fail() },
failure = { fail() },
success = { success() },
success = { Box(modifier = Modifier.testTag(tag = tag)) },
)
}

verify(exactly = 1) {
success()
}
assertExistsSingle(testTag = tag)
}
Loading

0 comments on commit 6d4d50b

Please sign in to comment.