Fix tests.
This commit is contained in:
parent
1971d8842c
commit
3623b9d7fc
2 changed files with 92 additions and 40 deletions
|
|
@ -21,6 +21,7 @@ import io.element.android.features.messages.impl.attachments.preview.imageeditor
|
||||||
import io.element.android.features.messages.impl.attachments.preview.imageeditor.AttachmentImageEdits
|
import io.element.android.features.messages.impl.attachments.preview.imageeditor.AttachmentImageEdits
|
||||||
import io.element.android.features.messages.impl.attachments.preview.imageeditor.EditedLocalMedia
|
import io.element.android.features.messages.impl.attachments.preview.imageeditor.EditedLocalMedia
|
||||||
import io.element.android.features.messages.impl.attachments.preview.imageeditor.NormalizedCropRect
|
import io.element.android.features.messages.impl.attachments.preview.imageeditor.NormalizedCropRect
|
||||||
|
import io.element.android.features.messages.impl.attachments.preview.imageeditor.assertIsSimilarTo
|
||||||
import io.element.android.features.messages.impl.attachments.video.MediaOptimizationSelectorState
|
import io.element.android.features.messages.impl.attachments.video.MediaOptimizationSelectorState
|
||||||
import io.element.android.features.messages.impl.attachments.video.VideoCompressionPresetSelector
|
import io.element.android.features.messages.impl.attachments.video.VideoCompressionPresetSelector
|
||||||
import io.element.android.features.messages.impl.attachments.video.VideoUploadEstimation
|
import io.element.android.features.messages.impl.attachments.video.VideoUploadEstimation
|
||||||
|
|
@ -579,7 +580,7 @@ class AttachmentsPreviewPresenterTest {
|
||||||
|
|
||||||
editorState.eventSink(AttachmentsPreviewEvent.RotateImageToTheLeft)
|
editorState.eventSink(AttachmentsPreviewEvent.RotateImageToTheLeft)
|
||||||
val rotatedState = awaitItem()
|
val rotatedState = awaitItem()
|
||||||
assertThat(rotatedState.imageEditorState?.edits?.rotationQuarterTurns).isEqualTo(1)
|
assertThat(rotatedState.imageEditorState?.edits?.rotationQuarterTurns).isEqualTo(3)
|
||||||
|
|
||||||
rotatedState.eventSink(AttachmentsPreviewEvent.ApplyImageEdits)
|
rotatedState.eventSink(AttachmentsPreviewEvent.ApplyImageEdits)
|
||||||
assertThat(awaitItem().isApplyingImageEdits).isTrue()
|
assertThat(awaitItem().isApplyingImageEdits).isTrue()
|
||||||
|
|
@ -630,9 +631,16 @@ class AttachmentsPreviewPresenterTest {
|
||||||
|
|
||||||
appliedState.eventSink(AttachmentsPreviewEvent.OpenImageEditor)
|
appliedState.eventSink(AttachmentsPreviewEvent.OpenImageEditor)
|
||||||
val reopenedState = consumeItemsUntilPredicate { it.imageEditorState != null }.last()
|
val reopenedState = consumeItemsUntilPredicate { it.imageEditorState != null }.last()
|
||||||
assertThat(reopenedState.imageEditorState?.localMedia?.uri).isEqualTo(originalLocalMedia.uri)
|
assertThat(reopenedState.imageEditorState!!.localMedia.uri).isEqualTo(originalLocalMedia.uri)
|
||||||
assertThat(reopenedState.imageEditorState?.edits?.cropRect).isEqualTo(cropRect)
|
val rotatedCropRect = NormalizedCropRect(
|
||||||
assertThat(reopenedState.imageEditorState?.edits?.rotationDegrees).isEqualTo(90)
|
left = cropRect.top,
|
||||||
|
top = 1f - cropRect.right,
|
||||||
|
right = cropRect.bottom,
|
||||||
|
bottom = 1f - cropRect.left,
|
||||||
|
)
|
||||||
|
reopenedState.imageEditorState.edits.cropRect.assertIsSimilarTo(rotatedCropRect)
|
||||||
|
assertThat(reopenedState.imageEditorState.edits.rotationQuarterTurns).isEqualTo(3)
|
||||||
|
assertThat(reopenedState.imageEditorState.edits.rotationDegrees).isEqualTo(270)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = 0.3f,
|
deltaX = 0.3f,
|
||||||
deltaY = 0.1f,
|
deltaY = 0.1f,
|
||||||
)
|
)
|
||||||
assertThat(result.left).isEqualTo(rect.left)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.right).isEqualTo(rect.right)
|
NormalizedCropRect(
|
||||||
assertThat(result.bottom).isEqualTo(rect.bottom)
|
left = rect.left,
|
||||||
assertThat(result.top).isWithin(0.0001f).of(0.3f)
|
top = 0.3f,
|
||||||
|
right = rect.right,
|
||||||
|
bottom = rect.bottom,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -38,10 +42,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = 0.1f,
|
deltaX = 0.1f,
|
||||||
deltaY = 0.3f,
|
deltaY = 0.3f,
|
||||||
)
|
)
|
||||||
assertThat(result.top).isEqualTo(rect.top)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.right).isEqualTo(rect.right)
|
NormalizedCropRect(
|
||||||
assertThat(result.bottom).isEqualTo(rect.bottom)
|
left = 0.2f,
|
||||||
assertThat(result.left).isWithin(0.0001f).of(0.2f)
|
top = rect.top,
|
||||||
|
right = rect.right,
|
||||||
|
bottom = rect.bottom,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -51,10 +59,15 @@ class NormalizedCropRectTest {
|
||||||
deltaX = -0.1f,
|
deltaX = -0.1f,
|
||||||
deltaY = 0.3f,
|
deltaY = 0.3f,
|
||||||
)
|
)
|
||||||
assertThat(result.top).isEqualTo(rect.top)
|
val s = assertThat(result)
|
||||||
assertThat(result.left).isEqualTo(rect.left)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.bottom).isEqualTo(rect.bottom)
|
NormalizedCropRect(
|
||||||
assertThat(result.right).isWithin(0.0001f).of(0.6f)
|
left = rect.left,
|
||||||
|
top = rect.top,
|
||||||
|
right = 0.6f,
|
||||||
|
bottom = rect.bottom,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -64,10 +77,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = -0.1f,
|
deltaX = -0.1f,
|
||||||
deltaY = -0.3f,
|
deltaY = -0.3f,
|
||||||
)
|
)
|
||||||
assertThat(result.top).isEqualTo(rect.top)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.left).isEqualTo(rect.left)
|
NormalizedCropRect(
|
||||||
assertThat(result.right).isEqualTo(rect.right)
|
left = rect.left,
|
||||||
assertThat(result.bottom).isWithin(0.0001f).of(0.5f)
|
top = rect.top,
|
||||||
|
right = rect.right,
|
||||||
|
bottom = 0.5f,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -77,10 +94,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = 0.1f,
|
deltaX = 0.1f,
|
||||||
deltaY = 0.1f,
|
deltaY = 0.1f,
|
||||||
)
|
)
|
||||||
assertThat(result.top).isWithin(0.0001f).of(0.3f)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.left).isWithin(0.0001f).of(0.2f)
|
NormalizedCropRect(
|
||||||
assertThat(result.right).isEqualTo(rect.right)
|
left = 0.2f,
|
||||||
assertThat(result.bottom).isEqualTo(rect.bottom)
|
top = 0.3f,
|
||||||
|
right = rect.right,
|
||||||
|
bottom = rect.bottom,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -90,10 +111,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = -0.1f,
|
deltaX = -0.1f,
|
||||||
deltaY = 0.1f,
|
deltaY = 0.1f,
|
||||||
)
|
)
|
||||||
assertThat(result.top).isWithin(0.0001f).of(0.3f)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.right).isWithin(0.0001f).of(0.6f)
|
NormalizedCropRect(
|
||||||
assertThat(result.left).isEqualTo(rect.left)
|
left = rect.left,
|
||||||
assertThat(result.bottom).isEqualTo(rect.bottom)
|
top = 0.3f,
|
||||||
|
right = 0.6f,
|
||||||
|
bottom = rect.bottom,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -103,10 +128,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = 0.1f,
|
deltaX = 0.1f,
|
||||||
deltaY = -0.1f,
|
deltaY = -0.1f,
|
||||||
)
|
)
|
||||||
assertThat(result.bottom).isWithin(0.0001f).of(0.7f)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.left).isWithin(0.0001f).of(0.2f)
|
NormalizedCropRect(
|
||||||
assertThat(result.top).isEqualTo(rect.top)
|
left = 0.2f,
|
||||||
assertThat(result.right).isEqualTo(rect.right)
|
top = rect.top,
|
||||||
|
right = rect.right,
|
||||||
|
bottom = 0.7f,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -116,10 +145,14 @@ class NormalizedCropRectTest {
|
||||||
deltaX = -0.1f,
|
deltaX = -0.1f,
|
||||||
deltaY = -0.1f,
|
deltaY = -0.1f,
|
||||||
)
|
)
|
||||||
assertThat(result.bottom).isWithin(0.0001f).of(0.7f)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.right).isWithin(0.0001f).of(0.6f)
|
NormalizedCropRect(
|
||||||
assertThat(result.top).isEqualTo(rect.top)
|
left = rect.left,
|
||||||
assertThat(result.left).isEqualTo(rect.left)
|
top = rect.top,
|
||||||
|
right = 0.6f,
|
||||||
|
bottom = 0.7f,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -129,9 +162,20 @@ class NormalizedCropRectTest {
|
||||||
deltaX = 0.6f,
|
deltaX = 0.6f,
|
||||||
deltaY = 0.6f,
|
deltaY = 0.6f,
|
||||||
)
|
)
|
||||||
assertThat(result.left).isWithin(0.0001f).of(0.4f)
|
result.assertIsSimilarTo(
|
||||||
assertThat(result.top).isWithin(0.0001f).of(0.4f)
|
NormalizedCropRect(
|
||||||
assertThat(result.right).isWithin(0.0001f).of(1.0f)
|
left = 0.4f,
|
||||||
assertThat(result.bottom).isWithin(0.0001f).of(1.0f)
|
top = 0.4f,
|
||||||
|
right = 1.0f,
|
||||||
|
bottom = 1.0f,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun NormalizedCropRect.assertIsSimilarTo(expectedResult: NormalizedCropRect) {
|
||||||
|
assertThat(left).isWithin(0.0001f).of(expectedResult.left)
|
||||||
|
assertThat(top).isWithin(0.0001f).of(expectedResult.top)
|
||||||
|
assertThat(right).isWithin(0.0001f).of(expectedResult.right)
|
||||||
|
assertThat(bottom).isWithin(0.0001f).of(expectedResult.bottom)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue