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