This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use medzik-android-utils because crashing
also, if you can, don't use unstable dependencies
- Loading branch information
Showing
28 changed files
with
1,546 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "dev.medzik.android.components" | ||
compileSdk = libs.versions.android.sdk.compile.get().toInt() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.android.sdk.min.get().toInt() | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
compose = true | ||
buildConfig = false | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.androidx.material3) | ||
compileOnly(libs.androidx.navigation.compose) | ||
|
||
debugImplementation(libs.androidx.material3) | ||
debugImplementation(libs.androidx.navigation.compose) | ||
|
||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
|
||
testImplementation(libs.androidx.junit) | ||
// testImplementation(libs.androidx.compose.runtime) | ||
|
||
debugImplementation(libs.androidx.ui.test.manifest) | ||
|
||
// for preview support | ||
debugImplementation(libs.androidx.ui.tooling) | ||
implementation(libs.androidx.ui.tooling.preview) | ||
} |
77 changes: 77 additions & 0 deletions
77
components/src/androidTest/java/dev/medzik/android/components/NavigationTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package dev.medzik.android.components | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
enum class Argument : NavArgument { | ||
ID, | ||
Name | ||
} | ||
|
||
enum class Screen(override val args: Array<NavArgument>? = null) : NavScreen { | ||
Home, | ||
Example(arrayOf(Argument.ID, Argument.Name)) | ||
} | ||
|
||
class NavigationTests { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testNavigation() { | ||
composeTestRule.setContent { | ||
val navController = rememberNavController() | ||
|
||
NavHost(navController = navController, startDestination = Screen.Home.getRoute()) { | ||
composable(Screen.Home.getRoute()) { | ||
Column { | ||
Text("Home Screen") | ||
|
||
Button(onClick = { | ||
navController.navigate( | ||
screen = Screen.Example, | ||
args = | ||
arrayOf( | ||
Argument.ID to "test id", | ||
Argument.Name to "test name" | ||
) | ||
) | ||
}) { | ||
Text("Click me to go to Example screen") | ||
} | ||
} | ||
} | ||
|
||
composable(Screen.Example.getRoute()) { | ||
val id = navController.getString(Argument.ID) | ||
val name = navController.getString(Argument.Name) | ||
|
||
Column { | ||
Text("Example Screen") | ||
Text("ID: $id") | ||
Text("Name: $name") | ||
} | ||
} | ||
} | ||
} | ||
|
||
composeTestRule.onNodeWithText("Home Screen").assertExists() | ||
|
||
// go to example screen | ||
composeTestRule.onNodeWithText("Click me to go to Example screen").performClick() | ||
composeTestRule.onNodeWithText("Example Screen").assertExists() | ||
|
||
// check arguments | ||
composeTestRule.onNodeWithText("ID: test id").assertExists() | ||
composeTestRule.onNodeWithText("Name: test name").assertExists() | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
components/src/androidTest/java/dev/medzik/android/components/RememberTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package dev.medzik.android.components | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class RememberTests { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testRememberMutable() { | ||
composeTestRule.setContent { | ||
var clicked by rememberMutable(0) | ||
|
||
Column { | ||
Text(text = "Clicked: $clicked") | ||
|
||
Button(onClick = { clicked++ }) { | ||
Text(text = "Click me") | ||
} | ||
} | ||
} | ||
|
||
// click the button two times | ||
repeat(2) { | ||
composeTestRule.onNodeWithText("Click me").performClick() | ||
} | ||
|
||
// check if the text changed | ||
composeTestRule.onNodeWithText("Clicked: 2").assertExists() | ||
} | ||
|
||
@Test | ||
fun testRememberMutableString() { | ||
composeTestRule.setContent { | ||
var value by rememberMutableString() | ||
|
||
Column { | ||
Text(text = "Current Value: $value") | ||
|
||
Button(onClick = { value = "test" }) { | ||
Text(text = "Click me") | ||
} | ||
} | ||
} | ||
|
||
// click button | ||
composeTestRule.onNodeWithText("Click me").performClick() | ||
// check if the text changed | ||
composeTestRule.onNodeWithText("Current Value: test").assertExists() | ||
} | ||
|
||
@Test | ||
fun testRememberMutableBoolean() { | ||
composeTestRule.setContent { | ||
var value by rememberMutableBoolean() | ||
|
||
Column { | ||
Text(text = "Current Value: $value") | ||
|
||
Button(onClick = { value = true }) { | ||
Text(text = "Click me") | ||
} | ||
} | ||
} | ||
|
||
// click button | ||
composeTestRule.onNodeWithText("Click me").performClick() | ||
// check if the text changed | ||
composeTestRule.onNodeWithText("Current Value: true").assertExists() | ||
} | ||
} |
Oops, something went wrong.