-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from KakaoCup/develop
Develop
- Loading branch information
Showing
21 changed files
with
1,512 additions
and
23 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
compose/src/main/kotlin/io/github/kakaocup/compose/node/assertion/ListNodeAssertions.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,40 @@ | ||
package io.github.kakaocup.compose.node.assertion | ||
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.node.assertion.NodeAssertions | ||
|
||
/** | ||
* Basic assertions for working with lists. | ||
*/ | ||
interface ListNodeAssertions : NodeAssertions { | ||
|
||
/** | ||
* Semantic property for the list length. | ||
*/ | ||
val lengthSemanticsPropertyKey: SemanticsPropertyKey<Int> | ||
|
||
/** | ||
* Checks that the length of the list is equal to [length]. | ||
* | ||
* @throws [AssertionError] if the list length is not equal to [length]. | ||
* @throws [IllegalStateException] if the list does not provide the [lengthSemanticsPropertyKey] property. | ||
*/ | ||
fun assertLengthEquals(length: Int) { | ||
delegate.check(NodeAssertions.ComposeBaseAssertionType.ASSERT_VALUE_EQUALS) { | ||
assert(hasListLength(length)) | ||
} | ||
} | ||
|
||
private fun hasListLength(length: Int): SemanticsMatcher { | ||
return SemanticsMatcher( | ||
"The length of the list is expected to be $length, but the actual size is different" | ||
) { node -> | ||
val actualLength = node.config.getOrNull(lengthSemanticsPropertyKey) | ||
?: error("List does not contain $lengthSemanticsPropertyKey modifier") | ||
|
||
actualLength == length | ||
} | ||
} | ||
} |
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
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
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
54 changes: 54 additions & 0 deletions
54
compose/src/main/kotlin/io/github/kakaocup/compose/node/element/list/KListItemNode.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,54 @@ | ||
package io.github.kakaocup.compose.node.element.list | ||
|
||
import androidx.compose.ui.semantics.SemanticsNode | ||
import androidx.compose.ui.test.SemanticsMatcher | ||
import io.github.kakaocup.compose.node.builder.NodeMatcher | ||
import io.github.kakaocup.compose.node.core.BaseNode | ||
import io.github.kakaocup.compose.utilities.checkNotNull | ||
import io.github.kakaocup.compose.utilities.orGlobal | ||
|
||
/** | ||
* Base class for all child nodes within [KListNode]. | ||
* | ||
* The constructor is declared as `protected` so that only inheritors have the right to call this constructor. | ||
* | ||
* Warning! Manually creating list items is **not necessary**. | ||
*/ | ||
open class KListItemNode<out T : KListItemNode<T>> protected constructor() : BaseNode<T>() { | ||
|
||
companion object { | ||
|
||
/** | ||
* Method for correctly initializing the necessary parameters of [BaseNode]. | ||
* This method allows us to keep the main constructor of the element empty, which greatly | ||
* simplifies the description of subclass elements. | ||
* | ||
* @param listNode The root node of the list within which we need to interact with the list item. | ||
* @param semanticsNode A list of key/value pairs associated with the layout node or its subtree. | ||
* @param useUnmergedTree If true, the unmerged semantic tree will be used to work with the node. | ||
*/ | ||
inline fun <reified T : KListItemNode<*>> newInstance( | ||
listNode: KListNode, | ||
semanticsNode: SemanticsNode, | ||
useUnmergedTree: Boolean, | ||
): T { | ||
val instance = T::class.java.getDeclaredConstructor().newInstance() | ||
|
||
instance.initSemantics( | ||
semanticsProvider = listNode.semanticsProvider.orGlobal().checkNotNull(), | ||
nodeMatcher = NodeMatcher( | ||
matcher = SemanticsMatcher( | ||
description = "Semantics node id = ${semanticsNode.id}", | ||
matcher = { it.id == semanticsNode.id }, | ||
), | ||
useUnmergedTree = useUnmergedTree, | ||
), | ||
parentNode = listNode, | ||
) | ||
|
||
return instance | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.