Browse Source

Use string resource instead of hard-coded strings.

pull/2175/head
Benoit Marty 9 months ago
parent
commit
dee8008917
  1. 19
      features/logout/impl/src/test/kotlin/io/element/android/features/logout/impl/LogoutViewTest.kt
  2. 1
      tests/testutils/build.gradle.kts
  3. 15
      tests/testutils/src/main/kotlin/io/element/android/tests/testutils/SemanticsNodeInteractionsProviderExtensions.kt

19
features/logout/impl/src/test/kotlin/io/element/android/features/logout/impl/LogoutViewTest.kt

@ -16,17 +16,18 @@ @@ -16,17 +16,18 @@
package io.element.android.features.logout.impl
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.performClick
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.tests.testutils.EnsureCalledOnce
import io.element.android.tests.testutils.EnsureCalledOnceWithParam
import io.element.android.tests.testutils.EnsureNeverCalled
import io.element.android.tests.testutils.EnsureNeverCalledWithParam
import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.clickOn
import io.element.android.tests.testutils.pressBack
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@ -34,7 +35,7 @@ import org.junit.runner.RunWith @@ -34,7 +35,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LogoutViewTest {
@get:Rule val rule = createComposeRule()
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
@Test
fun `clicking on logout sends a LogoutEvents`() {
@ -49,7 +50,7 @@ class LogoutViewTest { @@ -49,7 +50,7 @@ class LogoutViewTest {
onSuccessLogout = EnsureNeverCalledWithParam(),
)
}
rule.clickOn("Sign out")
rule.clickOn(CommonStrings.action_signout)
eventsRecorder.assertSingle(LogoutEvents.Logout(false))
}
@ -67,7 +68,7 @@ class LogoutViewTest { @@ -67,7 +68,7 @@ class LogoutViewTest {
onSuccessLogout = EnsureNeverCalledWithParam(),
)
}
rule.onNode(hasContentDescription("Back")).performClick()
rule.pressBack()
callback.assertSuccess()
}
@ -85,7 +86,7 @@ class LogoutViewTest { @@ -85,7 +86,7 @@ class LogoutViewTest {
onSuccessLogout = EnsureNeverCalledWithParam(),
)
}
rule.clickOn("Sign out anyway")
rule.clickOn(CommonStrings.action_signout_anyway)
eventsRecorder.assertSingle(LogoutEvents.Logout(true))
}
@ -103,7 +104,7 @@ class LogoutViewTest { @@ -103,7 +104,7 @@ class LogoutViewTest {
onSuccessLogout = EnsureNeverCalledWithParam(),
)
}
rule.clickOn("Cancel")
rule.clickOn(CommonStrings.action_cancel)
eventsRecorder.assertSingle(LogoutEvents.CloseDialogs)
}
@ -141,7 +142,7 @@ class LogoutViewTest { @@ -141,7 +142,7 @@ class LogoutViewTest {
onSuccessLogout = EnsureNeverCalledWithParam(),
)
}
rule.clickOn("Settings")
rule.clickOn(CommonStrings.common_settings)
callback.assertSuccess()
}
}

1
tests/testutils/build.gradle.kts

@ -31,6 +31,7 @@ dependencies { @@ -31,6 +31,7 @@ dependencies {
implementation(libs.test.truth)
implementation(libs.coroutines.test)
implementation(projects.libraries.core)
implementation(projects.libraries.uiStrings)
implementation(libs.test.turbine)
implementation(libs.molecule.runtime)
implementation(libs.androidx.compose.ui.test.junit)

15
tests/testutils/src/main/kotlin/io/element/android/tests/testutils/SemanticsNodeInteractionsProviderExtensions.kt

@ -16,12 +16,23 @@ @@ -16,12 +16,23 @@
package io.element.android.tests.testutils
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.activity.ComponentActivity
import androidx.annotation.StringRes
import androidx.compose.ui.test.hasClickAction
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.performClick
import io.element.android.libraries.ui.strings.CommonStrings
import org.junit.rules.TestRule
fun SemanticsNodeInteractionsProvider.clickOn(text: String) {
fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.clickOn(@StringRes res: Int) {
val text = activity.getString(res)
onNode(hasText(text) and hasClickAction())
.performClick()
}
fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.pressBack() {
val text = activity.getString(CommonStrings.action_back)
onNode(hasContentDescription(text)).performClick()
}

Loading…
Cancel
Save