Skip to content

Commit

Permalink
rotation android ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
babichev.a committed Mar 4, 2024
1 parent 47a23e2 commit 0b09c42
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 7 deletions.
7 changes: 6 additions & 1 deletion android-compose-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ android {
compose = true
}
packagingOptions.resources.excludes.add("/META-INF/{AL2.0,LGPL2.1}")
testOptions.execution = "ANDROIDX_TEST_ORCHESTRATOR"
testOptions{
execution = "ANDROIDX_TEST_ORCHESTRATOR"
emulatorControl.enable = true
}
}

dependencies {
Expand All @@ -80,6 +83,7 @@ dependencies {
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
implementation(libs.firebase.crashlytics)
implementation(libs.androidx.tracing)
debugImplementation(libs.leakCanary.android)
debugImplementation(libs.leakCanary.android.process)
implementation(libs.leakCanary.plumber.android)
Expand All @@ -91,6 +95,7 @@ dependencies {
androidTestImplementation(libs.androidx.test.runner)
androidTestUtil(libs.androidx.test.orchestrator)
androidTestImplementation(libs.espresso.core)
androidTestImplementation(libs.espresso.device)
androidTestImplementation(compose.desktop.uiTestJUnit4)
androidTestImplementation(libs.turbine)
androidTestImplementation(libs.leakCanary.android.instrumentation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.softartdev.notedelight.ui

import android.content.Context
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.device.DeviceInteraction.Companion.setScreenOrientation
import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
import androidx.test.espresso.device.action.ScreenOrientation
import androidx.test.espresso.device.rules.ScreenOrientationRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.softartdev.notedelight.ComposeIdlingRes
import com.softartdev.notedelight.MainActivity
import com.softartdev.notedelight.shared.R
import com.softartdev.notedelight.shared.base.IdlingRes
import leakcanary.DetectLeaksAfterTestSuccess
import leakcanary.TestDescriptionHolder
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class RotationTest {

private val composeTestRule = createAndroidComposeRule<MainActivity>()

@get:Rule
val rules: RuleChain = RuleChain.outerRule(TestDescriptionHolder)
.around(DetectLeaksAfterTestSuccess())
.around(ScreenOrientationRule(ScreenOrientation.PORTRAIT))
.around(composeTestRule)

private val context = ApplicationProvider.getApplicationContext<Context>()

@Before
fun registerIdlingResource() {
IdlingRegistry.getInstance().register(IdlingRes.countingIdlingResource)
composeTestRule.registerIdlingResource(ComposeIdlingRes)
}

@After
fun unregisterIdlingResource() {
composeTestRule.unregisterIdlingResource(ComposeIdlingRes)
IdlingRegistry.getInstance().unregister(IdlingRes.countingIdlingResource)
}

@Test
fun rotationTest() {
composeTestRule
.onNodeWithContentDescription(label = context.getString(R.string.create_note))
.assertIsDisplayed()

onDevice().setScreenOrientation(ScreenOrientation.LANDSCAPE)

composeTestRule
.onNodeWithContentDescription(label = context.getString(R.string.create_note))
.assertIsDisplayed()

onDevice().setScreenOrientation(ScreenOrientation.PORTRAIT)
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.configuration-cache=true

kotlin.code.style=official
#kotlin.native.binary.memoryModel=experimental
Expand All @@ -17,5 +18,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true
android.useAndroidX=true
android.nonTransitiveRClass=true
android.nonFinalResIds=true
android.experimental.androidTest.enableEmulatorControl=true

xcodeproj=iosApp/iosApp.xcworkspace
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ androidxCoreSplashscreen = "1.0.1"
androidxLegacySupport = "1.0.0"
androidxPreference = "1.2.1"
androidxMultidex = "2.0.1"
androidxTracing = "1.2.0"
androidxLifecycle = "2.7.0"
androidxArch = "2.2.0"
androidxTestExt = "1.1.5"
Expand Down Expand Up @@ -95,6 +96,7 @@ androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", versi
androidx-legacy-support = { module = "androidx.legacy:legacy-support-v4", version.ref = "androidxLegacySupport" }
androidx-preference = { module = "androidx.preference:preference", version.ref = "androidxPreference" }
androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "androidxMultidex" }
androidx-tracing = { module = "androidx.tracing:tracing", version.ref = "androidxTracing" }

androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" }
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" }
Expand All @@ -104,7 +106,6 @@ androidx-arch-core-runtime = { module = "androidx.arch.core:core-runtime", versi
androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "androidxArch" }

androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExt" }

androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidxTest" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidxTest" }
androidx-test-orchestrator = { module = "androidx.test:orchestrator", version.ref = "androidxTestOrchestrator" }
Expand All @@ -131,6 +132,7 @@ appdirs = { module = "net.harawata:appdirs", version.ref = "appdirs" }

espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" }
espresso-contrib = { module = "androidx.test.espresso:espresso-contrib", version.ref = "espresso" }
espresso-device = { module = "androidx.test.espresso:espresso-device", version = "1.0.0-alpha08" }
espresso-idling-resource = { module = "androidx.test.espresso:espresso-idling-resource", version.ref = "espresso" }

desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }
Expand Down
2 changes: 1 addition & 1 deletion iosApp/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 0dc93a6f6109335ea8cd3f91d2c87cc8c99f04a3

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion iosApp/Pods/Manifest.lock

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

4 changes: 2 additions & 2 deletions iosApp/Pods/Pods.xcodeproj/project.pbxproj

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

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

0 comments on commit 0b09c42

Please sign in to comment.