TroubleshootNotificationsEvents -> TroubleshootNotificationsEvent

This commit is contained in:
Benoit Marty
2026-08-25 10:33:16 +02:00
parent 217ccb75ed
commit cfa63156e2
7 changed files with 25 additions and 25 deletions
@@ -8,8 +8,8 @@
package io.element.android.libraries.troubleshoot.impl
sealed interface TroubleshootNotificationsEvents {
data object StartTests : TroubleshootNotificationsEvents
data object RetryFailedTests : TroubleshootNotificationsEvents
data class QuickFix(val testIndex: Int) : TroubleshootNotificationsEvents
sealed interface TroubleshootNotificationsEvent {
data object StartTests : TroubleshootNotificationsEvent
data object RetryFailedTests : TroubleshootNotificationsEvent
data class QuickFix(val testIndex: Int) : TroubleshootNotificationsEvent
}
@@ -38,19 +38,19 @@ class TroubleshootNotificationsPresenter(
}
val testSuiteState by troubleshootTestSuite.state.collectAsState()
fun handleEvent(event: TroubleshootNotificationsEvents) {
fun handleEvent(event: TroubleshootNotificationsEvent) {
when (event) {
TroubleshootNotificationsEvents.StartTests -> coroutineScope.launch {
TroubleshootNotificationsEvent.StartTests -> coroutineScope.launch {
troubleshootTestSuite.runTestSuite(this)
}
is TroubleshootNotificationsEvents.QuickFix -> coroutineScope.launch {
is TroubleshootNotificationsEvent.QuickFix -> coroutineScope.launch {
troubleshootTestSuite.quickFix(
testIndex = event.testIndex,
coroutineScope = this,
navigator = navigator,
)
}
TroubleshootNotificationsEvents.RetryFailedTests -> coroutineScope.launch {
TroubleshootNotificationsEvent.RetryFailedTests -> coroutineScope.launch {
troubleshootTestSuite.retryFailedTest(this)
}
}
@@ -10,7 +10,7 @@ package io.element.android.libraries.troubleshoot.impl
data class TroubleshootNotificationsState(
val testSuiteState: TroubleshootTestSuiteState,
val eventSink: (TroubleshootNotificationsEvents) -> Unit,
val eventSink: (TroubleshootNotificationsEvent) -> Unit,
) {
val hasFailedTests: Boolean = testSuiteState.mainState.isFailure()
}
@@ -78,7 +78,7 @@ open class TroubleshootNotificationsStatePreviewParam : PreviewParameterProvider
fun aTroubleshootNotificationsState(
tests: List<NotificationTroubleshootTestState> = emptyList(),
eventSink: (TroubleshootNotificationsEvents) -> Unit = {},
eventSink: (TroubleshootNotificationsEvent) -> Unit = {},
) = TroubleshootNotificationsState(
eventSink = eventSink,
testSuiteState = TroubleshootTestSuiteState(
@@ -44,7 +44,7 @@ fun TroubleshootNotificationsView(
when (event) {
Lifecycle.Event.ON_RESUME -> {
if (state.hasFailedTests) {
state.eventSink(TroubleshootNotificationsEvents.RetryFailedTests)
state.eventSink(TroubleshootNotificationsEvent.RetryFailedTests)
}
}
else -> Unit
@@ -129,7 +129,7 @@ private fun ColumnScope.TroubleshootNotificationsContent(state: TroubleshootNoti
TestSuiteView(
testSuiteState = state.testSuiteState,
onQuickFixClick = {
state.eventSink(TroubleshootNotificationsEvents.QuickFix(it))
state.eventSink(TroubleshootNotificationsEvent.QuickFix(it))
}
)
}
@@ -181,7 +181,7 @@ private fun RunTestButton(state: TroubleshootNotificationsState) {
}
),
onClick = {
state.eventSink(TroubleshootNotificationsEvents.StartTests)
state.eventSink(TroubleshootNotificationsEvent.StartTests)
},
modifier = Modifier.fillMaxWidth(),
)
@@ -42,7 +42,7 @@ class TroubleshootNotificationsPresenterTest {
)
presenter.test {
val initialState = awaitItem()
initialState.eventSink(TroubleshootNotificationsEvents.StartTests)
initialState.eventSink(TroubleshootNotificationsEvent.StartTests)
skipItems(1)
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
@@ -63,7 +63,7 @@ class TroubleshootNotificationsPresenterTest {
)
presenter.test {
val initialState = awaitItem()
initialState.eventSink(TroubleshootNotificationsEvents.RetryFailedTests)
initialState.eventSink(TroubleshootNotificationsEvent.RetryFailedTests)
skipItems(1)
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
@@ -160,7 +160,7 @@ class TroubleshootNotificationsPresenterTest {
skipItems(1)
val initialState = awaitItem()
assertThat(initialState.testSuiteState.mainState).isInstanceOf(AsyncAction.Failure::class.java)
initialState.eventSink(TroubleshootNotificationsEvents.QuickFix(0))
initialState.eventSink(TroubleshootNotificationsEvent.QuickFix(0))
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
}
@@ -27,7 +27,7 @@ import org.robolectric.annotation.Config
class TroubleshootNotificationsViewTest : RobolectricTest() {
@Test
fun `press menu back invokes the expected callback`() = runAndroidComposeUiTest {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>(expectEvents = false)
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvent>(expectEvents = false)
ensureCalledOnce {
setTroubleshootNotificationsView(
state = aTroubleshootNotificationsState(
@@ -41,20 +41,20 @@ class TroubleshootNotificationsViewTest : RobolectricTest() {
@Test
fun `clicking on run test emits the expected Event`() = runAndroidComposeUiTest {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvent>()
setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
eventSink = eventsRecorder
),
)
onNodeWithText("Run tests").performClick()
eventsRecorder.assertSingle(TroubleshootNotificationsEvents.StartTests)
eventsRecorder.assertSingle(TroubleshootNotificationsEvent.StartTests)
}
@Config(qualifiers = "h1024dp")
@Test
fun `clicking on run test again emits the expected Event`() = runAndroidComposeUiTest {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvent>()
setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
tests = listOf(
@@ -68,8 +68,8 @@ class TroubleshootNotificationsViewTest : RobolectricTest() {
onNodeWithText("Run tests again").performClick()
eventsRecorder.assertList(
listOf(
TroubleshootNotificationsEvents.RetryFailedTests,
TroubleshootNotificationsEvents.StartTests,
TroubleshootNotificationsEvent.RetryFailedTests,
TroubleshootNotificationsEvent.StartTests,
)
)
}
@@ -77,7 +77,7 @@ class TroubleshootNotificationsViewTest : RobolectricTest() {
@Config(qualifiers = "h1024dp")
@Test
fun `clicking on quick fix emits the expected Event`() = runAndroidComposeUiTest {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvent>()
setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
tests = listOf(
@@ -91,8 +91,8 @@ class TroubleshootNotificationsViewTest : RobolectricTest() {
onNodeWithText("Attempt to fix").performClick()
eventsRecorder.assertList(
listOf(
TroubleshootNotificationsEvents.RetryFailedTests,
TroubleshootNotificationsEvents.QuickFix(0),
TroubleshootNotificationsEvent.RetryFailedTests,
TroubleshootNotificationsEvent.QuickFix(0),
)
)
}