Skip to content

Commit

Permalink
fix compose list assertion message
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ex committed Nov 24, 2023
1 parent 91767b4 commit 945028c
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.atiurin.ultron.core.compose.list

import androidx.compose.ui.semantics.*
import androidx.compose.ui.test.*
import androidx.compose.ui.semantics.SemanticsNode
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.onChildAt
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.performScrollToIndex
import androidx.compose.ui.test.performScrollToKey
import androidx.compose.ui.test.performScrollToNode
import com.atiurin.ultron.core.common.options.ContentDescriptionContainsOption
import com.atiurin.ultron.core.compose.config.UltronComposeConfig
import com.atiurin.ultron.core.compose.nodeinteraction.UltronComposeSemanticsNodeInteraction
Expand Down Expand Up @@ -59,6 +66,7 @@ class UltronComposeList(

inline fun <reified T : UltronComposeListItem> getFirstVisibleItem(): T = getVisibleItem(0)
inline fun <reified T : UltronComposeListItem> getLastVisibleItem(): T = getVisibleItem(getMatcher().execute { it.fetchSemanticsNode().children.lastIndex })

/**
* Provide a scope with references to list SemanticsNode and SemanticsNodeInteraction.
* It is possible to evaluate any action or assertion on this node.
Expand Down Expand Up @@ -124,6 +132,7 @@ class UltronComposeList(
listInteraction.performScrollToNode(itemMatcher)
}
}

fun scrollToIndex(index: Int) = apply { getMatcher().perform { it.performScrollToIndex(index) } }
fun scrollToKey(key: Any) = apply { getMatcher().perform { it.performScrollToKey(key) } }
fun assertIsDisplayed() = apply { getMatcher().withTimeout(getOperationTimeout()).assertIsDisplayed() }
Expand All @@ -137,21 +146,21 @@ class UltronComposeList(
fun assertNotEmpty() = apply {
AssertUtils.assertTrue(
{ getVisibleItemsCount() > 0 }, getOperationTimeout(),
"Compose list (${listMatcher.description}) is NOT empty"
{ "Compose list (${listMatcher.description}) is NOT empty" }
)
}

fun assertEmpty() = apply {
AssertUtils.assertTrue(
{ getVisibleItemsCount() == 0 }, getOperationTimeout(),
"Compose list (${listMatcher.description}) has no items (visible items count = ${getVisibleItemsCount()})"
{ "Compose list (${listMatcher.description}) has no items (visible items count = ${getVisibleItemsCount()})" }
)
}

fun assertVisibleItemsCount(expected: Int) = apply {
AssertUtils.assertTrue(
{ getVisibleItemsCount() == expected }, getOperationTimeout(),
"Compose list (${listMatcher.description}) has visible items count = $expected (actual visible items count = ${getVisibleItemsCount()})"
{ "Compose list (${listMatcher.description}) has visible items count = $expected (actual visible items count = ${getVisibleItemsCount()})" }
)
}

Expand Down

0 comments on commit 945028c

Please sign in to comment.