Do ClickableText composables support Modifier.test...
# compose-desktop
c
Do ClickableText composables support Modifier.testTag()? Below I have an example of what I want to do and beneath that the error message I am getting. Sample:
Copy code
ClickableText(
            text = "Awesome text",
            modifier = Modifier.testTag("SOME_TEST_TAG"),
            onClick = { ... }
        )
ErrorMessage:
Copy code
Failed to assert the following: (OnClick is defined)
Reason: Expected exactly '1' node but could not find any node that satisfies: (TestTag = 'SOME_TEST_TAG')
However, the unmerged tree contains '1' node that matches. Are you missing `useUnmergedNode = true` in your finder?
c
what do you see when you print out the node tree using:
Copy code
composeTestRule.onRoot().printToLog()
c
As
composeRule.onRoot().printToLog()
threw a
NotImplementedException
I used
.printToString()
which resulted in the following output:
Copy code
Printing with useUnmergedTree = 'false'
Node #1 at (l=0.0, t=0.0, r=1024.0, b=768.0)px
 |-Node #2 at (l=980.0, t=0.0, r=1024.0, b=44.0)px, Tag: 'TAG_A'
 | Focused = 'false'
 | Actions = [OnClick]
 | MergeDescendants = 'true'
 |-Node #5 at (l=332.0, t=285.0, r=692.0, b=332.0)px
 | Text = 'TEXT_A'
 | Actions = [GetTextLayoutResult]
 |-Node #6 at (l=426.0, t=348.0, r=598.0, b=364.0)px
 | Text = '[Add your first photo source:]'
 | Actions = [GetTextLayoutResult]
 |-Node #7 at (l=312.0, t=388.0, r=400.0, b=476.0)px
 |  |-Node #8 at (l=312.0, t=388.0, r=400.0, b=476.0)px, Tag: 'TAG_B'
 |    Focused = 'false'
 |    Text = 'TEXT_B'
 |    Actions = [OnClick, GetTextLayoutResult]
 |    MergeDescendants = 'true'
 |-Node #12 at (l=416.0, t=388.0, r=504.0, b=476.0)px
 |  |-Node #13 at (l=416.0, t=388.0, r=504.0, b=476.0)px, Tag: 'TAG_C'
 |    Focused = 'false'
 |    Text = 'TEXT_C'
 |    Actions = [OnClick, GetTextLayoutResult]
 |    MergeDescendants = 'true'
 |-Node #17 at (l=520.0, t=388.0, r=608.0, b=476.0)px, Tag: 'TAG_D'
 | Focused = 'false'
 | Text = 'TEXT_D'
 | Actions = [OnClick, GetTextLayoutResult]
 | MergeDescendants = 'true'
 |-Node #21 at (l=144.0, t=724.0, r=220.0, b=768.0)px, Tag: 'TAG_E'
 | Focused = 'false'
 | Text = 'TEXT_E'
 | Actions = [OnClick, GetTextLayoutResult]
 | MergeDescendants = 'true'
 |-Node #25 at (l=364.0, t=724.0, r=440.0, b=768.0)px, Tag: 'TAG_F'
 | Focused = 'false'
 | Text = 'TEXT_F'
 | Actions = [OnClick, GetTextLayoutResult]
 | MergeDescendants = 'true'
 |-Node #29 at (l=584.0, t=724.0, r=660.0, b=768.0)px, Tag: 'TAG_G'
 | Focused = 'false'
 | Text = 'TEXT_G'
 | Actions = [OnClick, GetTextLayoutResult]
 | MergeDescendants = 'true'
 |-Node #33 at (l=804.0, t=724.0, r=880.0, b=768.0)px, Tag: 'TAG_H'
 | Focused = 'false'
 | Text = 'TEXT_H'
 | Actions = [OnClick, GetTextLayoutResult]
 | MergeDescendants = 'true'
 |-Node #37 at (l=0.0, t=0.0, r=1024.0, b=768.0)px
   Focused = 'false'
   Text = 'TEXT_I'
   VerticalScrollAxisRange = 'ScrollAxisRange(value=0.0, maxValue=0.0, reverseScrolling=false)'
   Actions = [OnClick, GetTextLayoutResult, ScrollBy]
   MergeDescendants = 'true'
    |-Node #47 at (l=368.0, t=410.0, r=656.0, b=454.0)px, Tag: 'TAG_J'
    | Focused = 'false'
    | Text = 'TEXT_J'
    | Actions = [OnClick, GetTextLayoutResult]
    | MergeDescendants = 'true'
    |-Node #51 at (l=368.0, t=462.0, r=656.0, b=506.0)px, Tag: 'TAG_K'
    | Focused = 'false'
    | Text = 'TEXT_K'
    | Actions = [OnClick, GetTextLayoutResult]
    | MergeDescendants = 'true'
    |-Node #55 at (l=368.0, t=514.0, r=656.0, b=558.0)px, Tag: 'TAG_L'
      Focused = 'false'
      Text = 'TEXT_L'
      Actions = [OnClick, GetTextLayoutResult]
      MergeDescendants = 'true'

Failed to assert the following: (OnClick is defined)
Reason: Expected exactly '1' node but could not find any node that satisfies: (TestTag = 'SOME_TEST_TAG')
However, the unmerged tree contains '1' node that matches. Are you missing `useUnmergedNode = true` in your finder?

java.lang.AssertionError: Failed to assert the following: (OnClick is defined)
Reason: Expected exactly '1' node but could not find any node that satisfies: (TestTag = 'SOME_TEST_TAG')
However, the unmerged tree contains '1' node that matches. Are you missing `useUnmergedNode = true` in your finder?
I printed out every node except for the one with "SOME_TEST_TAG"
c
how bizarre, I'm out of my depth now!
z
Something is very fishy, printToLog shouldn’t throw. What version of compose are you using? Can you share repro code?
c
I am using Compose Multiplatform 1.1.1
Copy code
class OurAwesomeTests {

    @get:Rule
    val rule: ComposeContentTestRule = createComposeRule()

    private suspend fun initTestRule() {

        rule.setContent {
            ClickableText(
                text = AnnotatedString("Hello World"),
                modifier = Modifier.testTag("SOME_TEST_TAG"),
                onClick = { }
            )
        }

        rule.awaitIdle()
    }

    @Test
    @OptIn(ExperimentalCoroutinesApi::class)
    fun findMySpecialTag(): TestResult = runTest {

        initTestRule()

        rule.onRoot().printToLog("SOME_TEST_TAG")

        rule.onNodeWithTag("SOME_TEST_TAG").performClick()
    }
}
Throws
Copy code
An operation is not implemented.
kotlin.NotImplementedError: An operation is not implemented.
	at androidx.compose.ui.test.DesktopOutput_desktopKt.printToLog(DesktopOutput.desktop.kt:20)
	at androidx.compose.ui.test.OutputKt.printToLog(Output.kt:69)
	at androidx.compose.ui.test.OutputKt.printToLog$default(Output.kt:63)
	at eu.lindigkeit.someApplication.ui.OurAwesomeTests$findMySpecialTag$1.invokeSuspend(OurAwesomeTests.kt:43)
z
Oh, ok that actually makes sense I guess since there’s no standard logging api on desktop. I’m not sure about the semantics problem though, @Alexandre Elias [G] does anything ring a bell for you?
737 Views