Skip to content

Commit

Permalink
Minor improvements to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-saia-datadog committed Dec 10, 2024
1 parent be663eb commit f602b9b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import android.view.View
import android.widget.ImageView

object ImageViewUtils {
/**
* Resolves the absolute position on the screen of the given [View].
* @param view: the [View].
* @return the [Rect] representing the absolute position of the view.
*/
fun resolveParentRectAbsPosition(view: View): Rect {
val coords = IntArray(2)
// this will always have size >= 2
Expand All @@ -29,6 +34,14 @@ object ImageViewUtils {
)
}

/**
* Calculates the clipping [Rect] of the given child [Rect] using its parent [Rect] and
* the screen density.
* @param parentRect: the parent [Rect].
* @param childRect: the child [Rect].
* @param density: the screen density.
* @return the clipping [Rect].
*/
fun calculateClipping(parentRect: Rect, childRect: Rect, density: Float): Rect {
val left = if (childRect.left < parentRect.left) {
parentRect.left - childRect.left
Expand Down Expand Up @@ -58,6 +71,12 @@ object ImageViewUtils {
)
}

/**
* Resolves the [Drawable] content [Rect] using the given [ImageView] scale type.
* @param imageView: the [ImageView].
* @param drawable: the [Drawable].
* @return the resolved content [Rect].
*/
fun resolveContentRectWithScaling(
imageView: ImageView,
drawable: Drawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ internal fun Rect.toWireframeClip(): MobileSegment.WireframeClip {
this.left.toLong(),
this.right.toLong()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.annotation.UiThread
import com.datadog.android.api.InternalLogger
import com.datadog.android.internal.utils.ImageViewUtils
import com.datadog.android.internal.utils.densityNormalized
import com.datadog.android.sessionreplay.SessionReplay
import com.datadog.android.sessionreplay.internal.utils.toWireframeClip
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.recorder.MappingContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ internal class DefaultImageWireframeHelperTest {
customResourceIdCacheKey = null,
asyncJobStatusCallback = mockAsyncJobStatusCallback
)
wireframes[0] as MobileSegment.Wireframe.ImageWireframe

assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)

// Then
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
Expand Down Expand Up @@ -939,7 +940,8 @@ internal class DefaultImageWireframeHelperTest {
customResourceIdCacheKey = null,
asyncJobStatusCallback = mockAsyncJobStatusCallback
)
wireframes[0] as MobileSegment.Wireframe.ImageWireframe

assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)

// Then
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
Expand Down Expand Up @@ -1270,7 +1272,8 @@ internal class DefaultImageWireframeHelperTest {
customResourceIdCacheKey = null,
asyncJobStatusCallback = mockAsyncJobStatusCallback
)
wireframes[0] as MobileSegment.Wireframe.ImageWireframe

assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)

// Then
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
Expand Down Expand Up @@ -1318,7 +1321,8 @@ internal class DefaultImageWireframeHelperTest {
customResourceIdCacheKey = null,
asyncJobStatusCallback = mockAsyncJobStatusCallback
)
wireframes[0] as MobileSegment.Wireframe.ImageWireframe

assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)

// Then
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
Expand Down

0 comments on commit f602b9b

Please sign in to comment.