Iterate on EnsureCalledOnce devX
This commit is contained in:
parent
2c667a0dc0
commit
2a6a3ded5e
2 changed files with 16 additions and 14 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
fun ensureCalledOnce(block: (callback: EnsureCalledOnce) -> Unit) {
|
||||||
block(this)
|
val callback = EnsureCalledOnce()
|
||||||
assertSuccess()
|
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) {
|
|
||||||
block(this)
|
fun <T> ensureCalledOnceWithParam(param: T, block: (callback: EnsureCalledOnceWithParam<T>) -> Unit) {
|
||||||
assertSuccess()
|
val callback = EnsureCalledOnceWithParam(param)
|
||||||
}
|
block(callback)
|
||||||
|
callback.assertSuccess()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue