-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea89435
commit 86d9761
Showing
6 changed files
with
352 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...atadog/android/sessionreplay/compose/internal/mappers/semantics/TabSemanticsNodeMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.compose.internal.mappers.semantics | ||
|
||
import androidx.compose.ui.semantics.SemanticsNode | ||
import com.datadog.android.sessionreplay.compose.internal.data.SemanticsWireframe | ||
import com.datadog.android.sessionreplay.compose.internal.data.UiContext | ||
import com.datadog.android.sessionreplay.compose.internal.utils.SemanticsUtils | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback | ||
import com.datadog.android.sessionreplay.utils.ColorStringFormatter | ||
|
||
internal class TabSemanticsNodeMapper( | ||
colorStringFormatter: ColorStringFormatter, | ||
private val semanticsUtils: SemanticsUtils = SemanticsUtils() | ||
) : AbstractSemanticsNodeMapper(colorStringFormatter, semanticsUtils) { | ||
|
||
override fun map( | ||
semanticsNode: SemanticsNode, | ||
parentContext: UiContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback | ||
): SemanticsWireframe { | ||
val parentFrames = resolveParentColor(semanticsNode) | ||
return SemanticsWireframe( | ||
wireframes = parentFrames, | ||
uiContext = parentContext | ||
) | ||
} | ||
|
||
private fun resolveParentColor(semanticsNode: SemanticsNode): List<MobileSegment.Wireframe> { | ||
val globalBounds = resolveBounds(semanticsNode) | ||
|
||
// TODO RUM-7082: Consider use `UiContext` to pass the color information | ||
var parentColor = semanticsNode.parent?.let { parent -> | ||
semanticsUtils.resolveBackgroundColor(parent)?.let { | ||
convertColor(it) | ||
} | ||
} | ||
|
||
// If parent color is not specified, it may be in the grandparent modifier info. | ||
if (parentColor == null) { | ||
parentColor = semanticsNode.parent?.parent?.let { grandParentNode -> | ||
semanticsUtils.resolveBackgroundColor(grandParentNode)?.let { | ||
convertColor(it) | ||
} | ||
} | ||
} | ||
|
||
val shapeStyle = MobileSegment.ShapeStyle(backgroundColor = parentColor) | ||
return MobileSegment.Wireframe.ShapeWireframe( | ||
id = semanticsNode.id.toLong(), | ||
x = globalBounds.x, | ||
y = globalBounds.y, | ||
width = globalBounds.width, | ||
height = globalBounds.height, | ||
shapeStyle = shapeStyle | ||
).let { listOf(it) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...og/android/sessionreplay/compose/internal/mappers/semantics/TabSemanticsNodeMapperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.compose.internal.mappers.semantics | ||
|
||
import androidx.compose.ui.semantics.SemanticsNode | ||
import com.datadog.android.sessionreplay.compose.internal.data.UiContext | ||
import com.datadog.android.sessionreplay.compose.test.elmyr.SessionReplayComposeForgeConfigurator | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback | ||
import fr.xgouchet.elmyr.Forge | ||
import fr.xgouchet.elmyr.annotation.Forgery | ||
import fr.xgouchet.elmyr.annotation.LongForgery | ||
import fr.xgouchet.elmyr.annotation.StringForgery | ||
import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.kotlin.doReturn | ||
import org.mockito.kotlin.whenever | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(MockitoExtension::class), | ||
ExtendWith(ForgeExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
@ForgeConfiguration(SessionReplayComposeForgeConfigurator::class) | ||
internal class TabSemanticsNodeMapperTest : AbstractCompositionGroupMapperTest() { | ||
|
||
private lateinit var testedTabSemanticsNodeMapper: TabSemanticsNodeMapper | ||
|
||
@Mock | ||
private lateinit var mockSemanticsNode: SemanticsNode | ||
|
||
@Mock | ||
private lateinit var mockParentNode: SemanticsNode | ||
|
||
@Mock | ||
private lateinit var mockAsyncJobStatusCallback: AsyncJobStatusCallback | ||
|
||
@LongForgery(min = 0xffffffff) | ||
var fakeBackgroundColor: Long = 0L | ||
|
||
@StringForgery(regex = "#[0-9A-F]{8}") | ||
lateinit var fakeBackgroundColorHexString: String | ||
|
||
@Forgery | ||
lateinit var fakeUiContext: UiContext | ||
|
||
@BeforeEach | ||
override fun `set up`(forge: Forge) { | ||
super.`set up`(forge) | ||
mockColorStringFormatter(fakeBackgroundColor, fakeBackgroundColorHexString) | ||
|
||
testedTabSemanticsNodeMapper = TabSemanticsNodeMapper( | ||
colorStringFormatter = mockColorStringFormatter, | ||
semanticsUtils = mockSemanticsUtils | ||
) | ||
} | ||
|
||
@Test | ||
fun `M return the correct wireframe W map`() { | ||
// Given | ||
val mockSemanticsNode = mockSemanticsNode() | ||
whenever(mockSemanticsUtils.resolveInnerBounds(mockSemanticsNode)) doReturn rectToBounds( | ||
fakeBounds, | ||
fakeDensity | ||
) | ||
whenever(mockSemanticsUtils.resolveBackgroundColor(mockParentNode)) doReturn fakeBackgroundColor | ||
whenever(mockSemanticsNode.parent).doReturn(mockParentNode) | ||
// When | ||
val actual = testedTabSemanticsNodeMapper.map( | ||
mockSemanticsNode, | ||
fakeUiContext, | ||
mockAsyncJobStatusCallback | ||
) | ||
|
||
// Then | ||
val expected = MobileSegment.Wireframe.ShapeWireframe( | ||
id = fakeSemanticsId.toLong(), | ||
x = (fakeBounds.left / fakeDensity).toLong(), | ||
y = (fakeBounds.top / fakeDensity).toLong(), | ||
width = (fakeBounds.size.width / fakeDensity).toLong(), | ||
height = (fakeBounds.size.height / fakeDensity).toLong(), | ||
shapeStyle = MobileSegment.ShapeStyle( | ||
backgroundColor = fakeBackgroundColorHexString | ||
) | ||
) | ||
assertThat(actual.wireframes).contains(expected) | ||
} | ||
|
||
private fun mockSemanticsNode(): SemanticsNode { | ||
return mockSemanticsNodeWithBound { | ||
whenever(mockSemanticsNode.layoutInfo).doReturn(mockLayoutInfo) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.