-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Crete compose base * Rollback files * Move test to barista-compose module * Methods with StringRes working * Update assertIsNotDisplayed * Add assertIsDisplayed and assertIsNotDisplayed to SemanticsNodeInteraction * Remove node version of assertIsDisplayed() and assertIsNotDisplayed() * Rename methods to assertDisplayed() and assertNotDisplayed() to match Barista API * Reorder params so we can have same signatures * Simplify tests * Remove unused composable * Remove compose from sample * Remove unneded files * Make sure build on Github CI runs compose tests * Cleanup test * Cleanup test * Update barista compose to allow publish
- Loading branch information
Showing
12 changed files
with
214 additions
and
2 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
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,50 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
} | ||
|
||
apply(from = "../config/android-quality.gradle") | ||
|
||
ext["PUBLISH_ARTIFACT_ID"] = "barista-compose" | ||
|
||
apply(from = "${rootProject.projectDir}/scripts/publish-module.gradle") | ||
|
||
android { | ||
compileSdk = 31 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
targetSdk = 31 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
testInstrumentationRunnerArguments["clearPackageData"] = "true" | ||
} | ||
|
||
buildFeatures { | ||
compose = true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = rootProject.extra["compose_version"] as String | ||
} | ||
|
||
packagingOptions { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api("androidx.test.ext:junit:1.1.3") | ||
api("androidx.compose.ui:ui-test-junit4:1.0.2") | ||
|
||
debugImplementation("androidx.compose.ui:ui:${rootProject.extra["compose_version"]}") | ||
debugImplementation("androidx.compose.material:material:${rootProject.extra["compose_version"]}") | ||
debugImplementation("androidx.compose.ui:ui-tooling-preview:${rootProject.extra["compose_version"]}") | ||
debugImplementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1") | ||
debugImplementation("androidx.activity:activity-compose:1.3.1") | ||
debugImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}") | ||
debugImplementation("androidx.compose.ui:ui-test-manifest:${rootProject.extra["compose_version"]}") | ||
debugImplementation("androidx.compose.ui:ui-tooling:${rootProject.extra["compose_version"]}") | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
barista-compose/src/androidTest/java/ComposeAssertionsTest.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,69 @@ | ||
package com.alorma.barista_compose.assertion | ||
|
||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.adevinta.android.barista.sample.TextComposable | ||
import com.alorma.barista_compose.R | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class ComposeAssertionsTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
// assertDisplayed tests | ||
@Test | ||
fun assertDisplayed_StringTest() { | ||
composeTestRule.setContent { | ||
TextComposable("Hello world") | ||
} | ||
|
||
composeTestRule.assertDisplayed("Hello world") | ||
} | ||
|
||
@Test | ||
fun assertDisplayed_ResourceTest() { | ||
composeTestRule.setContent { | ||
TextComposable(stringResource(R.string.app_name)) | ||
} | ||
|
||
composeTestRule.assertDisplayed(R.string.app_name) | ||
} | ||
|
||
@Test(expected = AssertionError::class) | ||
fun assertDisplayed_ResourceTest_fail() { | ||
composeTestRule.setContent { | ||
TextComposable(stringResource(R.string.app_name)) | ||
} | ||
|
||
composeTestRule.assertDisplayed(R.string.next) | ||
} | ||
|
||
// assertNotDisplayed tests | ||
@Test | ||
fun assertNotDisplayed_StringTest() { | ||
val text = "Hello world" | ||
composeTestRule.setContent { TextComposable(text) } | ||
|
||
composeTestRule.assertNotDisplayed("next") | ||
} | ||
|
||
@Test | ||
fun assertNotDisplayed_ResourceTest() { | ||
composeTestRule.setContent { | ||
TextComposable(stringResource(R.string.app_name)) | ||
} | ||
|
||
composeTestRule.assertNotDisplayed(R.string.next) | ||
} | ||
|
||
@Test(expected = AssertionError::class) | ||
fun assertNotDisplayed_ResourceTest_fail() { | ||
composeTestRule.setContent { | ||
TextComposable(stringResource(R.string.next)) | ||
} | ||
|
||
composeTestRule.assertNotDisplayed(R.string.next) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
barista-compose/src/debug/java/com/adevinta/android/barista/sample/TextComposable.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,17 @@ | ||
package com.adevinta.android.barista.sample | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun TextComposable( | ||
text: String | ||
) { | ||
Box(modifier = Modifier.padding(16.dp)) { | ||
Text(text = text) | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">Barista</string> | ||
<string name="next">Next</string> | ||
</resources> |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.alorma.barista_compose" | ||
> | ||
|
||
</manifest> |
49 changes: 49 additions & 0 deletions
49
barista-compose/src/main/java/com/alorma/barista_compose/assertion/BaristaAssertions.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,49 @@ | ||
package com.alorma.barista_compose.assertion | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.ui.test.SemanticsNodeInteraction | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.alorma.barista_compose.assertion.internal.resources | ||
|
||
fun ComposeTestRule.assertDisplayed( | ||
text: String, | ||
useUnmergedTree: Boolean = false, | ||
substring: Boolean = false, | ||
ignoreCase: Boolean = false | ||
): SemanticsNodeInteraction { | ||
return onNodeWithText( | ||
text = text, | ||
substring = substring, | ||
ignoreCase = ignoreCase, | ||
useUnmergedTree = useUnmergedTree | ||
).assertIsDisplayed() | ||
} | ||
|
||
fun ComposeTestRule.assertDisplayed( | ||
@StringRes textRes: Int, | ||
useUnmergedTree: Boolean = false, | ||
substring: Boolean = false, | ||
ignoreCase: Boolean = false, | ||
): SemanticsNodeInteraction { | ||
return assertDisplayed(resources().getString(textRes), useUnmergedTree, substring, ignoreCase) | ||
} | ||
|
||
fun ComposeTestRule.assertNotDisplayed( | ||
text: String, | ||
useUnmergedTree: Boolean = false, | ||
substring: Boolean = false, | ||
ignoreCase: Boolean = false | ||
) { | ||
return onNodeWithText(text, substring, ignoreCase, useUnmergedTree).assertDoesNotExist() | ||
} | ||
|
||
fun ComposeTestRule.assertNotDisplayed( | ||
@StringRes textRes: Int, | ||
useUnmergedTree: Boolean = false, | ||
substring: Boolean = false, | ||
ignoreCase: Boolean = false | ||
) { | ||
return assertNotDisplayed(resources().getString(textRes), useUnmergedTree, substring, ignoreCase) | ||
} |
10 changes: 10 additions & 0 deletions
10
...mpose/src/main/java/com/alorma/barista_compose/assertion/internal/ComposeTestRuleUtils.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,10 @@ | ||
package com.alorma.barista_compose.assertion.internal | ||
|
||
import androidx.compose.ui.test.junit4.AndroidComposeTestRule | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
|
||
internal fun ComposeTestRule.resources() = if (this is AndroidComposeTestRule<*, *>) { | ||
activity.resources | ||
} else { | ||
throw RuntimeException("ComposeTestRule is not AndroidComposeTestRule") | ||
} |
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ gradleEnterprise { | |
} | ||
} | ||
include ':sample', ':library' | ||
include ':barista-compose' |