Use string resource instead of hard-coded strings.
This commit is contained in:
parent
fdc3c9ff39
commit
dee8008917
3 changed files with 24 additions and 11 deletions
|
|
@ -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
|
|||
@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 {
|
|||
onSuccessLogout = EnsureNeverCalledWithParam(),
|
||||
)
|
||||
}
|
||||
rule.clickOn("Sign out")
|
||||
rule.clickOn(CommonStrings.action_signout)
|
||||
eventsRecorder.assertSingle(LogoutEvents.Logout(false))
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ class LogoutViewTest {
|
|||
onSuccessLogout = EnsureNeverCalledWithParam(),
|
||||
)
|
||||
}
|
||||
rule.onNode(hasContentDescription("Back")).performClick()
|
||||
rule.pressBack()
|
||||
callback.assertSuccess()
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
|||
onSuccessLogout = EnsureNeverCalledWithParam(),
|
||||
)
|
||||
}
|
||||
rule.clickOn("Cancel")
|
||||
rule.clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(LogoutEvents.CloseDialogs)
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +142,7 @@ class LogoutViewTest {
|
|||
onSuccessLogout = EnsureNeverCalledWithParam(),
|
||||
)
|
||||
}
|
||||
rule.clickOn("Settings")
|
||||
rule.clickOn(CommonStrings.common_settings)
|
||||
callback.assertSuccess()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue