@@ -14,18 +14,34 @@ import org.jetbrains.compose.web.css.timingFunction
14
14
import org.jetbrains.compose.web.css.transitions
15
15
import org.jetbrains.compose.web.dom.Div
16
16
import org.jetbrains.compose.web.testutils.runTest
17
+ import org.w3c.dom.css.CSSStyleDeclaration
17
18
import kotlin.test.Test
18
19
import kotlin.test.assertEquals
19
20
20
21
@ExperimentalComposeWebApi
21
22
class TransitionsTests {
23
+
24
+ private fun CSSStyleDeclaration.computedTransition (): String {
25
+ val cssDelimiter = Regex (" ,\\ s*" )
26
+
27
+ // setting transition property affects subProperties, but we should check for them separately
28
+ val props = transitionProperty.split(cssDelimiter)
29
+ val durations = transitionDuration.split(cssDelimiter)
30
+ val timings = transitionTimingFunction.split(cssDelimiter)
31
+ val delays = transitionDelay.split(cssDelimiter)
32
+
33
+ return props.indices.joinToString(" , " ) { i ->
34
+ " ${props[i]} ${durations[i]} ${timings[i]} ${delays[i]} "
35
+ }
36
+ }
37
+
22
38
@Test
23
39
fun duration () = runTest {
24
40
composition {
25
41
Div ({ style { transitions { " width" { duration(1 .s) } }}})
26
42
}
27
43
28
- assertEquals(" width 1s ease 0s" , nextChild().style.transition )
44
+ assertEquals(" width 1s ease 0s" , nextChild().style.computedTransition() )
29
45
}
30
46
31
47
@Test
@@ -34,7 +50,7 @@ class TransitionsTests {
34
50
Div ({ style { transitions { " width" { duration(1 .s) }; " height" { duration(2 .s) } }}})
35
51
}
36
52
37
- assertEquals(" width 1s ease 0s, height 2s ease 0s" , nextChild().style.transition )
53
+ assertEquals(" width 1s ease 0s, height 2s ease 0s" , nextChild().style.computedTransition() )
38
54
}
39
55
40
56
@Test
@@ -43,7 +59,7 @@ class TransitionsTests {
43
59
Div ({ style { transitions { all { duration(1 .s) } }}})
44
60
}
45
61
46
- assertEquals(" all 1s ease 0s" , nextChild().style.transition )
62
+ assertEquals(" all 1s ease 0s" , nextChild().style.computedTransition() )
47
63
}
48
64
49
65
@Test
@@ -52,7 +68,7 @@ class TransitionsTests {
52
68
Div ({ style { transitions { " width" { duration(1 .s); timingFunction(AnimationTimingFunction .EaseInOut ) }}}})
53
69
}
54
70
55
- assertEquals(" width 1s ease-in-out 0s" , nextChild().style.transition )
71
+ assertEquals(" width 1s ease-in-out 0s" , nextChild().style.computedTransition() )
56
72
}
57
73
58
74
@Test
@@ -61,7 +77,7 @@ class TransitionsTests {
61
77
Div ({ style { transitions { " width" { duration(1 .s); delay(2 .s) }}}})
62
78
}
63
79
64
- assertEquals(" width 1s ease 2s" , nextChild().style.transition )
80
+ assertEquals(" width 1s ease 2s" , nextChild().style.computedTransition() )
65
81
}
66
82
67
83
@Test
@@ -73,8 +89,8 @@ class TransitionsTests {
73
89
Div ({ style { transitions { defaultDuration(1 .s); myList { duration(2 .s) }}}})
74
90
}
75
91
76
- assertEquals(" width 1s ease 0s, height 1s ease 0s" , nextChild().style.transition )
77
- assertEquals(" width 0s ease 0s, height 1s ease 0s, width 2s ease 0s" , nextChild().style.transition )
78
- assertEquals(" width 2s ease 0s, height 2s ease 0s" , nextChild().style.transition )
92
+ assertEquals(" width 1s ease 0s, height 1s ease 0s" , nextChild().style.computedTransition() )
93
+ assertEquals(" width 0s ease 0s, height 1s ease 0s, width 2s ease 0s" , nextChild().style.computedTransition() )
94
+ assertEquals(" width 2s ease 0s, height 2s ease 0s" , nextChild().style.computedTransition() )
79
95
}
80
96
}
0 commit comments