Stronger lambda error (#4771)
* Make sure lambdaError() make the test fail in all circumstances. * Fix existing errors on tests. * Uniformize the way we are creating class under test. * Cleanup * Fix typo * Fix failing test after rebase.
This commit is contained in:
parent
5b9da3c41b
commit
4572419ed2
19 changed files with 289 additions and 279 deletions
|
|
@ -513,7 +513,17 @@ class AttachmentsPreviewPresenterTest {
|
|||
@Test
|
||||
fun `present - dismissing the progress dialog stops media upload with media queue`() = runTest {
|
||||
val onDoneListenerResult = lambdaRecorder<Unit> {}
|
||||
val presenter = createAttachmentsPreviewPresenter(mediaUploadOnSendQueueEnabled = true, onDoneListener = onDoneListenerResult)
|
||||
val presenter = createAttachmentsPreviewPresenter(
|
||||
room = FakeJoinedRoom(
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendFileLambda = { _, _, _, _, _, _ ->
|
||||
Result.success(FakeMediaUploadHandler())
|
||||
}
|
||||
}
|
||||
),
|
||||
mediaUploadOnSendQueueEnabled = true,
|
||||
onDoneListener = onDoneListenerResult,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import io.element.android.libraries.matrix.test.timeline.FakeTimeline
|
|||
import io.element.android.libraries.matrix.test.timeline.LiveTimelineProvider
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
|
@ -91,13 +91,12 @@ class ForwardMessagesPresenterTest {
|
|||
}
|
||||
}
|
||||
|
||||
private fun CoroutineScope.aForwardMessagesPresenter(
|
||||
private fun TestScope.aForwardMessagesPresenter(
|
||||
eventId: EventId = AN_EVENT_ID,
|
||||
fakeRoom: FakeJoinedRoom = FakeJoinedRoom(),
|
||||
coroutineScope: CoroutineScope = this,
|
||||
) = ForwardMessagesPresenter(
|
||||
eventId = eventId.value,
|
||||
timelineProvider = LiveTimelineProvider(fakeRoom),
|
||||
appCoroutineScope = coroutineScope,
|
||||
appCoroutineScope = this,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import io.element.android.libraries.matrix.test.A_USER_ID
|
|||
import io.element.android.libraries.matrix.test.A_USER_ID_2
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID_3
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID_4
|
||||
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler
|
||||
import io.element.android.libraries.matrix.test.permalink.FakePermalinkBuilder
|
||||
import io.element.android.libraries.matrix.test.permalink.FakePermalinkParser
|
||||
import io.element.android.libraries.matrix.test.room.FakeBaseRoom
|
||||
|
|
@ -101,8 +102,8 @@ import io.element.android.tests.testutils.waitForPredicate
|
|||
import io.mockk.mockk
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.advanceUntilIdle
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
|
|
@ -132,7 +133,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - initial state`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -147,7 +148,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - toggle fullscreen`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -163,7 +164,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - change message`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -186,7 +187,6 @@ class MessageComposerPresenterTest {
|
|||
this.saveDraftLambda = updateDraftLambda
|
||||
}
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
draftService = draftService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -229,7 +229,6 @@ class MessageComposerPresenterTest {
|
|||
this.saveDraftLambda = updateDraftLambda
|
||||
}
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
draftService = draftService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -273,7 +272,6 @@ class MessageComposerPresenterTest {
|
|||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = joinedRoom,
|
||||
isRichTextEditorEnabled = false,
|
||||
)
|
||||
|
|
@ -314,7 +312,6 @@ class MessageComposerPresenterTest {
|
|||
this.saveDraftLambda = updateDraftLambda
|
||||
}
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
draftService = draftService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -346,7 +343,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - change mode to reply`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -362,7 +359,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - cancel reply`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -382,7 +379,6 @@ class MessageComposerPresenterTest {
|
|||
@Test
|
||||
fun `present - send message with rich text enabled`() = runTest {
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = FakeJoinedRoom(
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendMessageLambda = { _, _, _ -> Result.success(Unit) }
|
||||
|
|
@ -417,7 +413,6 @@ class MessageComposerPresenterTest {
|
|||
fun `present - send message with plain text enabled`() = runTest {
|
||||
val permalinkBuilder = FakePermalinkBuilder(permalinkForUserLambda = { Result.success("") })
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
isRichTextEditorEnabled = false,
|
||||
room = FakeJoinedRoom(
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
|
|
@ -464,7 +459,6 @@ class MessageComposerPresenterTest {
|
|||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
this,
|
||||
joinedRoom,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -520,7 +514,6 @@ class MessageComposerPresenterTest {
|
|||
editMessageLambda = roomEditMessageLambda,
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
this,
|
||||
joinedRoom,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -576,7 +569,6 @@ class MessageComposerPresenterTest {
|
|||
typingNoticeResult = { Result.success(Unit) },
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
this,
|
||||
joinedRoom,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -628,7 +620,6 @@ class MessageComposerPresenterTest {
|
|||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
this,
|
||||
joinedRoom,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -666,7 +657,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - Open attachments menu`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -679,7 +670,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - Dismiss attachments menu`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -702,7 +693,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
navigator = navigator,
|
||||
)
|
||||
|
|
@ -743,7 +733,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
navigator = navigator,
|
||||
)
|
||||
|
|
@ -777,7 +766,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - Pick media from gallery & cancel does nothing`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
with(pickerProvider) {
|
||||
givenResult(null) // Simulate a user canceling the flow
|
||||
givenMimeType(MimeTypes.Images)
|
||||
|
|
@ -801,7 +790,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
navigator = navigator,
|
||||
)
|
||||
|
|
@ -819,7 +807,7 @@ class MessageComposerPresenterTest {
|
|||
val room = FakeJoinedRoom(
|
||||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(this, room = room)
|
||||
val presenter = createPresenter(room = room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -838,7 +826,7 @@ class MessageComposerPresenterTest {
|
|||
val room = FakeJoinedRoom(
|
||||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(this, room = room)
|
||||
val presenter = createPresenter(room = room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -863,7 +851,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
permissionPresenter = permissionPresenter,
|
||||
navigator = navigator,
|
||||
|
|
@ -888,7 +875,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
permissionPresenter = permissionPresenter,
|
||||
navigator = navigator,
|
||||
|
|
@ -915,7 +901,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
permissionPresenter = permissionPresenter,
|
||||
navigator = navigator,
|
||||
|
|
@ -940,7 +925,6 @@ class MessageComposerPresenterTest {
|
|||
onPreviewAttachmentLambda = onPreviewAttachmentLambda
|
||||
)
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
room = room,
|
||||
permissionPresenter = permissionPresenter,
|
||||
navigator = navigator,
|
||||
|
|
@ -961,7 +945,7 @@ class MessageComposerPresenterTest {
|
|||
@Test
|
||||
fun `present - errors are tracked`() = runTest {
|
||||
val testException = Exception("Test error")
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter()
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -973,7 +957,7 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - ToggleTextFormatting toggles text formatting`() = runTest {
|
||||
val presenter = createPresenter(this, isRichTextEditorEnabled = false)
|
||||
val presenter = createPresenter(isRichTextEditorEnabled = false)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1017,7 +1001,7 @@ class MessageComposerPresenterTest {
|
|||
)
|
||||
givenRoomInfo(aRoomInfo(isDirect = false))
|
||||
}
|
||||
val presenter = createPresenter(this, room)
|
||||
val presenter = createPresenter(room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1078,7 +1062,7 @@ class MessageComposerPresenterTest {
|
|||
)
|
||||
)
|
||||
}
|
||||
val presenter = createPresenter(this, room)
|
||||
val presenter = createPresenter(room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1094,7 +1078,6 @@ class MessageComposerPresenterTest {
|
|||
|
||||
fun `present - InsertSuggestion`() = runTest {
|
||||
val presenter = createPresenter(
|
||||
coroutineScope = this,
|
||||
permalinkBuilder = FakePermalinkBuilder(
|
||||
permalinkForUserLambda = {
|
||||
Result.success("https://matrix.to/#/${A_USER_ID_2.value}")
|
||||
|
|
@ -1134,7 +1117,7 @@ class MessageComposerPresenterTest {
|
|||
liveTimeline = timeline,
|
||||
typingNoticeResult = { Result.success(Unit) }
|
||||
)
|
||||
val presenter = createPresenter(room = room, coroutineScope = this)
|
||||
val presenter = createPresenter(room = room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1197,7 +1180,16 @@ class MessageComposerPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - send uri`() = runTest {
|
||||
val presenter = createPresenter(this)
|
||||
val presenter = createPresenter(
|
||||
room = FakeJoinedRoom(
|
||||
typingNoticeResult = { Result.success(Unit) },
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendFileLambda = { _, _, _, _, _, _ ->
|
||||
Result.success(FakeMediaUploadHandler())
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
val state = presenter.present()
|
||||
remember(state, state.textEditorState.messageHtml()) { state }
|
||||
|
|
@ -1214,7 +1206,7 @@ class MessageComposerPresenterTest {
|
|||
val room = FakeJoinedRoom(
|
||||
typingNoticeResult = typingNoticeResult,
|
||||
)
|
||||
val presenter = createPresenter(room = room, coroutineScope = this)
|
||||
val presenter = createPresenter(room = room)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1240,7 +1232,7 @@ class MessageComposerPresenterTest {
|
|||
val store = InMemorySessionPreferencesStore(
|
||||
isSendTypingNotificationsEnabled = false
|
||||
)
|
||||
val presenter = createPresenter(room = room, sessionPreferencesStore = store, coroutineScope = this)
|
||||
val presenter = createPresenter(room = room, sessionPreferencesStore = store)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1258,7 +1250,7 @@ class MessageComposerPresenterTest {
|
|||
val composerDraftService = FakeComposerDraftService().apply {
|
||||
this.loadDraftLambda = loadDraftLambda
|
||||
}
|
||||
val presenter = createPresenter(draftService = composerDraftService, coroutineScope = this)
|
||||
val presenter = createPresenter(draftService = composerDraftService)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1283,7 +1275,6 @@ class MessageComposerPresenterTest {
|
|||
val presenter = createPresenter(
|
||||
draftService = composerDraftService,
|
||||
permalinkBuilder = permalinkBuilder,
|
||||
coroutineScope = this
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
@ -1317,7 +1308,6 @@ class MessageComposerPresenterTest {
|
|||
val presenter = createPresenter(
|
||||
draftService = composerDraftService,
|
||||
permalinkBuilder = permalinkBuilder,
|
||||
coroutineScope = this
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
@ -1351,7 +1341,6 @@ class MessageComposerPresenterTest {
|
|||
val presenter = createPresenter(
|
||||
draftService = composerDraftService,
|
||||
permalinkBuilder = permalinkBuilder,
|
||||
coroutineScope = this
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
@ -1398,7 +1387,6 @@ class MessageComposerPresenterTest {
|
|||
room = room,
|
||||
draftService = composerDraftService,
|
||||
permalinkBuilder = permalinkBuilder,
|
||||
coroutineScope = this
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
@ -1428,7 +1416,7 @@ class MessageComposerPresenterTest {
|
|||
val composerDraftService = FakeComposerDraftService().apply {
|
||||
this.saveDraftLambda = saveDraftLambda
|
||||
}
|
||||
val presenter = createPresenter(draftService = composerDraftService, coroutineScope = this)
|
||||
val presenter = createPresenter(draftService = composerDraftService)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
|
|
@ -1452,7 +1440,6 @@ class MessageComposerPresenterTest {
|
|||
isRichTextEditorEnabled = false,
|
||||
draftService = composerDraftService,
|
||||
permalinkBuilder = permalinkBuilder,
|
||||
coroutineScope = this
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
val state = presenter.present()
|
||||
|
|
@ -1528,18 +1515,17 @@ class MessageComposerPresenterTest {
|
|||
return normalState
|
||||
}
|
||||
|
||||
private fun createPresenter(
|
||||
coroutineScope: CoroutineScope,
|
||||
private fun TestScope.createPresenter(
|
||||
room: JoinedRoom = FakeJoinedRoom(
|
||||
typingNoticeResult = { Result.success(Unit) }
|
||||
),
|
||||
navigator: MessagesNavigator = FakeMessagesNavigator(),
|
||||
pickerProvider: PickerProvider = this.pickerProvider,
|
||||
featureFlagService: FeatureFlagService = this.featureFlagService,
|
||||
pickerProvider: PickerProvider = this@MessageComposerPresenterTest.pickerProvider,
|
||||
featureFlagService: FeatureFlagService = this@MessageComposerPresenterTest.featureFlagService,
|
||||
locationService: LocationService = FakeLocationService(true),
|
||||
sessionPreferencesStore: SessionPreferencesStore = InMemorySessionPreferencesStore(),
|
||||
mediaPreProcessor: MediaPreProcessor = this.mediaPreProcessor,
|
||||
snackbarDispatcher: SnackbarDispatcher = this.snackbarDispatcher,
|
||||
mediaPreProcessor: MediaPreProcessor = this@MessageComposerPresenterTest.mediaPreProcessor,
|
||||
snackbarDispatcher: SnackbarDispatcher = this@MessageComposerPresenterTest.snackbarDispatcher,
|
||||
permissionPresenter: PermissionsPresenter = FakePermissionsPresenter(),
|
||||
permalinkBuilder: PermalinkBuilder = FakePermalinkBuilder(),
|
||||
permalinkParser: PermalinkParser = FakePermalinkParser(),
|
||||
|
|
@ -1553,7 +1539,7 @@ class MessageComposerPresenterTest {
|
|||
draftService: ComposerDraftService = FakeComposerDraftService(),
|
||||
) = MessageComposerPresenter(
|
||||
navigator = navigator,
|
||||
appCoroutineScope = coroutineScope,
|
||||
appCoroutineScope = this,
|
||||
room = room,
|
||||
mediaPickerProvider = pickerProvider,
|
||||
featureFlagService = featureFlagService,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue