@momo-kits/native-kits 0.169.13-beta.4-debug → 0.169.13-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +1 -4
- package/compose/build.gradle.kts +1 -5
- package/compose/compose.podspec +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +12 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +11 -3
- package/gradle/libs.versions.toml +0 -2
- package/gradle.properties +1 -1
- package/ios/Navigation/BottomTab/BottomTabBar.swift +14 -4
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +16 -3
- package/package.json +1 -1
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +0 -647
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +0 -1411
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +0 -130
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +0 -524
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +0 -559
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +0 -741
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +0 -221
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +0 -270
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +0 -849
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +0 -212
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +0 -239
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +0 -252
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +0 -154
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +0 -1038
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +0 -848
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +0 -47
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +0 -463
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +0 -1146
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +0 -667
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +0 -240
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +0 -185
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +0 -200
- package/scripts/sdui-visual/README.md +0 -64
- package/scripts/sdui-visual/diff.py +0 -65
- package/scripts/sdui-visual/drive.py +0 -234
- package/scripts/sdui-visual/plan.json +0 -713
- package/scripts/sdui-visual/run.sh +0 -92
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt
|
|
2
|
-
// Created At: 2026-11-10 10:00:00 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-opus-5-5
|
|
6
|
-
|
|
7
|
-
package vn.momo.kits.sdui
|
|
8
|
-
|
|
9
|
-
import androidx.compose.runtime.mutableStateMapOf
|
|
10
|
-
import org.junit.Assert.assertEquals
|
|
11
|
-
import org.junit.Assert.assertFalse
|
|
12
|
-
import org.junit.Assert.assertNotEquals
|
|
13
|
-
import org.junit.Assert.assertNotSame
|
|
14
|
-
import org.junit.Assert.assertSame
|
|
15
|
-
import org.junit.Assert.assertTrue
|
|
16
|
-
import org.junit.Test
|
|
17
|
-
import vn.momo.kits.const.defaultTheme
|
|
18
|
-
|
|
19
|
-
// AI-GENERATED START: unit tests for resolving a child's styles once and for stable repeat-row scopes
|
|
20
|
-
class SduiRenderReuseTest {
|
|
21
|
-
private val state = mutableStateMapOf<String, Any?>()
|
|
22
|
-
private val sink = object : TrackSink {
|
|
23
|
-
override val id = "rec"
|
|
24
|
-
val records = mutableListOf<TrackRecord>()
|
|
25
|
-
override fun write(record: TrackRecord) { records += record }
|
|
26
|
-
}
|
|
27
|
-
private val session = Tracker(listOf(sink), "sess").begin(SessionCtx("sdui:view:t"))
|
|
28
|
-
private fun nodeErrors() = sink.records.filter { it.event.step == "sdui_node_error" }.map { it.event.fields }
|
|
29
|
-
private fun scopeOf(data: Map<String, Any?> = emptyMap()) = SduiScope(data, state, nodeErrors = NodeErrorSink { session })
|
|
30
|
-
private val ctx = SduiCtx(defaultTheme, state, { _, _, _, _, _, _, _ -> }, session = session)
|
|
31
|
-
|
|
32
|
-
// ---- styles resolved once per child ---------------------------------------------------------------------------
|
|
33
|
-
@Test fun layChildrenResolvesEachChildExactlyOnceAndSplitsAbsoluteOnes() {
|
|
34
|
-
val sc = scopeOf()
|
|
35
|
-
val kids = listOf(
|
|
36
|
-
mapOf("type" to "Text", "styles" to mapOf("flex" to 1L)),
|
|
37
|
-
mapOf("type" to "View", "styles" to mapOf("position" to "absolute", "top" to 4L)),
|
|
38
|
-
mapOf("type" to "Text"),
|
|
39
|
-
)
|
|
40
|
-
val all = expand(kids, sc, defaultTheme, null)
|
|
41
|
-
val calls = mutableListOf<Expanded>()
|
|
42
|
-
val (flow, abs) = layChildren(all) { calls += it; preStyOf(it.node, it.scope, ctx) }
|
|
43
|
-
assertEquals(all, calls) // once each, in order
|
|
44
|
-
assertEquals(listOf(0, 2), flow.map { it.e.index })
|
|
45
|
-
assertEquals(listOf(1), abs.map { it.e.index })
|
|
46
|
-
assertTrue(flow[0].pre.sty.isFlexOne)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Test fun aPreResolvedStyleReportsNothingUntilTheChildUsesItThenOnceOnItsOwnPath() {
|
|
50
|
-
val sc = scopeOf()
|
|
51
|
-
val child = mapOf("type" to "Text", "id" to "t", "styles" to mapOf("backgroundColor" to "Colors.nope", "flex" to "{((}"))
|
|
52
|
-
val pre = preStyOf(child, sc, ctx)
|
|
53
|
-
assertTrue(nodeErrors().isEmpty())
|
|
54
|
-
assertEquals(setOf("unknown_token", "expr_failed"), pre.errors)
|
|
55
|
-
val sty = styOf(child, sc, ctx, "body.children.2", pre)
|
|
56
|
-
assertEquals(styOf(child, scopeOf(), ctx, null), sty) // same value as the child resolving it itself
|
|
57
|
-
assertEquals(listOf("body.children.2", "body.children.2"), nodeErrors().map { it["nodePath"] })
|
|
58
|
-
assertEquals(listOf("unknown_token", "expr_failed"), nodeErrors().map { it["code"] })
|
|
59
|
-
assertTrue(nodeErrors().all { it["nodeId"] == "t" && it["nodeType"] == "Text" })
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@Test fun aPreResolvedStyleReportsLikeTheChildsOwnResolution() {
|
|
63
|
-
val node = mapOf("type" to "View", "styles" to mapOf("padding" to "Spacing.ZZZ"))
|
|
64
|
-
styOf(node, scopeOf(), ctx, "body.children.0")
|
|
65
|
-
val own = nodeErrors()
|
|
66
|
-
sink.records.clear()
|
|
67
|
-
// another path: the session reports a path / code / reason once
|
|
68
|
-
styOf(node, scopeOf(), ctx, "body.children.1", preStyOf(node, scopeOf(), ctx))
|
|
69
|
-
assertEquals(1, own.size)
|
|
70
|
-
assertEquals(own.map { it + ("nodePath" to "body.children.1") }, nodeErrors())
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ---- styles that are accepted but ignored (text keys, alignSelf) ------------------------------------------------
|
|
74
|
-
@Test fun anIgnoredStyleKeyReportsOnceOnTheNodesOwnPathAndLeavesThePlanAlone() {
|
|
75
|
-
val lines = mutableListOf<String>()
|
|
76
|
-
val c = SduiCtx(defaultTheme, state, { _, _, _, _, _, _, _ -> }, session = session, log = capturingLog(lines))
|
|
77
|
-
val node = mapOf("type" to "View", "id" to "v", "styles" to mapOf("fontWeight" to "bold", "padding" to 4L))
|
|
78
|
-
val sc = scopeOf()
|
|
79
|
-
val sty = styOf(node, sc, c, "body.children.1")
|
|
80
|
-
repeat(3) { styOf(node, sc, c, "body.children.1") } // recompositions
|
|
81
|
-
styOf(node, sc, c, "body.children.1", preStyOf(node, sc, c)) // a parent that resolved it for layout
|
|
82
|
-
assertEquals(
|
|
83
|
-
listOf(mapOf("step" to "sdui_node_error", "code" to "unsupported_style", "reason" to "fontWeight", "nodePath" to "body.children.1",
|
|
84
|
-
"nodeId" to "v", "nodeType" to "View")),
|
|
85
|
-
nodeErrors(),
|
|
86
|
-
)
|
|
87
|
-
assertEquals(1, lines.size)
|
|
88
|
-
assertTrue(lines[0], lines[0].endsWith("body.children.1: styles.fontWeight is ignored; use props.typography/props.color"))
|
|
89
|
-
assertFalse(lines[0].contains("bold")) // the value never reaches the log
|
|
90
|
-
// still drawn: the plan is exactly the one without the key
|
|
91
|
-
assertEquals(stylePlanOf(Sty(mapOf("padding" to 4L)), stretch = true), stylePlanOf(sty, stretch = true))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@Test fun eachIgnoredKeyReportsItsOwnReasonAndAlignSelfItsOwnHint() {
|
|
95
|
-
val lines = mutableListOf<String>()
|
|
96
|
-
val c = SduiCtx(defaultTheme, state, { _, _, _, _, _, _, _ -> }, session = session, log = capturingLog(lines))
|
|
97
|
-
val node = mapOf("type" to "Text", "styles" to mapOf("color" to "#fff", "fontSize" to 14L, "alignSelf" to "center", "margin" to 2L))
|
|
98
|
-
styOf(node, scopeOf(), c, "body")
|
|
99
|
-
assertEquals(listOf("fontSize", "color", "alignSelf"), nodeErrors().map { it["reason"] })
|
|
100
|
-
assertTrue(nodeErrors().all { it["code"] == "unsupported_style" && it["nodePath"] == "body" })
|
|
101
|
-
assertTrue(lines.any { it.endsWith("body: styles.alignSelf is ignored; use the parent's alignItems") })
|
|
102
|
-
assertEquals(3, lines.size)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@Test fun anIgnoredStyleIsNotReportedByAQuietProbeNorByAParentResolvingIt() {
|
|
106
|
-
val node = mapOf("type" to "Text", "styles" to mapOf("lineHeight" to 20L))
|
|
107
|
-
styOf(node, scopeOf(), ctx, null)
|
|
108
|
-
preStyOf(node, scopeOf(), ctx)
|
|
109
|
-
assertTrue(nodeErrors().isEmpty())
|
|
110
|
-
// a whole-binding styles map is checked once resolved
|
|
111
|
-
val bound = mapOf("type" to "View", "styles" to "{s}")
|
|
112
|
-
styOf(bound, scopeOf(mapOf("s" to mapOf("letterSpacing" to 1L))), ctx, "body.children.0")
|
|
113
|
-
assertEquals(listOf("letterSpacing"), nodeErrors().map { it["reason"] })
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@Test fun eachRepeatCopyGetsTheStylesOfItsOwnScope() {
|
|
117
|
-
val sc = scopeOf(mapOf("rows" to listOf(mapOf("w" to 10L), mapOf("w" to 20L))))
|
|
118
|
-
val node = mapOf("type" to "View", "repeat" to mapOf("source" to "rows", "as" to "r"), "styles" to mapOf("width" to "{r.w}"))
|
|
119
|
-
val (flow, _) = layChildren(expand(listOf(node), sc, defaultTheme, null)) { preStyOf(it.node, it.scope, ctx) }
|
|
120
|
-
assertEquals(listOf(10L, 20L), flow.map { it.pre.sty.m["width"] })
|
|
121
|
-
flow.forEach { assertEquals(styOf(it.e.node, it.e.scope, ctx, null), it.pre.sty) }
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@Test fun styAndPreStyCompareByValue() {
|
|
125
|
-
assertEquals(Sty(mapOf("a" to 1L)), Sty(mapOf("a" to 1L)))
|
|
126
|
-
assertNotEquals(Sty(mapOf("a" to 1L)), Sty(mapOf("a" to 2L)))
|
|
127
|
-
assertEquals(PreSty(Sty(mapOf("a" to 1L)), setOf("x")), PreSty(Sty(mapOf("a" to 1L)), setOf("x")))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ---- stable repeat-row scopes --------------------------------------------------------------------------------
|
|
131
|
-
private val row = mapOf("type" to "Text", "repeat" to mapOf("source" to "{state.rows}", "as" to "r", "index" to "i"), "props" to mapOf("children" to "{r.t}"))
|
|
132
|
-
private fun rows(vararg t: String) = t.map { mapOf("t" to it) }
|
|
133
|
-
|
|
134
|
-
@Test fun unchangedRowsKeepTheirScopeAndTheListIsReused() {
|
|
135
|
-
state["rows"] = rows("a", "b", "c")
|
|
136
|
-
val sc = scopeOf(); val cache = ExpandCache(); val nodes = listOf(row, mapOf("type" to "Text"))
|
|
137
|
-
val first = expand(nodes, sc, defaultTheme, null, cache)
|
|
138
|
-
val second = expand(nodes, sc, defaultTheme, null, cache)
|
|
139
|
-
assertSame(first, second)
|
|
140
|
-
assertEquals(4, second.size)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
@Test fun anEqualItemThatIsANewInstanceKeepsTheScope() {
|
|
144
|
-
state["rows"] = rows("a", "b")
|
|
145
|
-
val sc = scopeOf(); val cache = ExpandCache()
|
|
146
|
-
val first = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
147
|
-
state["rows"] = rows("a", "b") // e.g. a filter / map expression re-run
|
|
148
|
-
val second = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
149
|
-
assertSame(first[0].scope, second[0].scope); assertSame(first[1].scope, second[1].scope)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
@Test fun aChangedItemGetsANewScopeOthersKeepTheirs() {
|
|
153
|
-
state["rows"] = rows("a", "b", "c")
|
|
154
|
-
val sc = scopeOf(); val cache = ExpandCache()
|
|
155
|
-
val first = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
156
|
-
state["rows"] = rows("a", "B", "c")
|
|
157
|
-
val second = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
158
|
-
assertSame(first[0].scope, second[0].scope); assertSame(first[2].scope, second[2].scope)
|
|
159
|
-
assertNotSame(first[1].scope, second[1].scope)
|
|
160
|
-
assertEquals("B", evalExpr("r.t", second[1].scope))
|
|
161
|
-
assertEquals(1L, evalExpr("i", second[1].scope))
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
@Test fun anInsertedRowShiftsTheItemsSoShiftedRowsGetNewScopesWithTheirNewIndex() {
|
|
165
|
-
state["rows"] = rows("a", "b")
|
|
166
|
-
val sc = scopeOf(); val cache = ExpandCache()
|
|
167
|
-
expand(listOf(row), sc, defaultTheme, null, cache)
|
|
168
|
-
state["rows"] = rows("z", "a", "b")
|
|
169
|
-
val second = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
170
|
-
assertEquals(listOf("z", "a", "b"), second.map { evalExpr("r.t", it.scope) })
|
|
171
|
-
assertEquals(listOf(0L, 1L, 2L), second.map { evalExpr("i", it.scope) })
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@Test fun aNewParentScopeOrSpecNodeGivesNewRows() {
|
|
175
|
-
state["rows"] = rows("a")
|
|
176
|
-
val cache = ExpandCache(); val sc = scopeOf()
|
|
177
|
-
val first = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
178
|
-
val otherParent = expand(listOf(row), sc.with("x", 1L), defaultTheme, null, cache)
|
|
179
|
-
assertNotSame(first[0].scope, otherParent[0].scope)
|
|
180
|
-
assertEquals(1L, evalExpr("x", otherParent[0].scope))
|
|
181
|
-
val otherNode = expand(listOf(row + ("id" to "n2")), sc, defaultTheme, null, cache)
|
|
182
|
-
assertNotSame(otherParent[0].scope, otherNode[0].scope)
|
|
183
|
-
assertEquals("n2", otherNode[0].node["id"])
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
@Test fun visibleIsStillEvaluatedEveryTimeAndAHiddenRowComesBackWithItsScope() {
|
|
187
|
-
state["rows"] = rows("a", "b"); state["hide"] = ""
|
|
188
|
-
val node = row + ("visible" to "{r.t != state.hide}")
|
|
189
|
-
val sc = scopeOf(); val cache = ExpandCache()
|
|
190
|
-
val first = expand(listOf(node), sc, defaultTheme, null, cache)
|
|
191
|
-
state["hide"] = "b"
|
|
192
|
-
assertEquals(listOf("a"), expand(listOf(node), sc, defaultTheme, null, cache).map { evalExpr("r.t", it.scope) })
|
|
193
|
-
state["hide"] = ""
|
|
194
|
-
val third = expand(listOf(node), sc, defaultTheme, null, cache)
|
|
195
|
-
assertSame(first[1].scope, third[1].scope)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@Test fun cachedExpansionStillReportsBrokenVisibleOnTheChildPath() {
|
|
199
|
-
val cache = ExpandCache(); val sc = scopeOf()
|
|
200
|
-
val kids = listOf(mapOf("type" to "Text", "visible" to "{((}"))
|
|
201
|
-
expand(kids, sc, defaultTheme, "body.children.3", cache)
|
|
202
|
-
assertEquals(listOf("body.children.3.children.0"), nodeErrors().map { it["nodePath"] })
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
@Test fun withoutACacheEveryExpansionMakesNewScopes() {
|
|
206
|
-
state["rows"] = rows("a")
|
|
207
|
-
val sc = scopeOf()
|
|
208
|
-
assertNotSame(expand(listOf(row), sc, defaultTheme, null)[0].scope, expand(listOf(row), sc, defaultTheme, null)[0].scope)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
@Test fun aReusedRowScopeStillReadsLiveState() {
|
|
212
|
-
state["rows"] = rows("a"); state["n"] = 1L
|
|
213
|
-
val sc = scopeOf(); val cache = ExpandCache()
|
|
214
|
-
val first = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
215
|
-
state["n"] = 2L
|
|
216
|
-
val second = expand(listOf(row), sc, defaultTheme, null, cache)
|
|
217
|
-
assertSame(first[0].scope, second[0].scope)
|
|
218
|
-
assertEquals(2L, evalExpr("n", second[0].scope))
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
// AI-GENERATED END: unit tests for resolving a child's styles once and for stable repeat-row scopes
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt
|
|
2
|
-
// Created At: 2026-11-03 10:00:00 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-sonnet-5-5
|
|
6
|
-
|
|
7
|
-
package vn.momo.kits.sdui
|
|
8
|
-
|
|
9
|
-
import androidx.compose.foundation.layout.Arrangement
|
|
10
|
-
import androidx.compose.foundation.layout.PaddingValues
|
|
11
|
-
import androidx.compose.ui.Alignment
|
|
12
|
-
import androidx.compose.ui.graphics.Color
|
|
13
|
-
import androidx.compose.ui.text.input.KeyboardType
|
|
14
|
-
import androidx.compose.ui.text.style.TextDecoration
|
|
15
|
-
import androidx.compose.ui.text.style.TextOverflow
|
|
16
|
-
import androidx.compose.ui.unit.TextUnit
|
|
17
|
-
import androidx.compose.ui.unit.dp
|
|
18
|
-
import androidx.compose.ui.unit.sp
|
|
19
|
-
import vn.momo.kits.components.ButtonSize
|
|
20
|
-
import vn.momo.kits.components.ChipSize
|
|
21
|
-
import vn.momo.kits.components.RibbonPosition
|
|
22
|
-
import vn.momo.kits.components.TagColor
|
|
23
|
-
import vn.momo.kits.components.TagSize
|
|
24
|
-
import vn.momo.kits.components.ButtonType
|
|
25
|
-
import vn.momo.kits.components.DotSize
|
|
26
|
-
import vn.momo.kits.components.IconAlign
|
|
27
|
-
import vn.momo.kits.components.ImageState
|
|
28
|
-
import vn.momo.kits.components.InputFontWeight
|
|
29
|
-
import vn.momo.kits.components.Size
|
|
30
|
-
import vn.momo.kits.components.TabViewType
|
|
31
|
-
import vn.momo.kits.components.TitleSize
|
|
32
|
-
import org.junit.Test
|
|
33
|
-
import org.junit.Assert.assertEquals
|
|
34
|
-
import org.junit.Assert.assertNotNull
|
|
35
|
-
import org.junit.Assert.assertNull
|
|
36
|
-
|
|
37
|
-
class SduiRendererPropsTest {
|
|
38
|
-
@Test fun buttonArgsDefaultsAreKitDefaults() {
|
|
39
|
-
val a = buttonArgsOf(emptyMap())
|
|
40
|
-
assertEquals(ButtonArgs(ButtonType.PRIMARY, Size.LARGE, "Button", "", "", false, true, true), a)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Test fun buttonArgsSetValuesAndIconsNotSwapped() {
|
|
44
|
-
val a = buttonArgsOf(mapOf(
|
|
45
|
-
"type" to "danger", "size" to "small", "title" to "Pay", "iconLeft" to "L", "iconRight" to "R",
|
|
46
|
-
"loading" to true, "useTintColor" to false, "full" to false,
|
|
47
|
-
))
|
|
48
|
-
assertEquals(ButtonArgs(ButtonType.DANGER, Size.SMALL, "Pay", "L", "R", true, false, false), a)
|
|
49
|
-
assertEquals(Size.LARGE, buttonArgsOf(mapOf("size" to "huge")).size)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Test fun textProps() {
|
|
53
|
-
assertEquals(TextOverflow.Ellipsis, textOverflowOf("ellipsis"))
|
|
54
|
-
assertEquals(TextOverflow.Visible, textOverflowOf("visible"))
|
|
55
|
-
assertEquals(TextOverflow.Clip, textOverflowOf(null))
|
|
56
|
-
assertEquals(TextOverflow.Clip, textOverflowOf("zzz"))
|
|
57
|
-
// numberOfLines set and no overflow -> "…" (owner-approved exception to the kit's Clip default)
|
|
58
|
-
assertEquals(TextOverflow.Ellipsis, textOverflowOf(null, linesLimited = true))
|
|
59
|
-
assertEquals(TextOverflow.Clip, textOverflowOf("clip", linesLimited = true))
|
|
60
|
-
assertEquals(TextDecoration.Underline, textDecorationOf("underline"))
|
|
61
|
-
assertEquals(TextDecoration.LineThrough, textDecorationOf("line-through"))
|
|
62
|
-
assertEquals(TextDecoration.LineThrough, textDecorationOf("line_through"))
|
|
63
|
-
assertEquals(TextDecoration.combine(listOf(TextDecoration.Underline, TextDecoration.LineThrough)), textDecorationOf("underline line-through"))
|
|
64
|
-
assertNull(textDecorationOf("none")); assertNull(textDecorationOf(null))
|
|
65
|
-
assertEquals(TextUnit.Unspecified, letterSpacingOf(null))
|
|
66
|
-
assertEquals(1.5f.sp, letterSpacingOf(1.5))
|
|
67
|
-
assertEquals("fam", optStr("fam")); assertNull(optStr("")); assertNull(optStr(null))
|
|
68
|
-
assertEquals(1, intOr(null, 1)); assertEquals(3, intOr(3L, 1))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@Test fun titleProps() {
|
|
72
|
-
assertEquals(TitleSize.Medium, titleSizeOf(null))
|
|
73
|
-
assertEquals(TitleSize.Small, titleSizeOf("small"))
|
|
74
|
-
assertEquals(TitleSize.Large, titleSizeOf("large"))
|
|
75
|
-
assertEquals(TitleSize.Medium, titleSizeOf("xx"))
|
|
76
|
-
assertEquals(IconAlign.Top, iconAlignOf(null))
|
|
77
|
-
assertEquals(IconAlign.Center, iconAlignOf("center"))
|
|
78
|
-
assertEquals(IconAlign.Bottom, iconAlignOf("bottom"))
|
|
79
|
-
assertEquals(ButtonSize.Small, titleButtonSizeOf(null))
|
|
80
|
-
assertEquals(ButtonSize.Large, titleButtonSizeOf("large"))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@Test fun imageProps() {
|
|
84
|
-
assertEquals(Alignment.TopStart, alignmentOf(null, Alignment.TopStart))
|
|
85
|
-
assertEquals(Alignment.BottomEnd, alignmentOf("bottom_end", Alignment.TopStart))
|
|
86
|
-
assertEquals(Alignment.Center, alignmentOf("center", Alignment.TopStart))
|
|
87
|
-
assertEquals(Alignment.TopStart, alignmentOf("nope", Alignment.TopStart))
|
|
88
|
-
assertNull(colorFilterOf(null)); assertNotNull(colorFilterOf(Color.Red))
|
|
89
|
-
assertEquals(1f, alphaOf(null)); assertEquals(0.5f, alphaOf(0.5)); assertEquals(1f, alphaOf(7))
|
|
90
|
-
assertEquals("success", imageStateName(ImageState.Success))
|
|
91
|
-
assertEquals("error", imageStateName(ImageState.Error))
|
|
92
|
-
assertEquals("loading", imageStateName(ImageState.Loading))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@Test fun paddingValues() {
|
|
96
|
-
assertNull(paddingValuesOf(null))
|
|
97
|
-
assertEquals(PaddingValues(8.dp), paddingValuesOf(8))
|
|
98
|
-
assertEquals(PaddingValues(start = 4.dp, top = 2.dp, end = 4.dp, bottom = 2.dp), paddingValuesOf(mapOf("horizontal" to 4, "vertical" to 2)))
|
|
99
|
-
assertEquals(PaddingValues(start = 1.dp, top = 0.dp, end = 3.dp, bottom = 0.dp), paddingValuesOf(mapOf("left" to 1, "right" to 3)))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@Test fun tabViewProps() {
|
|
103
|
-
assertEquals(TabViewType.DEFAULT, tabViewTypeOf(null))
|
|
104
|
-
assertEquals(TabViewType.CARD, tabViewTypeOf("card"))
|
|
105
|
-
assertEquals(DotSize.Small, dotSizeOf(null))
|
|
106
|
-
assertEquals(DotSize.Large, dotSizeOf("large"))
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Test fun paginationKinds() {
|
|
110
|
-
assertEquals(PaginationKind.DOT, paginationKindOf(null))
|
|
111
|
-
assertEquals(PaginationKind.WHITE_DOT, paginationKindOf("white_dot"))
|
|
112
|
-
assertEquals(PaginationKind.WHITE_DOT, paginationKindOf("white-dot"))
|
|
113
|
-
assertEquals(PaginationKind.NUMBER, paginationKindOf("number"))
|
|
114
|
-
assertEquals(PaginationKind.SCROLL, paginationKindOf("scroll"))
|
|
115
|
-
assertEquals(PaginationKind.DOT, paginationKindOf("?"))
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@Test fun scrollArrangements() {
|
|
119
|
-
assertEquals(Arrangement.Start, horizontalArrangementOf(null))
|
|
120
|
-
assertEquals(Arrangement.SpaceBetween, horizontalArrangementOf("space_between"))
|
|
121
|
-
assertEquals(Arrangement.Top, verticalArrangementOf(null))
|
|
122
|
-
assertEquals(Arrangement.Bottom, verticalArrangementOf("bottom"))
|
|
123
|
-
assertEquals(Arrangement.Center, verticalArrangementOf("center"))
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@Test fun inputSearchProps() {
|
|
127
|
-
assertEquals(InputFontWeight.REGULAR, inputFontWeightOf(null, InputFontWeight.REGULAR))
|
|
128
|
-
assertEquals(InputFontWeight.BOLD, inputFontWeightOf("bold", InputFontWeight.REGULAR))
|
|
129
|
-
assertEquals(InputFontWeight.BOLD, inputFontWeightOf("BOLD", InputFontWeight.REGULAR))
|
|
130
|
-
assertEquals(KeyboardType.Text, keyboardTypeOf(null))
|
|
131
|
-
assertEquals(KeyboardType.Number, keyboardTypeOf("number"))
|
|
132
|
-
assertEquals(KeyboardType.Number, keyboardTypeOf("number-pad"))
|
|
133
|
-
assertEquals(KeyboardType.NumberPassword, keyboardTypeOf("number_password"))
|
|
134
|
-
assertEquals(KeyboardType.Text, keyboardTypeOf("zzz"))
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
@Test fun snakeAndColours() {
|
|
138
|
-
assertEquals("top_right", snake("top-right")); assertEquals("line_through", snake("LINE_THROUGH")); assertNull(snake(3))
|
|
139
|
-
assertEquals(KIT_LABEL, "Label")
|
|
140
|
-
assertEquals(Color(0xFFFF0000), parseColor("#FF0000"))
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ---- numeric strings ----
|
|
144
|
-
@Test fun numericStringsAreAccepted() {
|
|
145
|
-
assertEquals(6, intOr("6", 12)); assertEquals(12, intOr("abc", 12)); assertEquals(12, intOr(null, 12))
|
|
146
|
-
assertEquals(1.5f, floatOr("1.5", 1f)); assertEquals(1f, floatOr(true, 1f))
|
|
147
|
-
assertEquals(500L, longOr("500", 3000L)); assertEquals(3000L, longOr(listOf(1), 3000L))
|
|
148
|
-
assertEquals(6, itemArgsOf(mapOf("widthSpan" to "6")).widthSpan)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// ---- Text lines ----
|
|
152
|
-
@Test fun textLinesClamp() {
|
|
153
|
-
assertEquals(Int.MAX_VALUE, maxLinesOf(null)); assertEquals(Int.MAX_VALUE, maxLinesOf(0))
|
|
154
|
-
assertEquals(Int.MAX_VALUE, maxLinesOf(-3)); assertEquals(Int.MAX_VALUE, maxLinesOf("x"))
|
|
155
|
-
assertEquals(2, maxLinesOf(2)); assertEquals(2, maxLinesOf("2"))
|
|
156
|
-
assertEquals(1, minLinesOf(null, 5)); assertEquals(1, minLinesOf(0, 5)); assertEquals(1, minLinesOf(-2, 5))
|
|
157
|
-
assertEquals(3, minLinesOf(3, 5)); assertEquals(2, minLinesOf(9, 2))
|
|
158
|
-
assertEquals(1, minLinesOf(9, 1))
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// ---- padding ----
|
|
162
|
-
@Test fun negativePaddingClampedToZero() {
|
|
163
|
-
assertEquals(PaddingValues(0.dp), paddingValuesOf(-5))
|
|
164
|
-
assertEquals(PaddingValues(start = 0.dp, top = 2.dp, end = 0.dp, bottom = 2.dp),
|
|
165
|
-
paddingValuesOf(mapOf("horizontal" to -4, "vertical" to 2)))
|
|
166
|
-
assertEquals(PaddingValues(start = 0.dp, top = 0.dp, end = 3.dp, bottom = 0.dp), paddingValuesOf(mapOf("left" to -1, "right" to 3)))
|
|
167
|
-
assertEquals(16.dp, PaddingValues(start = 4.dp, end = 12.dp).horizontal())
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ---- grid ----
|
|
171
|
-
@Test fun gridSizePerSpanUsesActualCardPadding() {
|
|
172
|
-
// default Card padding 12 -> 24 horizontal: identical to the old fixed assumption
|
|
173
|
-
val old = (360.dp - 24.dp - 24.dp - 8.dp * 11) / 12 - (1f / 12).dp
|
|
174
|
-
assertEquals(old.value, gridSizePerSpan(360.dp, true, true, 24.dp).value, 0.001f)
|
|
175
|
-
// zero padding gives each span more room; a wide padding gives less
|
|
176
|
-
assertEquals(24f / 12f, gridSizePerSpan(360.dp, true, true, 24.dp).value - gridSizePerSpan(360.dp, true, true, 48.dp).value, 0.001f)
|
|
177
|
-
assert(gridSizePerSpan(360.dp, true, true, 0.dp) > gridSizePerSpan(360.dp, true, true, 24.dp))
|
|
178
|
-
// Section: no card padding, gutter 12
|
|
179
|
-
assertEquals(((360.dp - 24.dp - 12.dp * 11) / 12 - (1f / 12).dp).value, gridSizePerSpan(360.dp, true, false, 24.dp).value, 0.001f)
|
|
180
|
-
assertEquals(0f, gridSizePerSpan(20.dp, true, true, 24.dp).value, 0f)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@Test fun itemSpans() {
|
|
184
|
-
assertEquals(ItemArgs(12, 0), itemArgsOf(emptyMap()))
|
|
185
|
-
assertEquals(ItemArgs(12, 0), itemArgsOf(mapOf("widthSpan" to "wide", "heightSpan" to null)))
|
|
186
|
-
assertEquals(ItemArgs(1, 0), itemArgsOf(mapOf("widthSpan" to 0, "heightSpan" to -2)))
|
|
187
|
-
assertEquals(ItemArgs(12, 3), itemArgsOf(mapOf("widthSpan" to 99, "heightSpan" to 3)))
|
|
188
|
-
assertEquals(ItemArgs(6, 4), itemArgsOf(mapOf("widthSpan" to 6L, "heightSpan" to "4")))
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
@Test fun sectionAndCardArgs() {
|
|
192
|
-
val s = gridArgsOf(mapOf("useMargin" to false, "backgroundImage" to "https://x/y.png", "useShadow" to true), card = false)
|
|
193
|
-
assertEquals(false, s.useMargin); assertEquals(false, s.useShadow); assertEquals("https://x/y.png", s.backgroundImage)
|
|
194
|
-
assertEquals(true, gridArgsOf(emptyMap(), false).useMargin)
|
|
195
|
-
val c = gridArgsOf(mapOf("useMargin" to false, "useShadow" to true, "contentPadding" to -8), card = true)
|
|
196
|
-
assertEquals(true, c.useMargin); assertEquals(true, c.useShadow); assertEquals(PaddingValues(0.dp), c.contentPadding)
|
|
197
|
-
assertEquals(PaddingValues(12.dp), gridArgsOf(emptyMap(), true).contentPadding)
|
|
198
|
-
assertEquals(false, gridArgsOf(emptyMap(), true).useShadow)
|
|
199
|
-
assertNull(gridArgsOf(emptyMap(), true).backgroundImage)
|
|
200
|
-
assertEquals(Color(0xFFFF0000), gridArgsOf(mapOf("backgroundColor" to "#FF0000"), true).backgroundColor)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ---- Badge / Ribbon / Tag / Chip ----
|
|
204
|
-
@Test fun badgeArgs() {
|
|
205
|
-
assertEquals(BadgeArgs(KIT_LABEL, null), badgeArgsOf(emptyMap()))
|
|
206
|
-
assertEquals(BadgeArgs("New", Color(0xFF00FF00)), badgeArgsOf(mapOf("label" to "New", "backgroundColor" to "#00FF00")))
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@Test fun ribbonArgs() {
|
|
210
|
-
assertEquals(RibbonArgs(RibbonPosition.TopRight, KIT_LABEL, false), ribbonArgsOf(emptyMap()))
|
|
211
|
-
assertEquals(RibbonPosition.TopLeft, ribbonArgsOf(mapOf("position" to "top_left")).position)
|
|
212
|
-
assertEquals(RibbonPosition.BottomLeft, ribbonArgsOf(mapOf("position" to "bottom-left")).position)
|
|
213
|
-
assertEquals(RibbonPosition.BottomRight, ribbonArgsOf(mapOf("position" to "bottom_right")).position)
|
|
214
|
-
assertEquals(RibbonPosition.TopRight, ribbonArgsOf(mapOf("position" to "nowhere")).position)
|
|
215
|
-
assertEquals(RibbonPosition.TopRight, ribbonArgsOf(mapOf("position" to 3)).position)
|
|
216
|
-
assertEquals(true, ribbonArgsOf(mapOf("isRound" to true, "label" to "Hot")).isRound)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
@Test fun tagArgs() {
|
|
220
|
-
assertEquals(TagArgs(KIT_LABEL, null, null, TagColor.Default, TagSize.Large), tagArgsOf(emptyMap()))
|
|
221
|
-
val t = tagArgsOf(mapOf("label" to "A", "icon" to "ic", "color" to "green", "size" to "medium", "customColor" to "#0000FF"))
|
|
222
|
-
assertEquals(TagArgs("A", "ic", Color(0xFF0000FF), TagColor.Green, TagSize.Medium), t)
|
|
223
|
-
assertEquals(TagSize.Large, tagArgsOf(mapOf("size" to "huge")).size)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
@Test fun chipArgsKeepIconsAndTintsApart() {
|
|
227
|
-
assertEquals(ChipArgs(KIT_LABEL, null, null, null, null, null, false, ChipSize.LARGE, null), chipArgsOf(emptyMap()))
|
|
228
|
-
val c = chipArgsOf(mapOf(
|
|
229
|
-
"label" to "L", "iconLeft" to "left", "iconRight" to "right", "iconLeftTint" to "#FF0000", "iconRightTint" to "#0000FF",
|
|
230
|
-
"backgroundColor" to "#00FF00", "selected" to true, "size" to "small", "accessibilityLabel" to "a",
|
|
231
|
-
))
|
|
232
|
-
assertEquals("left", c.iconLeft); assertEquals("right", c.iconRight)
|
|
233
|
-
assertEquals(Color(0xFFFF0000), c.iconLeftTint); assertEquals(Color(0xFF0000FF), c.iconRightTint)
|
|
234
|
-
assertEquals(Color(0xFF00FF00), c.backgroundColor)
|
|
235
|
-
assertEquals(true, c.selected); assertEquals(ChipSize.SMALL, c.size); assertEquals("a", c.accessibilityLabel)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// ---- Carousel ----
|
|
239
|
-
@Test fun autoplayIntervalHasAFloor() {
|
|
240
|
-
assertEquals(3000L, autoplayIntervalOf(null)); assertEquals(1000L, autoplayIntervalOf(0))
|
|
241
|
-
assertEquals(1000L, autoplayIntervalOf(-50)); assertEquals(1000L, autoplayIntervalOf("10"))
|
|
242
|
-
assertEquals(5000L, autoplayIntervalOf("5000")); assertEquals(2500L, autoplayIntervalOf(2500))
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ---- InputSearch overlay decision ----
|
|
246
|
-
private fun searchNode(vararg actions: String, props: Map<String, Any?> = emptyMap()): Node =
|
|
247
|
-
mapOf("type" to "InputSearch", "props" to props, "actions" to actions.map { mapOf("name" to it) })
|
|
248
|
-
|
|
249
|
-
@Test fun searchOverlayOnlyForPurePressable() {
|
|
250
|
-
assertEquals(true, searchShowsOverlay(searchNode("onPress")))
|
|
251
|
-
assertEquals(false, searchPressOnFocus(searchNode("onPress")))
|
|
252
|
-
// typing callback present: no overlay, onPress fires on focus
|
|
253
|
-
for (cb in SEARCH_TYPING_CALLBACKS) {
|
|
254
|
-
val n = searchNode("onPress", cb)
|
|
255
|
-
assertEquals(cb, false, searchShowsOverlay(n)); assertEquals(cb, true, searchPressOnFocus(n))
|
|
256
|
-
}
|
|
257
|
-
// no onPress: never an overlay
|
|
258
|
-
assertEquals(false, searchShowsOverlay(searchNode("onChangeText")))
|
|
259
|
-
assertEquals(false, searchShowsOverlay(searchNode()))
|
|
260
|
-
assertEquals(false, searchPressOnFocus(searchNode("onChangeText")))
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
@Test fun searchOverlayReadsPropFormActions() {
|
|
264
|
-
val pressInProps = searchNode(props = mapOf("onPress" to mapOf("set" to "x")))
|
|
265
|
-
assertEquals(true, searchShowsOverlay(pressInProps))
|
|
266
|
-
val both = searchNode(props = mapOf("onPress" to mapOf("set" to "x"), "onChangeText" to mapOf("set" to "q")))
|
|
267
|
-
assertEquals(false, searchShowsOverlay(both)); assertEquals(true, searchPressOnFocus(both))
|
|
268
|
-
assertEquals(false, searchShowsOverlay(searchNode("onPress", props = mapOf("onFocus" to listOf(mapOf("set" to "x"))))))
|
|
269
|
-
}
|
|
270
|
-
}
|