From 796fb9b483228c21189c5429fbd927bd98eed03a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 6 Feb 2024 09:01:59 +0100 Subject: [PATCH] Fix test now that the send button is always enabled but can fail if description is too short. --- .../impl/bugreport/BugReportPresenterTest.kt | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenterTest.kt b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenterTest.kt index 8b9b5dbe89..7d6f16d412 100644 --- a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenterTest.kt +++ b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenterTest.kt @@ -54,7 +54,7 @@ class BugReportPresenterTest { assertThat(initialState.sending).isEqualTo(AsyncAction.Uninitialized) assertThat(initialState.screenshotUri).isNull() assertThat(initialState.sendingProgress).isEqualTo(0f) - assertThat(initialState.submitEnabled).isFalse() + assertThat(initialState.submitEnabled).isTrue() } } @@ -66,7 +66,7 @@ class BugReportPresenterTest { }.test { val initialState = awaitItem() initialState.eventSink.invoke(BugReportEvents.SetDescription(A_SHORT_DESCRIPTION)) - assertThat(awaitItem().submitEnabled).isFalse() + assertThat(awaitItem().submitEnabled).isTrue() initialState.eventSink.invoke(BugReportEvents.SetDescription(A_LONG_DESCRIPTION)) assertThat(awaitItem().submitEnabled).isTrue() } @@ -146,6 +146,8 @@ class BugReportPresenterTest { presenter.present() }.test { val initialState = awaitItem() + initialState.eventSink.invoke(BugReportEvents.SetDescription(A_LONG_DESCRIPTION)) + skipItems(1) initialState.eventSink.invoke(BugReportEvents.SendBugReport) skipItems(1) val progressState = awaitItem() @@ -170,6 +172,8 @@ class BugReportPresenterTest { presenter.present() }.test { val initialState = awaitItem() + initialState.eventSink.invoke(BugReportEvents.SetDescription(A_LONG_DESCRIPTION)) + skipItems(1) initialState.eventSink.invoke(BugReportEvents.SendBugReport) skipItems(1) val progressState = awaitItem() @@ -187,6 +191,25 @@ class BugReportPresenterTest { } } + @Test + fun `present - send failure description too short`() = runTest { + val presenter = createPresenter() + moleculeFlow(RecompositionMode.Immediate) { + presenter.present() + }.test { + val initialState = awaitItem() + initialState.eventSink.invoke(BugReportEvents.SetDescription(A_SHORT_DESCRIPTION)) + skipItems(1) + initialState.eventSink.invoke(BugReportEvents.SendBugReport) + val errorState = awaitItem() + assertThat(errorState.sending).isEqualTo(AsyncAction.Failure(BugReportFormError.DescriptionTooShort)) + // Reset failure + initialState.eventSink.invoke(BugReportEvents.ClearError) + val lastItem = awaitItem() + assertThat(lastItem.sending).isInstanceOf(AsyncAction.Uninitialized::class.java) + } + } + @Test fun `present - send cancel`() = runTest { val presenter = createPresenter( @@ -198,6 +221,8 @@ class BugReportPresenterTest { presenter.present() }.test { val initialState = awaitItem() + initialState.eventSink.invoke(BugReportEvents.SetDescription(A_LONG_DESCRIPTION)) + skipItems(1) initialState.eventSink.invoke(BugReportEvents.SendBugReport) skipItems(1) val progressState = awaitItem()