File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
1
import org.gradle.kotlin.dsl.support.zipTo
2
2
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
3
+ import org.jetbrains.compose.ExperimentalComposeLibrary
3
4
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
4
5
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
5
6
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
@@ -121,6 +122,9 @@ dependencies {
121
122
testImplementation(libs.mockitoKotlin)
122
123
testImplementation(libs.junitJupiter)
123
124
testImplementation(libs.junitJupiterParams)
125
+
126
+ @OptIn(ExperimentalComposeLibrary ::class )
127
+ testImplementation(compose.uiTest)
124
128
}
125
129
126
130
tasks.test {
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ class ReactiveProperties: Properties() {
32
32
}
33
33
34
34
operator fun get (key : String ): String? = getProperty(key)
35
+
36
+ operator fun set (key : String , value : String ) {
37
+ setProperty(key, value)
38
+ }
35
39
}
36
40
val LocalPreferences = compositionLocalOf<ReactiveProperties > { error(" No preferences provided" ) }
37
41
@OptIn(FlowPreview ::class )
@@ -53,7 +57,7 @@ fun PreferencesProvider(content: @Composable () -> Unit){
53
57
LaunchedEffect (properties) {
54
58
snapshotFlow { properties._stateMap .toMap() }
55
59
.dropWhile { it == initialState }
56
- .debounce(1000 )
60
+ .debounce(100 )
57
61
.collect {
58
62
preferencesFile.outputStream().use { output ->
59
63
output.write(
Original file line number Diff line number Diff line change
1
+ package processing.app
2
+
3
+ import androidx.compose.material.Button
4
+ import androidx.compose.material.Text
5
+ import androidx.compose.ui.Modifier
6
+ import androidx.compose.ui.platform.testTag
7
+ import androidx.compose.ui.test.*
8
+ import kotlin.test.Test
9
+
10
+ class PreferencesKtTest {
11
+ @OptIn(ExperimentalTestApi ::class )
12
+ @Test
13
+ fun testKeyReactivity () = runComposeUiTest {
14
+ val newValue = (0 .. Int .MAX_VALUE ).random().toString()
15
+ val testKey = " test.preferences.reactivity.$newValue "
16
+ setContent {
17
+ PreferencesProvider {
18
+ val preferences = LocalPreferences .current
19
+ Text (preferences[testKey] ? : " default" , modifier = Modifier .testTag(" text" ))
20
+
21
+ Button (onClick = {
22
+ preferences[testKey] = newValue
23
+ }, modifier = Modifier .testTag(" button" )) {
24
+ Text (" Change" )
25
+ }
26
+ }
27
+ }
28
+
29
+ onNodeWithTag(" text" ).assertTextEquals(" default" )
30
+ onNodeWithTag(" button" ).performClick()
31
+ onNodeWithTag(" text" ).assertTextEquals(newValue)
32
+ }
33
+
34
+ }
You can’t perform that action at this time.
0 commit comments