Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only suspendable send/recieve channel methods in tests #1421

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package androidx.compose.ui

import kotlin.math.abs
import kotlinx.browser.document
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import org.w3c.dom.HTMLCanvasElement
import org.w3c.dom.asList

Expand Down Expand Up @@ -47,4 +52,8 @@ internal interface OnCanvasTests {
throw AssertionError("Expected $expected but got $actual. Difference is more than the allowed delta $tolerance")
}
}
}

internal fun <T> Channel<T>.sendFromScope(value: T, scope: CoroutineScope = GlobalScope) {
scope.launch(Dispatchers.Unconfined) { send(value) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.platform.ViewConfiguration
import androidx.compose.ui.window.CanvasBasedWindow
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -61,8 +60,6 @@ class SelectionContainerTests : OnCanvasTests {
}

@Test
@Ignore
// TODO: Activate after fixing https://youtrack.jetbrains.com/issue/CMP-1580/Fix-flaky-tests
fun canSelectOneWordUsingDoubleClick() = runTest {
createCanvasAndAttach()
val syncChannel = Channel<Selection?>(
Expand All @@ -79,7 +76,7 @@ class SelectionContainerTests : OnCanvasTests {
selection = selection,
onSelectionChange = {
selection = it
syncChannel.trySend(it)
syncChannel.sendFromScope(it)
},
children = {
Column {
Expand Down Expand Up @@ -143,7 +140,7 @@ class SelectionContainerTests : OnCanvasTests {
selection = selection,
onSelectionChange = {
selection = it
syncChannel.trySend(it)
syncChannel.sendFromScope(it)
},
children = {
Column {
Expand Down Expand Up @@ -179,8 +176,6 @@ class SelectionContainerTests : OnCanvasTests {
}

@Test
@Ignore
// TODO: Activate after fixing https://youtrack.jetbrains.com/issue/CMP-1580/Fix-flaky-tests
fun twoSingleClicksDoNotTriggerSelection() = runTest {
createCanvasAndAttach()

Expand All @@ -199,7 +194,7 @@ class SelectionContainerTests : OnCanvasTests {
selection = selection,
onSelectionChange = {
selection = it
syncChannel.trySend(it)
syncChannel.sendFromScope(it)
selectionCallbackCounter++
},
children = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.window.CanvasBasedWindow
import kotlin.test.AfterTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -39,8 +38,6 @@ class TextTests : OnCanvasTests {
}

@Test
@Ignore
// TODO: Activate after fixing https://youtrack.jetbrains.com/issue/CMP-1580/Fix-flaky-tests
// https://github.com/JetBrains/compose-multiplatform/issues/4078
fun baselineShouldBeNotZero() = runTest {
val canvas = createCanvasAndAttach()
Expand All @@ -56,15 +53,15 @@ class TextTests : OnCanvasTests {
"Heading",
modifier = Modifier.alignByBaseline()
.onGloballyPositioned {
headingOnPositioned.trySend(it[FirstBaseline] / density)
headingOnPositioned.sendFromScope(it[FirstBaseline] / density)
},
style = MaterialTheme.typography.h4
)
Text(
" — Subtitle",
modifier = Modifier.alignByBaseline()
.onGloballyPositioned {
subtitleOnPositioned.trySend(it[FirstBaseline] / density)
subtitleOnPositioned.sendFromScope(it[FirstBaseline] / density)
},
style = MaterialTheme.typography.subtitle1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import androidx.compose.ui.events.createTouchEvent
import androidx.compose.ui.events.keyDownEvent
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.sendFromScope
import androidx.compose.ui.window.CanvasBasedWindow
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand All @@ -53,8 +53,6 @@ class TextInputTests : OnCanvasTests {
}

@Test
@Ignore
// TODO: Activate after fixing https://youtrack.jetbrains.com/issue/CMP-1580/Fix-flaky-tests
fun keyboardEventPassedToTextField() = runTest {

val textInputChannel = Channel<String>(
Expand All @@ -70,15 +68,15 @@ class TextInputTests : OnCanvasTests {
TextField(
value = "",
onValueChange = { value ->
textInputChannel.trySend(value)
textInputChannel.sendFromScope(value)
},
modifier = Modifier.focusRequester(firstFocusRequester)
)

TextField(
value = "",
onValueChange = { value ->
textInputChannel.trySend(value)
textInputChannel.sendFromScope(value)
},
modifier = Modifier.focusRequester(secondFocusRequester)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package androidx.compose.ui.window

import androidx.compose.ui.sendFromScope
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -63,7 +64,7 @@ class ComposeWindowLifecycleTest {

lifecycleOwner.lifecycle.addObserver(object : LifecycleEventObserver {
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
eventsChannel.trySend(event)
eventsChannel.sendFromScope(event)
}
})

Expand Down
Loading