mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Iterate on EnsureCalledOnce devX
This commit is contained in:
+5
-5
@@ -21,12 +21,12 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import io.element.android.libraries.architecture.AsyncAction
|
import io.element.android.libraries.architecture.AsyncAction
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
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.EnsureNeverCalled
|
||||||
import io.element.android.tests.testutils.EnsureNeverCalledWithParam
|
import io.element.android.tests.testutils.EnsureNeverCalledWithParam
|
||||||
import io.element.android.tests.testutils.EventsRecorder
|
import io.element.android.tests.testutils.EventsRecorder
|
||||||
import io.element.android.tests.testutils.clickOn
|
import io.element.android.tests.testutils.clickOn
|
||||||
|
import io.element.android.tests.testutils.ensureCalledOnce
|
||||||
|
import io.element.android.tests.testutils.ensureCalledOnceWithParam
|
||||||
import io.element.android.tests.testutils.pressBack
|
import io.element.android.tests.testutils.pressBack
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -57,7 +57,7 @@ class LogoutViewTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `clicking on back invoke back callback`() {
|
fun `clicking on back invoke back callback`() {
|
||||||
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
||||||
EnsureCalledOnce().run { callback ->
|
ensureCalledOnce { callback ->
|
||||||
rule.setContent {
|
rule.setContent {
|
||||||
LogoutView(
|
LogoutView(
|
||||||
aLogoutState(
|
aLogoutState(
|
||||||
@@ -112,7 +112,7 @@ class LogoutViewTest {
|
|||||||
fun `success logout invoke onSuccessLogout`() {
|
fun `success logout invoke onSuccessLogout`() {
|
||||||
val data = "data"
|
val data = "data"
|
||||||
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
||||||
EnsureCalledOnceWithParam<String?>(data).run { callback ->
|
ensureCalledOnceWithParam<String?>(data) { callback ->
|
||||||
rule.setContent {
|
rule.setContent {
|
||||||
LogoutView(
|
LogoutView(
|
||||||
aLogoutState(
|
aLogoutState(
|
||||||
@@ -130,7 +130,7 @@ class LogoutViewTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `last session setting button invoke onChangeRecoveryKeyClicked`() {
|
fun `last session setting button invoke onChangeRecoveryKeyClicked`() {
|
||||||
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
||||||
EnsureCalledOnce().run { callback ->
|
ensureCalledOnce { callback ->
|
||||||
rule.setContent {
|
rule.setContent {
|
||||||
LogoutView(
|
LogoutView(
|
||||||
aLogoutState(
|
aLogoutState(
|
||||||
|
|||||||
+10
-8
@@ -27,11 +27,12 @@ class EnsureCalledOnce : () -> Unit {
|
|||||||
throw AssertionError("Expected to be called once, but was called $counter times")
|
throw AssertionError("Expected to be called once, but was called $counter times")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun run(block: (callback: EnsureCalledOnce) -> Unit) {
|
|
||||||
block(this)
|
|
||||||
assertSuccess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ensureCalledOnce(block: (callback: EnsureCalledOnce) -> Unit) {
|
||||||
|
val callback = EnsureCalledOnce()
|
||||||
|
block(callback)
|
||||||
|
callback.assertSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnsureCalledOnceWithParam<T>(
|
class EnsureCalledOnceWithParam<T>(
|
||||||
@@ -50,9 +51,10 @@ class EnsureCalledOnceWithParam<T>(
|
|||||||
throw AssertionError("Expected to be called once, but was called $counter times")
|
throw AssertionError("Expected to be called once, but was called $counter times")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun run(block: (callback: EnsureCalledOnceWithParam<T>) -> Unit) {
|
fun <T> ensureCalledOnceWithParam(param: T, block: (callback: EnsureCalledOnceWithParam<T>) -> Unit) {
|
||||||
block(this)
|
val callback = EnsureCalledOnceWithParam(param)
|
||||||
assertSuccess()
|
block(callback)
|
||||||
}
|
callback.assertSuccess()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user