mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-11-04 02:53:06 +00:00
fix of build
This commit is contained in:
1 parent
a84a89fb5b
commit
997e03e232
3 files changed
+20
-18
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import org.w3c.dom.MutationObserverInit
|
||||
|
||||
/**
|
||||
* Creates options for [org.w3c.dom.MutationObserver] without adding unspecified properties.
|
||||
*
|
||||
@@ -18,7 +20,7 @@ fun MutationObserverOptions(
|
||||
attributeOldValue: Boolean? = null,
|
||||
characterDataOldValue: Boolean? = null,
|
||||
attributeFilter: Array<String>? = null
|
||||
): NativeMutationObserverInit = js("{}").unsafeCast<NativeMutationObserverInit>().apply {
|
||||
): MutationObserverInit = js("{}").unsafeCast<MutationObserverInit>().apply {
|
||||
if (childList != null) this.childList = childList
|
||||
if (attributes != null) this.attributes = attributes
|
||||
if (characterData != null) this.characterData = characterData
|
||||
|
||||
+8
-8
@@ -22,7 +22,7 @@ class MutationObserverBrowserTests {
|
||||
root.appendChild(nested)
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
observer.observe(root, MutationObserverInit(childList = true, subtree = true))
|
||||
observer.observe(root, MutationObserverOptions(childList = true, subtree = true))
|
||||
nested.appendChild(child)
|
||||
val record = observer.takeRecords().single()
|
||||
assertEquals("childList", record.type)
|
||||
@@ -45,7 +45,7 @@ class MutationObserverBrowserTests {
|
||||
target.setAttribute("data-state", "old")
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
observer.observe(target, MutationObserverInit(attributeFilter = arrayOf("data-state"), attributeOldValue = true))
|
||||
observer.observe(target, MutationObserverOptions(attributeFilter = arrayOf("data-state"), attributeOldValue = true))
|
||||
target.setAttribute("ignored", "value")
|
||||
target.setAttribute("data-state", "new")
|
||||
val record = observer.takeRecords().single()
|
||||
@@ -64,7 +64,7 @@ class MutationObserverBrowserTests {
|
||||
val target = document.createTextNode("old")
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
observer.observe(target, MutationObserverInit(characterDataOldValue = true))
|
||||
observer.observe(target, MutationObserverOptions(characterDataOldValue = true))
|
||||
target.data = "new"
|
||||
val record = observer.takeRecords().single()
|
||||
assertEquals("characterData", record.type)
|
||||
@@ -80,7 +80,7 @@ class MutationObserverBrowserTests {
|
||||
val target = document.createElement("div")
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
observer.observe(target, MutationObserverInit(childList = true, attributeFilter = null))
|
||||
observer.observe(target, MutationObserverOptions(childList = true, attributeFilter = null))
|
||||
target.appendChild(document.createElement("span"))
|
||||
assertEquals("childList", observer.takeRecords().single().type)
|
||||
} finally {
|
||||
@@ -93,7 +93,7 @@ class MutationObserverBrowserTests {
|
||||
val target = document.createElement("div")
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
observer.observe(target, MutationObserverInit(attributeFilter = emptyArray()))
|
||||
observer.observe(target, MutationObserverOptions(attributeFilter = emptyArray()))
|
||||
target.setAttribute("data-state", "new")
|
||||
assertTrue(observer.takeRecords().isEmpty())
|
||||
} finally {
|
||||
@@ -106,12 +106,12 @@ class MutationObserverBrowserTests {
|
||||
val target = document.createElement("div")
|
||||
val observer = MutationObserver { _, _ -> }
|
||||
try {
|
||||
assertFails { observer.observe(target, MutationObserverInit()) }
|
||||
assertFails { observer.observe(target, MutationObserverOptions()) }
|
||||
assertFails {
|
||||
observer.observe(target, MutationObserverInit(attributes = false, attributeFilter = arrayOf("class")))
|
||||
observer.observe(target, MutationObserverOptions(attributes = false, attributeFilter = arrayOf("class")))
|
||||
}
|
||||
assertFails {
|
||||
observer.observe(target, MutationObserverInit(characterData = false, characterDataOldValue = true))
|
||||
observer.observe(target, MutationObserverOptions(characterData = false, characterDataOldValue = true))
|
||||
}
|
||||
} finally {
|
||||
observer.disconnect()
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import org.w3c.dom.MutationObserverInit as NativeMutationObserverInit
|
||||
import org.w3c.dom.MutationObserverInit
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertSame
|
||||
|
||||
class MutationObserverInitTests {
|
||||
private fun keys(options: NativeMutationObserverInit): List<String> =
|
||||
private fun keys(@Suppress("unused") options: MutationObserverInit): List<String> =
|
||||
js("Object.keys(options)").unsafeCast<Array<String>>().sorted()
|
||||
|
||||
@Test
|
||||
fun emptyOptionsHaveNoProperties() {
|
||||
assertEquals(emptyList(), keys(MutationObserverInit()))
|
||||
assertEquals(emptyList(), keys(MutationObserverOptions()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun childListOptionsOmitUnspecifiedProperties() {
|
||||
val options = MutationObserverInit(childList = true, subtree = true)
|
||||
val options = MutationObserverOptions(childList = true, subtree = true)
|
||||
assertEquals(listOf("childList", "subtree"), keys(options))
|
||||
assertEquals(true, options.childList)
|
||||
assertEquals(true, options.subtree)
|
||||
@@ -25,7 +25,7 @@ class MutationObserverInitTests {
|
||||
|
||||
@Test
|
||||
fun explicitNullOptionsAreOmitted() {
|
||||
val options = MutationObserverInit(
|
||||
val options = MutationObserverOptions(
|
||||
childList = null,
|
||||
attributes = null,
|
||||
characterData = null,
|
||||
@@ -40,7 +40,7 @@ class MutationObserverInitTests {
|
||||
@Test
|
||||
fun explicitFalseAndEmptyFilterArePreserved() {
|
||||
val filter = emptyArray<String>()
|
||||
val options = MutationObserverInit(false, false, false, false, false, false, filter)
|
||||
val options = MutationObserverOptions(false, false, false, false, false, false, filter)
|
||||
assertEquals(
|
||||
listOf("attributeFilter", "attributeOldValue", "attributes", "characterData", "characterDataOldValue", "childList", "subtree"),
|
||||
keys(options)
|
||||
@@ -58,7 +58,7 @@ class MutationObserverInitTests {
|
||||
@Test
|
||||
fun filtersAndOldValueOptionsDoNotForceObservationFlags() {
|
||||
val filter = arrayOf("class", "data-state")
|
||||
val options = MutationObserverInit(
|
||||
val options = MutationObserverOptions(
|
||||
attributeFilter = filter,
|
||||
attributeOldValue = true,
|
||||
characterDataOldValue = true
|
||||
@@ -71,8 +71,8 @@ class MutationObserverInitTests {
|
||||
|
||||
@Test
|
||||
fun eachCallCreatesIndependentOptions() {
|
||||
val first = MutationObserverInit(childList = true)
|
||||
val second = MutationObserverInit(attributes = true)
|
||||
val first = MutationObserverOptions(childList = true)
|
||||
val second = MutationObserverOptions(attributes = true)
|
||||
first.subtree = true
|
||||
assertEquals(listOf("childList", "subtree"), keys(first))
|
||||
assertEquals(listOf("attributes"), keys(second))
|
||||
|
||||
Reference in new issue
Block a user