Skip to content

Commit

Permalink
Merge pull request #603 from takahirom/takahirom/add-default-theme-te…
Browse files Browse the repository at this point in the history
…st/2024-12-12

Add default theme test
  • Loading branch information
takahirom authored Dec 15, 2024
2 parents 371cce6 + 0895c56 commit 4f7ef54
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gradle/android.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
android {
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35
versionCode 1
versionName "1.0"

Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ composeCompiler = "1.5.10"
composeMultiplatform = "1.6.2"
robolectric = "4.14.1"
generativeaiGoogle = "0.9.0-1.0.1"
robolectric-android-all = "Q-robolectric-5415296"
robolectric-android-all = "15-robolectric-12650502"

roborazzi-for-replacing-by-include-build = "1.0.0"

Expand All @@ -32,6 +32,7 @@ androidx-lifecycle = "2.6.1"
androidx-navigation = "2.7.7"
androidx-test-espresso-core = "3.5.1"
androidx-test-ext-junit = "1.2.1"
androidx-test-core = "1.6.1"
kim = "0.17.7"

dropbox-differ = "0.3.0"
Expand Down Expand Up @@ -86,6 +87,7 @@ androidx-navigation-ui-ktx = { module = "androidx.navigation:navigation-ui-ktx",
androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso-core" }
androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-ext-junit" }
androidx-test-ext-junit-ktx = { module = "androidx.test.ext:junit-ktx", version.ref = "androidx-test-ext-junit" }
androidx-test-core-ktx = { group = "androidx.test", name = "core-ktx", version.ref = "androidx-test-core" }
kim = { module = "com.ashampoo:kim", version.ref = "kim" }

android-tools-build-gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
Expand Down
4 changes: 2 additions & 2 deletions include-build/roborazzi-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ kotlin {

android {
namespace 'com.github.takahirom.roborazzi.core'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions roborazzi-accessibility-check/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ if (System.getenv("INTEGRATION_TEST") != "true") {

android {
namespace 'com.github.takahirom.roborazzi.accessibility.check'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions roborazzi-ai-gemini/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ kotlin {

android {
namespace 'com.github.takahirom.roborazzi.ai.gemini'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions roborazzi-ai-openai/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ kotlin {

android {
namespace 'com.github.takahirom.roborazzi.ai.openai'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions roborazzi-junit-rule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ if (System.getenv("INTEGRATION_TEST") != "true") {

android {
namespace 'com.github.takahirom.roborazzi.junit.rule'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions sample-android-without-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugins {

android {
namespace 'com.github.takahirom.roborazzi.sample'
compileSdk 34
compileSdk 35

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 35
versionCode 1
versionName "1.0"

Expand Down
1 change: 1 addition & 0 deletions sample-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ dependencies {
androidTestImplementation libs.androidx.test.ext.junit
testImplementation libs.androidx.compose.material
testImplementation libs.androidx.test.espresso.core
testImplementation libs.androidx.test.core.ktx
testImplementation libs.robolectric
testImplementation(libs.kim)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.github.takahirom.roborazzi.sample

import android.app.Application
import android.content.ComponentName
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.unit.dp
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.RoborazziRule
import com.github.takahirom.roborazzi.RoborazziTransparentActivity
import com.github.takahirom.roborazzi.captureRoboImage
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import org.junit.runner.RunWith
import org.robolectric.Shadows
import org.robolectric.annotation.GraphicsMode

class DefaultThemeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(android.R.style.Theme_Material_Light)
super.onCreate(savedInstanceState)
}
}

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class DefaultThemeComposeTest {
@get:Rule(order = 1)
val addActivityToRobolectricRule = object : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
val appContext: Application = ApplicationProvider.getApplicationContext()
Shadows.shadowOf(appContext.packageManager).addActivityIfNotPresent(
ComponentName(
appContext.packageName,
DefaultThemeActivity::class.java.name,
)
)
}
}

@get:Rule(order = 2)
val composeTestRule = createAndroidComposeRule<DefaultThemeActivity>()

@get:Rule
val roborazziRule = RoborazziRule(
composeRule = composeTestRule,
captureRoot = composeTestRule.onRoot(),
)

@Test
fun composable() {
composeTestRule.setContent {
MaterialTheme {
Surface {
Box(modifier = Modifier.padding(8.dp)) {
ElevatedCard(
elevation = CardDefaults.cardElevation(
defaultElevation = 6.dp
),
) {
Text("a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz")
}
}
}
}
}
composeTestRule.onRoot().captureRoboImage()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.io.File
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(
sdk = [30],
sdk = [35],
qualifiers = RobolectricDeviceQualifiers.NexusOne
)
class ManualTest {
Expand Down

0 comments on commit 4f7ef54

Please sign in to comment.