diff --git a/compose/src/main/kotlin/io/github/kakaocup/compose/node/assertion/LazyListNodeAssertions.kt b/compose/src/main/kotlin/io/github/kakaocup/compose/node/assertion/LazyListNodeAssertions.kt index 537fa6b6..8601b448 100644 --- a/compose/src/main/kotlin/io/github/kakaocup/compose/node/assertion/LazyListNodeAssertions.kt +++ b/compose/src/main/kotlin/io/github/kakaocup/compose/node/assertion/LazyListNodeAssertions.kt @@ -4,9 +4,11 @@ import androidx.compose.ui.semantics.SemanticsPropertyKey import androidx.compose.ui.semantics.getOrNull import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert +import io.github.kakaocup.compose.exception.KakaoComposeException +import io.github.kakaocup.compose.utilities.checkNotNull interface LazyListNodeAssertions : NodeAssertions { - val lengthSemanticsPropertyKey: SemanticsPropertyKey + val lengthSemanticsPropertyKey: SemanticsPropertyKey? /** * Asserts that the lazy list length contains the given [length]. @@ -21,7 +23,9 @@ interface LazyListNodeAssertions : NodeAssertions { private fun hasLazyListLength(length: Int): SemanticsMatcher = SemanticsMatcher( "The length of the lazy list is expected to be ${length}, but the actual size is different" ) { node -> - val actualLength = node.config.getOrNull(lengthSemanticsPropertyKey) ?: error("Lazy list does not contain $lengthSemanticsPropertyKey modifier") + val actualLength = node.config.getOrNull( + lengthSemanticsPropertyKey ?: throw KakaoComposeException("lengthSemanticsPropertyKey not provided to `KLazyListNode` constructor") + ) ?: error("Lazy list does not contain $lengthSemanticsPropertyKey modifier") return@SemanticsMatcher actualLength == length } } diff --git a/compose/src/main/kotlin/io/github/kakaocup/compose/node/core/BaseNode.kt b/compose/src/main/kotlin/io/github/kakaocup/compose/node/core/BaseNode.kt index 68e37984..554988ef 100644 --- a/compose/src/main/kotlin/io/github/kakaocup/compose/node/core/BaseNode.kt +++ b/compose/src/main/kotlin/io/github/kakaocup/compose/node/core/BaseNode.kt @@ -88,4 +88,4 @@ abstract class BaseNode> constructor( return semanticsMatcherList.reduce { finalMatcher, matcher -> finalMatcher and matcher } } -} +} \ No newline at end of file diff --git a/compose/src/main/kotlin/io/github/kakaocup/compose/node/element/lazylist/KLazyListNode.kt b/compose/src/main/kotlin/io/github/kakaocup/compose/node/element/lazylist/KLazyListNode.kt index 573f4b33..dbbc1651 100644 --- a/compose/src/main/kotlin/io/github/kakaocup/compose/node/element/lazylist/KLazyListNode.kt +++ b/compose/src/main/kotlin/io/github/kakaocup/compose/node/element/lazylist/KLazyListNode.kt @@ -24,7 +24,7 @@ class KLazyListNode( nodeMatcher: NodeMatcher, itemTypeBuilder: KLazyListItemBuilder.() -> Unit, val positionMatcher: (position: Int) -> SemanticsMatcher, - override val lengthSemanticsPropertyKey: SemanticsPropertyKey, + override val lengthSemanticsPropertyKey: SemanticsPropertyKey? = null, ) : BaseNode(semanticsProvider, nodeMatcher), LazyListNodeAssertions { val semanticsMatcher = nodeMatcher.matcher @@ -37,6 +37,7 @@ class KLazyListNode( * @param viewBuilderAction ViewBuilder which will result in view's interaction * @param itemTypeBuilder Lambda with receiver where you pass your item providers * @param positionMatcher Lambda which finds node by given position + * @param lengthSemanticsPropertyKey SemanticsPropertyKey with length list size * * @see ViewBuilder */ @@ -45,7 +46,7 @@ class KLazyListNode( viewBuilderAction: ViewBuilder.() -> Unit, itemTypeBuilder: KLazyListItemBuilder.() -> Unit, positionMatcher: (position: Int) -> SemanticsMatcher, - lengthSemanticsPropertyKey: SemanticsPropertyKey + lengthSemanticsPropertyKey: SemanticsPropertyKey? = null ) : this( semanticsProvider = semanticsProvider, nodeMatcher = ViewBuilder().apply(viewBuilderAction).build(),