@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,741 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt
|
|
2
|
-
// Created At: 2026-11-10 14: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.ui.Alignment
|
|
11
|
-
import androidx.compose.ui.graphics.Color
|
|
12
|
-
import androidx.compose.ui.layout.ContentScale
|
|
13
|
-
import androidx.compose.ui.text.input.KeyboardType
|
|
14
|
-
import androidx.compose.ui.text.style.TextAlign
|
|
15
|
-
import androidx.compose.ui.text.style.TextOverflow
|
|
16
|
-
import androidx.compose.ui.unit.dp
|
|
17
|
-
import androidx.compose.ui.unit.LayoutDirection
|
|
18
|
-
import org.junit.Assert.assertEquals
|
|
19
|
-
import org.junit.Assert.assertFalse
|
|
20
|
-
import org.junit.Assert.assertNotNull
|
|
21
|
-
import org.junit.Assert.assertNull
|
|
22
|
-
import org.junit.Assert.assertTrue
|
|
23
|
-
import org.junit.Test
|
|
24
|
-
import vn.momo.kits.const.Spacing
|
|
25
|
-
import vn.momo.kits.components.DotSize
|
|
26
|
-
import vn.momo.kits.components.IconAlign
|
|
27
|
-
import vn.momo.kits.components.InputFontWeight
|
|
28
|
-
import vn.momo.kits.components.TabViewDirection
|
|
29
|
-
import vn.momo.kits.components.TabViewType
|
|
30
|
-
import vn.momo.kits.components.TitleSize
|
|
31
|
-
import vn.momo.kits.components.TitleType
|
|
32
|
-
|
|
33
|
-
// AI-GENERATED START: unit tests for the pure drawing decisions extracted from the SDUI Compose renderer
|
|
34
|
-
class SduiRenderPlanTest {
|
|
35
|
-
private fun sty(vararg kv: Pair<String, Any?>) = Sty(mapOf(*kv))
|
|
36
|
-
|
|
37
|
-
// ---- childPath / imageUrl / contentScale ------------------------------------------------------------------------
|
|
38
|
-
@Test fun childPathAppendsTheChildIndex() {
|
|
39
|
-
assertEquals("body.children.3", childPath("body", Expanded(emptyMap(), SduiScope(emptyMap(), androidx.compose.runtime.mutableStateMapOf()), 3)))
|
|
40
|
-
assertEquals(".children.0", childPath("", Expanded(emptyMap(), SduiScope(emptyMap(), androidx.compose.runtime.mutableStateMapOf()), 0)))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Test fun imageUrlAcceptsStringOrUriMapAndRejectsBlank() {
|
|
44
|
-
assertEquals("http://a", imageUrl("http://a"))
|
|
45
|
-
assertEquals("http://b", imageUrl(mapOf("uri" to "http://b")))
|
|
46
|
-
assertNull(imageUrl(""))
|
|
47
|
-
assertNull(imageUrl(" "))
|
|
48
|
-
assertNull(imageUrl(mapOf("uri" to " ")))
|
|
49
|
-
assertNull(imageUrl(mapOf("uri" to 3)))
|
|
50
|
-
assertNull(imageUrl(null))
|
|
51
|
-
assertNull(imageUrl(5L))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@Test fun contentScaleMapsResizeModes() {
|
|
55
|
-
assertEquals(ContentScale.Fit, contentScale("contain"))
|
|
56
|
-
assertEquals(ContentScale.FillBounds, contentScale("stretch"))
|
|
57
|
-
assertEquals(ContentScale.Crop, contentScale("cover"))
|
|
58
|
-
assertEquals(ContentScale.Crop, contentScale(null))
|
|
59
|
-
assertEquals(ContentScale.Crop, contentScale(1L))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ---- nodeKindOf ---------------------------------------------------------------------------------------------------
|
|
63
|
-
@Test fun nodeKindMapsEveryBranch() {
|
|
64
|
-
val expected = mapOf(
|
|
65
|
-
"View" to NodeKind.VIEW, "TouchableOpacity" to NodeKind.VIEW, "Item" to NodeKind.VIEW,
|
|
66
|
-
"ImageBackground" to NodeKind.IMAGE_BACKGROUND, "Screen" to NodeKind.SCREEN,
|
|
67
|
-
"Section" to NodeKind.GRID, "Card" to NodeKind.GRID, "Text" to NodeKind.TEXT, "Title" to NodeKind.TITLE,
|
|
68
|
-
"Image" to NodeKind.IMAGE, "Badge" to NodeKind.BADGE, "BadgeRibbon" to NodeKind.BADGE_RIBBON, "Tag" to NodeKind.TAG,
|
|
69
|
-
"Icon" to NodeKind.ICON, "Button" to NodeKind.BUTTON, "TabView" to NodeKind.TAB_VIEW, "Carousel" to NodeKind.CAROUSEL,
|
|
70
|
-
"Pagination" to NodeKind.PAGINATION, "Chip" to NodeKind.CHIP, "ScrollView" to NodeKind.SCROLL_VIEW,
|
|
71
|
-
"InputSearch" to NodeKind.INPUT_SEARCH,
|
|
72
|
-
)
|
|
73
|
-
expected.forEach { (t, k) -> assertEquals(t, k, nodeKindOf(t)) }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@Test fun nodeKindKitTypesAndUnknowns() {
|
|
77
|
-
KIT_NODE_TYPES.forEach { t ->
|
|
78
|
-
// an earlier branch wins when a kit name is also a drawn branch
|
|
79
|
-
val k = nodeKindOf(t)
|
|
80
|
-
assertTrue(t, k == NodeKind.KIT || k != NodeKind.UNSUPPORTED)
|
|
81
|
-
}
|
|
82
|
-
assertEquals(NodeKind.KIT, nodeKindOf("Switch"))
|
|
83
|
-
assertEquals(NodeKind.UNSUPPORTED, nodeKindOf("CornerStone"))
|
|
84
|
-
assertEquals(NodeKind.UNSUPPORTED, nodeKindOf("view"))
|
|
85
|
-
assertEquals(NodeKind.UNSUPPORTED, nodeKindOf(""))
|
|
86
|
-
assertEquals(NodeKind.UNSUPPORTED, nodeKindOf(null))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ---- viewPlanOf -----------------------------------------------------------------------------------------------------
|
|
90
|
-
@Test fun viewPlanDefaults() {
|
|
91
|
-
val p = viewPlanOf(sty(), Parent(), hasBgImage = false, hasAbsolute = false)
|
|
92
|
-
assertEquals(ViewPlan(stretchH = false, stretch = true, weight = false, sized = false, fillMain = false, wrapBox = false), p)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@Test fun viewPlanStretchHeightOnlyForFillHeightParentWithoutHeightAndNotAbsolute() {
|
|
96
|
-
val fh = Parent(stretch = false, fillHeight = true)
|
|
97
|
-
assertTrue(viewPlanOf(sty(), fh, false, false).stretchH)
|
|
98
|
-
assertFalse(viewPlanOf(sty("height" to 40L), fh, false, false).stretchH)
|
|
99
|
-
assertFalse(viewPlanOf(sty("position" to "absolute"), fh, false, false).stretchH)
|
|
100
|
-
assertFalse(viewPlanOf(sty(), Parent(), false, false).stretchH)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@Test fun viewPlanAbsoluteNeverStretchesWidth() {
|
|
104
|
-
assertTrue(viewPlanOf(sty(), Parent(stretch = true), false, false).stretch)
|
|
105
|
-
assertFalse(viewPlanOf(sty("position" to "absolute"), Parent(stretch = true), false, false).stretch)
|
|
106
|
-
assertFalse(viewPlanOf(sty(), Parent(stretch = false), false, false).stretch)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Test fun viewPlanWeightIsFlexOne() {
|
|
110
|
-
assertTrue(viewPlanOf(sty("flex" to 1L), Parent(), false, false).weight)
|
|
111
|
-
assertFalse(viewPlanOf(sty("flex" to 2L), Parent(), false, false).weight)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@Test fun viewPlanSizedFromHeightAspectFlexOrFillHeightParent() {
|
|
115
|
-
assertTrue(viewPlanOf(sty("height" to 10L), Parent(), false, false).sized)
|
|
116
|
-
assertTrue(viewPlanOf(sty("aspectRatio" to 1.5), Parent(), false, false).sized)
|
|
117
|
-
assertTrue(viewPlanOf(sty("flex" to 1L), Parent(), false, false).sized)
|
|
118
|
-
assertTrue(viewPlanOf(sty(), Parent(fillHeight = true), false, false).sized)
|
|
119
|
-
assertFalse(viewPlanOf(sty("width" to 10L), Parent(), false, false).sized)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
@Test fun viewPlanFillMainNeedsSizedAndSpreadingJustify() {
|
|
123
|
-
for (j in listOf("center", "flex-end", "space-between")) {
|
|
124
|
-
assertTrue(j, viewPlanOf(sty("height" to 10L, "justifyContent" to j), Parent(), false, false).fillMain)
|
|
125
|
-
assertFalse(j, viewPlanOf(sty("justifyContent" to j), Parent(), false, false).fillMain)
|
|
126
|
-
}
|
|
127
|
-
assertFalse(viewPlanOf(sty("height" to 10L, "justifyContent" to "flex-start"), Parent(), false, false).fillMain)
|
|
128
|
-
assertFalse(viewPlanOf(sty("height" to 10L), Parent(), false, false).fillMain)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
@Test fun viewPlanWrapBoxForBackgroundImageOrAbsoluteChildren() {
|
|
132
|
-
assertTrue(viewPlanOf(sty(), Parent(), hasBgImage = true, hasAbsolute = false).wrapBox)
|
|
133
|
-
assertTrue(viewPlanOf(sty(), Parent(), hasBgImage = false, hasAbsolute = true).wrapBox)
|
|
134
|
-
assertFalse(viewPlanOf(sty(), Parent(), hasBgImage = false, hasAbsolute = false).wrapBox)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// ---- flexPlanOf -----------------------------------------------------------------------------------------------------
|
|
138
|
-
@Test fun flexPlanDefaultsToColumnStartStretch() {
|
|
139
|
-
val p = flexPlanOf(sty(), false)
|
|
140
|
-
assertEquals(FlexPlan(FlexKind.COLUMN, Justify.START, Cross.START, 0.dp, 0.dp, true, true, false), p)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
@Test fun flexKindRowWrapColumn() {
|
|
144
|
-
assertEquals(FlexKind.ROW, flexPlanOf(sty("flexDirection" to "row"), false).kind)
|
|
145
|
-
assertEquals(FlexKind.WRAP, flexPlanOf(sty("flexDirection" to "row", "flexWrap" to "wrap"), false).kind)
|
|
146
|
-
// wrap without a row is still a column
|
|
147
|
-
assertEquals(FlexKind.COLUMN, flexPlanOf(sty("flexWrap" to "wrap"), false).kind)
|
|
148
|
-
assertEquals(FlexKind.COLUMN, flexPlanOf(sty("flexDirection" to "column"), false).kind)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@Test fun flexJustifyMapping() {
|
|
152
|
-
assertEquals(Justify.CENTER, flexPlanOf(sty("justifyContent" to "center"), false).justify)
|
|
153
|
-
assertEquals(Justify.END, flexPlanOf(sty("justifyContent" to "flex-end"), false).justify)
|
|
154
|
-
assertEquals(Justify.SPACE_BETWEEN, flexPlanOf(sty("justifyContent" to "space-between"), false).justify)
|
|
155
|
-
assertEquals(Justify.START, flexPlanOf(sty("justifyContent" to "flex-start"), false).justify)
|
|
156
|
-
assertEquals(Justify.START, flexPlanOf(sty("justifyContent" to "space-around"), false).justify)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@Test fun flexCrossMappingAndStretch() {
|
|
160
|
-
assertEquals(Cross.CENTER, flexPlanOf(sty("alignItems" to "center"), false).cross)
|
|
161
|
-
assertEquals(Cross.END, flexPlanOf(sty("alignItems" to "flex-end"), false).cross)
|
|
162
|
-
assertEquals(Cross.START, flexPlanOf(sty("alignItems" to "flex-start"), false).cross)
|
|
163
|
-
assertTrue(flexPlanOf(sty("alignItems" to "stretch"), false).stretch)
|
|
164
|
-
assertTrue(flexPlanOf(sty(), false).stretch)
|
|
165
|
-
assertFalse(flexPlanOf(sty("alignItems" to "center"), false).stretch)
|
|
166
|
-
assertFalse(flexPlanOf(sty("alignItems" to "flex-start"), false).stretch)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
@Test fun flexGapFromGapThenRowGapAndClampedToZero() {
|
|
170
|
-
assertEquals(8.dp, flexPlanOf(sty("gap" to 8L), false).gap)
|
|
171
|
-
assertEquals(6.dp, flexPlanOf(sty("rowGap" to 6L), false).gap)
|
|
172
|
-
assertEquals(8.dp, flexPlanOf(sty("gap" to 8L, "rowGap" to 6L), false).gap)
|
|
173
|
-
assertEquals(0.dp, flexPlanOf(sty("gap" to -4L), false).gap)
|
|
174
|
-
assertEquals(0.dp, flexPlanOf(sty(), false).gap)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
@Test fun flexRowGapFallsBackToGapAndClamps() {
|
|
178
|
-
assertEquals(6.dp, flexPlanOf(sty("gap" to 8L, "rowGap" to 6L), false).rowGap)
|
|
179
|
-
assertEquals(8.dp, flexPlanOf(sty("gap" to 8L), false).rowGap)
|
|
180
|
-
assertEquals(0.dp, flexPlanOf(sty("gap" to 8L, "rowGap" to -2L), false).rowGap)
|
|
181
|
-
assertEquals(0.dp, flexPlanOf(sty("gap" to -3L), false).rowGap)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
@Test fun flexIntrinsicHeightWhenStretchingWithoutFixedHeight() {
|
|
185
|
-
assertTrue(flexPlanOf(sty("flexDirection" to "row"), false).intrinsicHeight)
|
|
186
|
-
assertFalse(flexPlanOf(sty("flexDirection" to "row", "height" to 50L), false).intrinsicHeight)
|
|
187
|
-
assertFalse(flexPlanOf(sty("flexDirection" to "row", "alignItems" to "center"), false).intrinsicHeight)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@Test fun flexPlanCarriesFillMain() {
|
|
191
|
-
assertTrue(flexPlanOf(sty(), true).fillMain)
|
|
192
|
-
assertFalse(flexPlanOf(sty(), false).fillMain)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// ---- flexChildOf -----------------------------------------------------------------------------------------------------
|
|
196
|
-
@Test fun rowChildDoesNotStretchAndFillsHeightWhenStretching() {
|
|
197
|
-
val plan = flexPlanOf(sty("flexDirection" to "row"), false)
|
|
198
|
-
assertEquals(FlexChild(Parent(stretch = false, fillHeight = true), false), flexChildOf(plan, sty()))
|
|
199
|
-
assertEquals(FlexChild(Parent(stretch = false, fillHeight = true), true), flexChildOf(plan, sty("flex" to 1L)))
|
|
200
|
-
val centered = flexPlanOf(sty("flexDirection" to "row", "alignItems" to "center"), false)
|
|
201
|
-
assertEquals(Parent(stretch = false, fillHeight = false), flexChildOf(centered, sty()).parent)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
@Test fun columnChildStretchFollowsAlignItems() {
|
|
205
|
-
val stretch = flexPlanOf(sty(), false)
|
|
206
|
-
assertEquals(FlexChild(Parent(stretch = true), false), flexChildOf(stretch, sty()))
|
|
207
|
-
assertEquals(FlexChild(Parent(stretch = true), true), flexChildOf(stretch, sty("flex" to 1L)))
|
|
208
|
-
val center = flexPlanOf(sty("alignItems" to "center"), false)
|
|
209
|
-
assertEquals(Parent(stretch = false), flexChildOf(center, sty()).parent)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
@Test fun wrapChildNeverGetsWeight() {
|
|
213
|
-
val plan = flexPlanOf(sty("flexDirection" to "row", "flexWrap" to "wrap"), false)
|
|
214
|
-
assertEquals(FlexChild(Parent(stretch = false), false), flexChildOf(plan, sty("flex" to 1L)))
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
@Test fun flexTwoIsNotAWeightedChild() {
|
|
218
|
-
assertFalse(flexChildOf(flexPlanOf(sty(), false), sty("flex" to 2L)).weight)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ---- absolutePlanOf ---------------------------------------------------------------------------------------------------
|
|
222
|
-
@Test fun absoluteDefaultsToTopStartNoOffset() {
|
|
223
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 0.dp, 0.dp), absolutePlanOf(sty()))
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
@Test fun absoluteTopLeft() {
|
|
227
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 4.dp, 8.dp), absolutePlanOf(sty("left" to 4L, "top" to 8L)))
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
@Test fun absoluteRightOnlyAnchorsTopEndWithNegativeDx() {
|
|
231
|
-
assertEquals(AbsolutePlan(Corner.TOP_END, (-6).dp, 0.dp), absolutePlanOf(sty("right" to 6L)))
|
|
232
|
-
assertEquals(AbsolutePlan(Corner.TOP_END, (-6).dp, 3.dp), absolutePlanOf(sty("right" to 6L, "top" to 3L)))
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
@Test fun absoluteRightAndBottomAnchorsBottomEnd() {
|
|
236
|
-
assertEquals(AbsolutePlan(Corner.BOTTOM_END, (-6).dp, (-2).dp), absolutePlanOf(sty("right" to 6L, "bottom" to 2L)))
|
|
237
|
-
// top + bottom + right: top wins (CSS), so it anchors top-end 5 dp down, and spans the height minus 7 dp
|
|
238
|
-
assertEquals(AbsolutePlan(Corner.TOP_END, (-6).dp, 5.dp, stretchH = 7.dp), absolutePlanOf(sty("right" to 6L, "bottom" to 2L, "top" to 5L)))
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
@Test fun absoluteBottomOnlyAnchorsBottomStart() {
|
|
242
|
-
assertEquals(AbsolutePlan(Corner.BOTTOM_START, 0.dp, (-7).dp), absolutePlanOf(sty("bottom" to 7L)))
|
|
243
|
-
assertEquals(AbsolutePlan(Corner.BOTTOM_START, 2.dp, (-7).dp), absolutePlanOf(sty("bottom" to 7L, "left" to 2L)))
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
@Test fun absoluteLeftWinsOverRight() {
|
|
247
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 1.dp, 0.dp, stretchW = 10.dp), absolutePlanOf(sty("left" to 1L, "right" to 9L)))
|
|
248
|
-
// a set width keeps the size: left wins, no stretch
|
|
249
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 1.dp, 0.dp), absolutePlanOf(sty("left" to 1L, "right" to 9L, "width" to 20L)))
|
|
250
|
-
// a min / max bound also keeps the left anchoring (so the bound applies); "auto" is no size
|
|
251
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 1.dp, 0.dp), absolutePlanOf(sty("left" to 1L, "right" to 9L, "maxWidth" to 300L)))
|
|
252
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 1.dp, 0.dp), absolutePlanOf(sty("left" to 1L, "right" to 9L, "minWidth" to 30L)))
|
|
253
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 1.dp, 0.dp, stretchW = 10.dp), absolutePlanOf(sty("left" to 1L, "right" to 9L, "width" to "auto")))
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
@Test fun absoluteAllFourEdgesSpanTheParent() {
|
|
257
|
-
// the background-image case: left/top/right/bottom 0 and no size = exactly the parent's box
|
|
258
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 0.dp, 0.dp, stretchW = 0.dp, stretchH = 0.dp),
|
|
259
|
-
absolutePlanOf(sty("left" to 0L, "top" to 0L, "right" to 0L, "bottom" to 0L)))
|
|
260
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 4.dp, 2.dp, stretchW = 12.dp, stretchH = 5.dp),
|
|
261
|
-
absolutePlanOf(sty("left" to 4L, "top" to 2L, "right" to 8L, "bottom" to 3L)))
|
|
262
|
-
// a set height keeps the height; the width still spans
|
|
263
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 0.dp, 0.dp, stretchW = 0.dp),
|
|
264
|
-
absolutePlanOf(sty("left" to 0L, "top" to 0L, "right" to 0L, "bottom" to 0L, "height" to 40L)))
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// ---- absSlotsOf (paint order) --------------------------------------------------------------------------------------
|
|
268
|
-
private fun laid(i: Int, vararg st: Pair<String, Any?>) =
|
|
269
|
-
Laid(Expanded(mapOf("type" to "View"), SduiScope(emptyMap(), androidx.compose.runtime.mutableStateMapOf()), i), PreSty(sty(*st), emptySet()), i)
|
|
270
|
-
|
|
271
|
-
@Test fun absoluteBeforeAnInFlowSiblingPaintsUnderTheContent() {
|
|
272
|
-
val abs = "position" to "absolute"
|
|
273
|
-
// [bg(abs), mascot(abs), row, list, badge(abs)]: like React Native, the first two go under, the last one on top
|
|
274
|
-
val flow = listOf(laid(2), laid(3))
|
|
275
|
-
val slots = absSlotsOf(flow, listOf(laid(0, abs), laid(1, abs), laid(4, abs)))
|
|
276
|
-
assertEquals(listOf(true, true, false), slots.map { it.below })
|
|
277
|
-
// no in-flow child at all: every absolute child is on top (nothing to go under)
|
|
278
|
-
assertEquals(listOf(false), absSlotsOf(emptyList(), listOf(laid(0, abs))).map { it.below })
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
@Test fun absoluteTopAndBottomKeepTopStart() {
|
|
282
|
-
assertEquals(AbsolutePlan(Corner.TOP_START, 0.dp, 3.dp, stretchH = 7.dp), absolutePlanOf(sty("top" to 3L, "bottom" to 4L)))
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// ---- grid -------------------------------------------------------------------------------------------------------------
|
|
286
|
-
@Test fun gridSpanWidthForFullHalfAndSingleSpan() {
|
|
287
|
-
val per = 20.dp
|
|
288
|
-
val gutter = 12.dp
|
|
289
|
-
assertEquals(20.dp * 12 + 12.dp * 11, gridSpanWidth(per, gutter, 12))
|
|
290
|
-
assertEquals(20.dp * 6 + 12.dp * 5, gridSpanWidth(per, gutter, 6))
|
|
291
|
-
assertEquals(20.dp, gridSpanWidth(per, gutter, 1))
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
@Test fun gridSpanWidthZeroSpanIsClampedToZero() {
|
|
295
|
-
assertEquals(0.dp, gridSpanWidth(10.dp, 12.dp, 0))
|
|
296
|
-
assertEquals(0.dp, gridSpanWidth(0.dp, 8.dp, 1))
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
@Test fun itemSizeHasHeightOnlyWhenHeightSpanPositive() {
|
|
300
|
-
val s = itemSizeOf(ItemArgs(6, 0), 20.dp, 12.dp)
|
|
301
|
-
assertEquals(gridSpanWidth(20.dp, 12.dp, 6), s.width)
|
|
302
|
-
assertNull(s.height)
|
|
303
|
-
val t = itemSizeOf(ItemArgs(12, 3), 20.dp, 8.dp)
|
|
304
|
-
assertEquals(gridSpanWidth(20.dp, 8.dp, 12), t.width)
|
|
305
|
-
assertEquals(gridSpanWidth(20.dp, 8.dp, 3), t.height)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
@Test fun itemSizeFromParsedItemProps() {
|
|
309
|
-
val a = itemArgsOf(mapOf("widthSpan" to 6L, "heightSpan" to 1L))
|
|
310
|
-
assertEquals(ItemSize(gridSpanWidth(10.dp, 12.dp, 6), gridSpanWidth(10.dp, 12.dp, 1)), itemSizeOf(a, 10.dp, 12.dp))
|
|
311
|
-
assertEquals(gridSpanWidth(10.dp, 12.dp, 12), itemSizeOf(itemArgsOf(emptyMap()), 10.dp, 12.dp).width)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
@Test fun onlyAnItemTypeIsAGridItem() {
|
|
315
|
-
assertTrue(isGridItem(mapOf("type" to "Item")))
|
|
316
|
-
assertFalse(isGridItem(mapOf("type" to "View")))
|
|
317
|
-
assertFalse(isGridItem(emptyMap()))
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// ---- textArgsOf -------------------------------------------------------------------------------------------------------
|
|
321
|
-
private val black = Color.Black
|
|
322
|
-
|
|
323
|
-
@Test fun textDefaults() {
|
|
324
|
-
val a = textArgsOf(emptyMap(), sty(), black, 375f)
|
|
325
|
-
assertEquals("", a.text)
|
|
326
|
-
assertEquals(black, a.color)
|
|
327
|
-
assertEquals(TextAlign.Start, a.align)
|
|
328
|
-
assertNull(a.typography)
|
|
329
|
-
assertEquals(Int.MAX_VALUE, a.maxLines)
|
|
330
|
-
assertEquals(TextOverflow.Clip, a.overflow)
|
|
331
|
-
assertNull(a.decoration)
|
|
332
|
-
assertNull(a.fontFamily)
|
|
333
|
-
assertEquals(1, a.minLines)
|
|
334
|
-
assertTrue(a.softWrap)
|
|
335
|
-
assertNull(a.accessibilityId)
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
@Test fun textChildrenWinsOverTextAndUppercaseTransform() {
|
|
339
|
-
assertEquals("a", textArgsOf(mapOf("children" to "a", "text" to "b"), sty(), black, 375f).text)
|
|
340
|
-
assertEquals("b", textArgsOf(mapOf("text" to "b"), sty(), black, 375f).text)
|
|
341
|
-
assertEquals("XIN CHÀO", textArgsOf(mapOf("text" to "xin chào"), sty("textTransform" to "uppercase"), black, 375f).text)
|
|
342
|
-
assertEquals("xin", textArgsOf(mapOf("text" to "xin"), sty("textTransform" to "lowercase"), black, 375f).text)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
@Test fun textAlignMapping() {
|
|
346
|
-
assertEquals(TextAlign.Center, textArgsOf(emptyMap(), sty("textAlign" to "center"), black, 375f).align)
|
|
347
|
-
assertEquals(TextAlign.End, textArgsOf(emptyMap(), sty("textAlign" to "right"), black, 375f).align)
|
|
348
|
-
assertEquals(TextAlign.Start, textArgsOf(emptyMap(), sty("textAlign" to "left"), black, 375f).align)
|
|
349
|
-
assertEquals(TextAlign.Start, textArgsOf(emptyMap(), sty("textAlign" to "justify"), black, 375f).align)
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
@Test fun textColourFallsBackToTheThemeDefault() {
|
|
353
|
-
assertEquals(Color.White, textArgsOf(mapOf("color" to "white"), sty(), black, 375f).color)
|
|
354
|
-
assertEquals(black, textArgsOf(mapOf("color" to "Colors.nope"), sty(), black, 375f).color)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
@Test fun textLineHeightScalesWithScreenWidthAndIsNullForUnknownTypography() {
|
|
358
|
-
val base = textArgsOf(mapOf("typography" to "header_m_bold"), sty(), black, 375f).lineHeightSp
|
|
359
|
-
assertNotNull(base)
|
|
360
|
-
val wide = textArgsOf(mapOf("typography" to "header_m_bold"), sty(), black, 450f).lineHeightSp!!
|
|
361
|
-
assertEquals(base!! * 1.2f, wide, 0.001f)
|
|
362
|
-
val narrow = textArgsOf(mapOf("typography" to "header_m_bold"), sty(), black, 200f).lineHeightSp!!
|
|
363
|
-
assertEquals(base * 0.8f, narrow, 0.001f)
|
|
364
|
-
assertNull(textArgsOf(mapOf("typography" to "nope"), sty(), black, 375f).lineHeightSp)
|
|
365
|
-
assertEquals("nope", textArgsOf(mapOf("typography" to "nope"), sty(), black, 375f).typography)
|
|
366
|
-
assertNotNull(textArgsOf(emptyMap(), sty(), black, 375f).lineHeightSp) // body_default_regular fallback
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
@Test fun textLinesOverflowAndMinLines() {
|
|
370
|
-
val limited = textArgsOf(mapOf("numberOfLines" to 2L), sty(), black, 375f)
|
|
371
|
-
assertEquals(2, limited.maxLines)
|
|
372
|
-
assertEquals(TextOverflow.Ellipsis, limited.overflow)
|
|
373
|
-
assertEquals(TextOverflow.Visible, textArgsOf(mapOf("numberOfLines" to 2L, "overflow" to "visible"), sty(), black, 375f).overflow)
|
|
374
|
-
assertEquals(TextOverflow.Clip, textArgsOf(mapOf("numberOfLines" to 0L), sty(), black, 375f).overflow)
|
|
375
|
-
assertEquals(2, textArgsOf(mapOf("numberOfLines" to 2L, "minLines" to 5L), sty(), black, 375f).minLines)
|
|
376
|
-
assertEquals(3, textArgsOf(mapOf("minLines" to 3L), sty(), black, 375f).minLines)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
@Test fun textOptionalPassThroughProps() {
|
|
380
|
-
val a = textArgsOf(
|
|
381
|
-
mapOf("fontFamily" to "Mono", "softWrap" to false, "accessibilityId" to "t1", "textDecoration" to "underline", "letterSpacing" to 2L),
|
|
382
|
-
sty(), black, 375f,
|
|
383
|
-
)
|
|
384
|
-
assertEquals("Mono", a.fontFamily)
|
|
385
|
-
assertFalse(a.softWrap)
|
|
386
|
-
assertEquals("t1", a.accessibilityId)
|
|
387
|
-
assertNotNull(a.decoration)
|
|
388
|
-
assertEquals(2f, a.letterSpacing.value, 0f)
|
|
389
|
-
assertNull(textArgsOf(mapOf("fontFamily" to ""), sty(), black, 375f).fontFamily)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// ---- title / image / icon ------------------------------------------------------------------------------------------
|
|
393
|
-
@Test fun titleDefaults() {
|
|
394
|
-
val a = titleArgsOf(emptyMap())
|
|
395
|
-
assertEquals("", a.title)
|
|
396
|
-
assertEquals(TitleType.Section, a.type)
|
|
397
|
-
assertEquals(TitleSize.Medium, a.size)
|
|
398
|
-
assertNull(a.icon)
|
|
399
|
-
assertNull(a.iconColor)
|
|
400
|
-
assertEquals(IconAlign.Top, a.iconAlign)
|
|
401
|
-
assertFalse(a.showRightAction)
|
|
402
|
-
assertFalse(a.showTrailingAction)
|
|
403
|
-
assertFalse(a.textOnly)
|
|
404
|
-
assertNull(a.description)
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
@Test fun titleFullProps() {
|
|
408
|
-
val a = titleArgsOf(mapOf(
|
|
409
|
-
"title" to "T", "type" to "card", "size" to "large", "icon" to "ic", "iconColor" to "white", "iconAlign" to "center",
|
|
410
|
-
"showRightAction" to true, "showTrailingAction" to true, "badgeLabel" to "5", "buttonTitle" to "Go", "buttonSize" to "large",
|
|
411
|
-
"textOnly" to true, "description" to "d",
|
|
412
|
-
))
|
|
413
|
-
assertEquals("T", a.title)
|
|
414
|
-
assertEquals(TitleType.Card, a.type)
|
|
415
|
-
assertEquals(TitleSize.Large, a.size)
|
|
416
|
-
assertEquals("ic", a.icon)
|
|
417
|
-
assertEquals(Color.White, a.iconColor)
|
|
418
|
-
assertEquals(IconAlign.Center, a.iconAlign)
|
|
419
|
-
assertTrue(a.showRightAction && a.showTrailingAction && a.textOnly)
|
|
420
|
-
assertEquals("5", a.badgeLabel)
|
|
421
|
-
assertEquals("Go", a.buttonTitle)
|
|
422
|
-
assertEquals(vn.momo.kits.components.ButtonSize.Large, a.buttonSize)
|
|
423
|
-
assertEquals("d", a.description)
|
|
424
|
-
// only a literal true counts
|
|
425
|
-
assertFalse(titleArgsOf(mapOf("showRightAction" to "true")).showRightAction)
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
@Test fun imageWithoutUsableSourceIsNull() {
|
|
429
|
-
assertNull(imageArgsOf(emptyMap()))
|
|
430
|
-
assertNull(imageArgsOf(mapOf("source" to "")))
|
|
431
|
-
assertNull(imageArgsOf(mapOf("source" to mapOf("uri" to ""))))
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
@Test fun imageDefaults() {
|
|
435
|
-
val a = imageArgsOf(mapOf("source" to "http://x"))!!
|
|
436
|
-
assertEquals("http://x", a.url)
|
|
437
|
-
assertEquals(Alignment.TopStart, a.alignment)
|
|
438
|
-
assertEquals(ContentScale.Crop, a.contentScale)
|
|
439
|
-
assertNull(a.colorFilter)
|
|
440
|
-
assertEquals(1f, a.alpha, 0f)
|
|
441
|
-
assertTrue(a.loading)
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
@Test fun imageResizeAlignmentTintAlphaLoading() {
|
|
445
|
-
val a = imageArgsOf(mapOf(
|
|
446
|
-
"source" to mapOf("uri" to "http://y"), "resizeMode" to "contain", "alignment" to "center",
|
|
447
|
-
"colorFilter" to "white", "alpha" to 3, "loading" to false,
|
|
448
|
-
))!!
|
|
449
|
-
assertEquals("http://y", a.url)
|
|
450
|
-
assertEquals(ContentScale.Fit, a.contentScale)
|
|
451
|
-
assertEquals(Alignment.Center, a.alignment)
|
|
452
|
-
assertNotNull(a.colorFilter)
|
|
453
|
-
assertEquals(1f, a.alpha, 0f)
|
|
454
|
-
assertFalse(a.loading)
|
|
455
|
-
assertEquals(ContentScale.FillBounds, imageArgsOf(mapOf("source" to "u", "resizeMode" to "stretch"))!!.contentScale)
|
|
456
|
-
assertEquals(ContentScale.Crop, imageArgsOf(mapOf("source" to "u", "resizeMode" to "cover"))!!.contentScale)
|
|
457
|
-
assertEquals(0f, imageArgsOf(mapOf("source" to "u", "alpha" to -1))!!.alpha, 0f)
|
|
458
|
-
// only a literal false turns loading off
|
|
459
|
-
assertTrue(imageArgsOf(mapOf("source" to "u", "loading" to "false"))!!.loading)
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
@Test fun iconDefaultsAndOverrides() {
|
|
463
|
-
val d = iconArgsOf(emptyMap(), black)
|
|
464
|
-
assertEquals("", d.source)
|
|
465
|
-
assertEquals(24.dp, d.size)
|
|
466
|
-
assertEquals(black, d.color)
|
|
467
|
-
val a = iconArgsOf(mapOf("source" to "ic_x", "size" to 16L, "color" to "white"), black)
|
|
468
|
-
assertEquals("ic_x", a.source)
|
|
469
|
-
assertEquals(16.dp, a.size)
|
|
470
|
-
assertEquals(Color.White, a.color)
|
|
471
|
-
assertEquals(0.dp, iconArgsOf(mapOf("size" to -5L), black).size)
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// ---- pagination / scroll --------------------------------------------------------------------------------------------
|
|
475
|
-
@Test fun paginationDefaults() {
|
|
476
|
-
val a = paginationArgsOf(emptyMap())
|
|
477
|
-
assertEquals(PaginationKind.DOT, a.kind)
|
|
478
|
-
assertEquals(0, a.active)
|
|
479
|
-
assertEquals(3, a.length)
|
|
480
|
-
assertEquals(2, a.numberLength)
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
@Test fun paginationExplicitLengthAppliesToNumberToo() {
|
|
484
|
-
val a = paginationArgsOf(mapOf("type" to "number", "activeIndex" to 1L, "dataLength" to 7L))
|
|
485
|
-
assertEquals(PaginationKind.NUMBER, a.kind)
|
|
486
|
-
assertEquals(1, a.active)
|
|
487
|
-
assertEquals(7, a.length)
|
|
488
|
-
assertEquals(7, a.numberLength)
|
|
489
|
-
assertEquals(PaginationKind.WHITE_DOT, paginationArgsOf(mapOf("type" to "white-dot")).kind)
|
|
490
|
-
assertEquals(PaginationKind.SCROLL, paginationArgsOf(mapOf("type" to "scroll")).kind)
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
@Test fun scrollDefaultsToVerticalEnabled() {
|
|
494
|
-
val a = scrollArgsOf(emptyMap())
|
|
495
|
-
assertFalse(a.horizontal)
|
|
496
|
-
assertTrue(a.enabled)
|
|
497
|
-
assertFalse(a.reverse)
|
|
498
|
-
assertEquals(Arrangement.Start, a.horizontalArrangement)
|
|
499
|
-
assertEquals(Arrangement.Top, a.verticalArrangement)
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
@Test fun scrollHorizontalFlagsAndArrangements() {
|
|
503
|
-
val a = scrollArgsOf(mapOf(
|
|
504
|
-
"horizontal" to true, "enabled" to false, "reverseScrolling" to true,
|
|
505
|
-
"horizontalArrangement" to "space_between", "verticalArrangement" to "bottom",
|
|
506
|
-
))
|
|
507
|
-
assertTrue(a.horizontal)
|
|
508
|
-
assertFalse(a.enabled)
|
|
509
|
-
assertTrue(a.reverse)
|
|
510
|
-
assertEquals(Arrangement.SpaceBetween, a.horizontalArrangement)
|
|
511
|
-
assertEquals(Arrangement.Bottom, a.verticalArrangement)
|
|
512
|
-
assertFalse(scrollArgsOf(mapOf("horizontal" to "true")).horizontal)
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// ---- search -----------------------------------------------------------------------------------------------------------
|
|
516
|
-
private fun searchNode(vararg callbacks: String) = mapOf(
|
|
517
|
-
"type" to "InputSearch",
|
|
518
|
-
"actions" to callbacks.map { mapOf("name" to it, "type" to "noop") },
|
|
519
|
-
)
|
|
520
|
-
|
|
521
|
-
@Test fun searchDefaults() {
|
|
522
|
-
val a = searchArgsOf(mapOf("type" to "InputSearch"), emptyMap())
|
|
523
|
-
assertEquals("", a.buttonText)
|
|
524
|
-
assertFalse(a.showButtonText)
|
|
525
|
-
assertEquals("", a.placeholder)
|
|
526
|
-
assertFalse(a.disabled)
|
|
527
|
-
assertEquals("", a.icon)
|
|
528
|
-
assertEquals(Color.Unspecified, a.iconColor)
|
|
529
|
-
assertFalse(a.loading)
|
|
530
|
-
assertEquals(InputFontWeight.REGULAR, a.fontWeight)
|
|
531
|
-
assertEquals(KeyboardType.Text, a.keyboardType)
|
|
532
|
-
assertEquals(Color.Unspecified, a.backgroundColor)
|
|
533
|
-
assertNull(a.leftPosition)
|
|
534
|
-
assertEquals(listOf("onFocus"), a.focusEvents)
|
|
535
|
-
assertFalse(a.overlay)
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
@Test fun searchPlaceholderPrefersFirstTypingData() {
|
|
539
|
-
assertEquals("a", searchArgsOf(emptyMap(), mapOf("typingData" to listOf("a", "b"), "placeholder" to "p")).placeholder)
|
|
540
|
-
assertEquals("p", searchArgsOf(emptyMap(), mapOf("placeholder" to "p")).placeholder)
|
|
541
|
-
assertEquals("p", searchArgsOf(emptyMap(), mapOf("typingData" to emptyList<Any?>(), "placeholder" to "p")).placeholder)
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
@Test fun searchLeftPositionClampedAndPropsMapped() {
|
|
545
|
-
assertEquals(0.dp, searchArgsOf(emptyMap(), mapOf("leftPosition" to -4L)).leftPosition)
|
|
546
|
-
assertEquals(10.dp, searchArgsOf(emptyMap(), mapOf("leftPosition" to 10L)).leftPosition)
|
|
547
|
-
val a = searchArgsOf(emptyMap(), mapOf(
|
|
548
|
-
"buttonText" to "Go", "showButtonText" to true, "disabled" to true, "icon" to "i", "iconColor" to "white",
|
|
549
|
-
"loading" to true, "fontWeight" to "bold", "backgroundColor" to "black",
|
|
550
|
-
))
|
|
551
|
-
assertEquals("Go", a.buttonText)
|
|
552
|
-
assertTrue(a.showButtonText && a.disabled && a.loading)
|
|
553
|
-
assertEquals("i", a.icon)
|
|
554
|
-
assertEquals(Color.White, a.iconColor)
|
|
555
|
-
assertEquals(InputFontWeight.BOLD, a.fontWeight)
|
|
556
|
-
assertEquals(Color.Black, a.backgroundColor)
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
@Test fun searchPurePressableShowsOverlayAndNeverPressesOnFocus() {
|
|
560
|
-
val a = searchArgsOf(searchNode("onPress"), emptyMap())
|
|
561
|
-
assertTrue(a.overlay)
|
|
562
|
-
assertEquals(listOf("onFocus"), a.focusEvents)
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
@Test fun searchPressPlusTypingFiresPressOnFocusWithoutOverlay() {
|
|
566
|
-
val a = searchArgsOf(searchNode("onPress", "onChangeText"), emptyMap())
|
|
567
|
-
assertFalse(a.overlay)
|
|
568
|
-
assertEquals(listOf("onFocus", "onPress"), a.focusEvents)
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
@Test fun searchTypingOnlyHasNeitherOverlayNorPressOnFocus() {
|
|
572
|
-
val a = searchArgsOf(searchNode("onFocus"), emptyMap())
|
|
573
|
-
assertFalse(a.overlay)
|
|
574
|
-
assertEquals(listOf("onFocus"), a.focusEvents)
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// ---- tab view ---------------------------------------------------------------------------------------------------------
|
|
578
|
-
@Test fun tabViewWithoutTabsIsNull() {
|
|
579
|
-
assertNull(tabViewArgsOf(emptyMap()))
|
|
580
|
-
assertNull(tabViewArgsOf(mapOf("tabs" to emptyList<Any?>())))
|
|
581
|
-
assertNull(tabViewArgsOf(mapOf("tabs" to listOf("not a map", 3L))))
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
@Test fun tabViewDefaultsAndTabItems() {
|
|
585
|
-
val a = tabViewArgsOf(mapOf("tabs" to listOf(
|
|
586
|
-
mapOf("title" to "A", "icon" to "ic"),
|
|
587
|
-
mapOf("title" to "B", "icon" to "https://cdn/x.png", "showDot" to true, "dotSize" to "large", "badgeValue" to "3", "accessibilityLabel" to "b"),
|
|
588
|
-
"skipped",
|
|
589
|
-
)))!!
|
|
590
|
-
assertEquals(2, a.tabs.size)
|
|
591
|
-
assertEquals(0, a.selected)
|
|
592
|
-
assertEquals(TabViewType.DEFAULT, a.type)
|
|
593
|
-
assertFalse(a.scrollable)
|
|
594
|
-
assertFalse(a.fitContent)
|
|
595
|
-
assertNull(a.selectedColor)
|
|
596
|
-
assertNull(a.unselectedColor)
|
|
597
|
-
assertEquals(TabViewDirection.ROW, a.direction)
|
|
598
|
-
assertTrue(a.userScrollEnabled)
|
|
599
|
-
assertEquals(TabItemArgs("A", "ic", false, false, DotSize.Small, null, null), a.tabs[0])
|
|
600
|
-
assertEquals(TabItemArgs("B", "https://cdn/x.png", true, true, DotSize.Large, "3", "b"), a.tabs[1])
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
@Test fun tabViewSelectedIndexClampedAndTabsCappedAtTwelve() {
|
|
604
|
-
val many = (1..20).map { mapOf("title" to "t$it") }
|
|
605
|
-
assertEquals(12, tabViewArgsOf(mapOf("tabs" to many))!!.tabs.size)
|
|
606
|
-
assertEquals(11, tabViewArgsOf(mapOf("tabs" to many, "selectedIndex" to 99L))!!.selected)
|
|
607
|
-
assertEquals(0, tabViewArgsOf(mapOf("tabs" to many, "selectedIndex" to -3L))!!.selected)
|
|
608
|
-
assertEquals(2, tabViewArgsOf(mapOf("tabs" to many, "selectedIndex" to 2L))!!.selected)
|
|
609
|
-
assertEquals(0, tabViewArgsOf(mapOf("tabs" to many, "selectedIndex" to "2"))!!.selected)
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
@Test fun tabViewOptions() {
|
|
613
|
-
val a = tabViewArgsOf(mapOf(
|
|
614
|
-
"tabs" to listOf(mapOf("title" to "A")), "type" to "card", "scrollable" to true, "fitContent" to true,
|
|
615
|
-
"selectedColor" to "white", "unselectedColor" to "black", "direction" to "column", "userScrollEnabled" to false,
|
|
616
|
-
))!!
|
|
617
|
-
assertEquals(TabViewType.CARD, a.type)
|
|
618
|
-
assertTrue(a.scrollable && a.fitContent)
|
|
619
|
-
assertEquals(Color.White, a.selectedColor)
|
|
620
|
-
assertEquals(Color.Black, a.unselectedColor)
|
|
621
|
-
assertEquals(TabViewDirection.COLUMN, a.direction)
|
|
622
|
-
assertFalse(a.userScrollEnabled)
|
|
623
|
-
assertEquals("", a.tabs[0].icon)
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// ---- carousel ---------------------------------------------------------------------------------------------------------
|
|
627
|
-
@Test fun carouselWithoutSlidesIsNull() {
|
|
628
|
-
assertNull(carouselArgsOf(emptyMap(), 0))
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
@Test fun carouselDefaults() {
|
|
632
|
-
val a = carouselArgsOf(emptyMap(), 3)!!
|
|
633
|
-
assertEquals(0, a.target)
|
|
634
|
-
assertFalse(a.loop)
|
|
635
|
-
assertFalse(a.autoplay)
|
|
636
|
-
assertEquals(3000L, a.autoplayInterval)
|
|
637
|
-
assertTrue(a.scrollEnabled)
|
|
638
|
-
assertEquals(1f, a.inactiveSlideOpacity, 0f)
|
|
639
|
-
assertEquals(1f, a.inactiveSlideScale, 0f)
|
|
640
|
-
assertEquals(0.dp, a.contentPadding.calculateLeftPadding(LayoutDirection.Ltr))
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
@Test fun carouselIndexClampedIntoSlideRange() {
|
|
644
|
-
assertEquals(2, carouselArgsOf(mapOf("index" to 9L), 3)!!.target)
|
|
645
|
-
assertEquals(0, carouselArgsOf(mapOf("index" to -1L), 3)!!.target)
|
|
646
|
-
assertEquals(1, carouselArgsOf(mapOf("index" to 1L), 3)!!.target)
|
|
647
|
-
assertEquals(0, carouselArgsOf(mapOf("index" to 5L), 1)!!.target)
|
|
648
|
-
assertEquals(0, carouselArgsOf(mapOf("index" to "1"), 3)!!.target)
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
@Test fun carouselOptions() {
|
|
652
|
-
val a = carouselArgsOf(mapOf(
|
|
653
|
-
"loop" to true, "autoplay" to true, "autoplayInterval" to 10L, "scrollEnabled" to false,
|
|
654
|
-
"inactiveSlideOpacity" to 0.5, "inactiveSlideScale" to 0.9, "contentPadding" to 16L,
|
|
655
|
-
), 2)!!
|
|
656
|
-
assertTrue(a.loop && a.autoplay)
|
|
657
|
-
assertEquals(1000L, a.autoplayInterval)
|
|
658
|
-
assertFalse(a.scrollEnabled)
|
|
659
|
-
assertEquals(0.5f, a.inactiveSlideOpacity, 0f)
|
|
660
|
-
assertEquals(0.9f, a.inactiveSlideScale, 0f)
|
|
661
|
-
assertEquals(16.dp, a.contentPadding.calculateLeftPadding(LayoutDirection.Ltr))
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// ---- screenChildTopOf (nested Screen = grid region) -------------------------------------------------------------------
|
|
665
|
-
@Test fun screenChildGetsSpacingMByDefault() {
|
|
666
|
-
assertEquals(Spacing.M, screenChildTopOf(emptyMap(), emptyMap()))
|
|
667
|
-
assertEquals(Spacing.M, screenChildTopOf(mapOf("useGridLayout" to true), mapOf("useMargin" to true)))
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
@Test fun screenChildTopIsZeroWithoutGridLayout() {
|
|
671
|
-
assertEquals(0.dp, screenChildTopOf(mapOf("useGridLayout" to false), emptyMap()))
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
@Test fun screenChildTopIsZeroWhenChildOptsOutOfMargin() {
|
|
675
|
-
assertEquals(0.dp, screenChildTopOf(emptyMap(), mapOf("useMargin" to false)))
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
@Test fun screenChildTopOnlyBooleanFalseTurnsTheGapOff() {
|
|
679
|
-
// `!= false`: a string "false", 0, null or any other value keeps the gap
|
|
680
|
-
for (v in listOf("false", 0L, 0, null, "", "{state.x}")) {
|
|
681
|
-
assertEquals("useGridLayout=$v", Spacing.M, screenChildTopOf(mapOf("useGridLayout" to v), emptyMap()))
|
|
682
|
-
assertEquals("useMargin=$v", Spacing.M, screenChildTopOf(emptyMap(), mapOf("useMargin" to v)))
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// ---- absolute overlay / shrink-to-fit column ---------------------------------------------------------------------
|
|
687
|
-
@Test fun cornerAlignmentMapsEachCorner() {
|
|
688
|
-
assertEquals(Alignment.TopStart, cornerAlignment(Corner.TOP_START))
|
|
689
|
-
assertEquals(Alignment.TopEnd, cornerAlignment(Corner.TOP_END))
|
|
690
|
-
assertEquals(Alignment.BottomStart, cornerAlignment(Corner.BOTTOM_START))
|
|
691
|
-
assertEquals(Alignment.BottomEnd, cornerAlignment(Corner.BOTTOM_END))
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
private fun n(type: String, styles: Map<String, Any?>? = null, vararg kids: Map<String, Any?>): Map<String, Any?> =
|
|
695
|
-
buildMap { put("type", type); if (styles != null) put("styles", styles); if (kids.isNotEmpty()) put("children", kids.toList()) }
|
|
696
|
-
|
|
697
|
-
@Test fun intrinsicSafeAllowsPlainViewsTextsAndFixedImages() {
|
|
698
|
-
assertTrue(intrinsicSafe(n("View", null, n("Text"), n("Icon"), n("Badge"), n("Tag"))))
|
|
699
|
-
assertTrue(intrinsicSafe(n("TouchableOpacity", null, n("Image", mapOf("width" to 32, "height" to 32)))))
|
|
700
|
-
// the kit Image is a BoxWithConstraints: only fixed numeric sides answer intrinsics without subcomposing
|
|
701
|
-
assertFalse(intrinsicSafe(n("View", null, n("Image", mapOf("width" to 32)))))
|
|
702
|
-
assertFalse(intrinsicSafe(n("View", null, n("Image", mapOf("width" to "50%", "height" to 32)))))
|
|
703
|
-
assertFalse(intrinsicSafe(n("View", null, n("Image"))))
|
|
704
|
-
assertFalse("negative size is dropped, not fixed", intrinsicSafe(n("View", null, n("Image", mapOf("width" to -1, "height" to 40)))))
|
|
705
|
-
assertTrue(intrinsicSafe(n("View", null, n("Image", mapOf("width" to 0, "height" to 0.5)))))
|
|
706
|
-
// anything else (scrolls, grids, kit nodes, unknown) is not checked, so not safe; nested too
|
|
707
|
-
for (t in listOf("ScrollView", "Section", "Carousel", "Button", "ImageBackground", "Nope")) assertFalse(t, intrinsicSafe(n("View", null, n(t))))
|
|
708
|
-
assertFalse(intrinsicSafe(n("View", null, n("View", null, n("View", null, n("ScrollView"))))))
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
private val column = ViewPlan(stretchH = false, stretch = false, weight = false, sized = false, fillMain = false, wrapBox = false)
|
|
712
|
-
private val pill = n("View", null, n("Text"))
|
|
713
|
-
|
|
714
|
-
@Test fun shrinkWrapsAColumnTheParentDoesNotStretch() {
|
|
715
|
-
assertTrue(shrinkWrapsColumn(sty(), column, listOf(sty()), pill))
|
|
716
|
-
assertTrue(shrinkWrapsColumn(sty("alignItems" to "stretch"), column, listOf(sty()), pill))
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
@Test fun shrinkWrapLeavesEveryOtherViewAlone() {
|
|
720
|
-
assertFalse("stretched by its parent", shrinkWrapsColumn(sty(), column.copy(stretch = true), listOf(sty()), pill))
|
|
721
|
-
assertFalse("flex: 1", shrinkWrapsColumn(sty(), column.copy(weight = true), listOf(sty()), pill))
|
|
722
|
-
assertFalse("row", shrinkWrapsColumn(sty("flexDirection" to "row"), column, listOf(sty()), pill))
|
|
723
|
-
for (a in listOf("center", "flex-start", "flex-end")) assertFalse(a, shrinkWrapsColumn(sty("alignItems" to a), column, listOf(sty()), pill))
|
|
724
|
-
for (k in listOf("width", "minWidth", "maxWidth")) assertFalse(k, shrinkWrapsColumn(sty(k to 40), column, listOf(sty()), pill))
|
|
725
|
-
assertFalse("no child stretches", shrinkWrapsColumn(sty(), column, listOf(sty("width" to 20)), pill))
|
|
726
|
-
assertFalse("absolute children do not stretch", shrinkWrapsColumn(sty(), column, listOf(sty("position" to "absolute")), pill))
|
|
727
|
-
assertFalse("no children", shrinkWrapsColumn(sty(), column, emptyList(), pill))
|
|
728
|
-
assertFalse("unsafe subtree", shrinkWrapsColumn(sty(), column, listOf(sty()), n("View", null, n("Image"))))
|
|
729
|
-
for (g in listOf("flex" to 0.7, "flex" to 2, "flexGrow" to 1)) assertFalse("grows $g", shrinkWrapsColumn(sty(g), column, listOf(sty()), pill))
|
|
730
|
-
assertTrue("flex 0 does not grow", shrinkWrapsColumn(sty("flex" to 0), column, listOf(sty()), pill))
|
|
731
|
-
assertFalse("absolute", shrinkWrapsColumn(sty("position" to "absolute", "left" to 0, "right" to 0), column, listOf(sty()), pill))
|
|
732
|
-
assertFalse("alignSelf stretch", shrinkWrapsColumn(sty("alignSelf" to "stretch"), column, listOf(sty()), pill))
|
|
733
|
-
assertFalse("percent child", shrinkWrapsColumn(sty(), column, listOf(sty(), sty("width" to "50%")), pill))
|
|
734
|
-
// a percent size deeper down (grandchild in a column or a row) still feeds back: the whole subtree is checked
|
|
735
|
-
assertFalse("nested percent", shrinkWrapsColumn(sty(), column, listOf(sty()), n("View", null, n("View", null, n("Text"), n("View", mapOf("width" to "50%"))))))
|
|
736
|
-
assertFalse("size bound to data (may be a percent)", shrinkWrapsColumn(sty(), column, listOf(sty()), n("View", null, n("View", mapOf("width" to "{w}")))))
|
|
737
|
-
assertTrue("a binding on a non-size key is fine", shrinkWrapsColumn(sty(), column, listOf(sty()), n("View", mapOf("backgroundColor" to "{c}"), n("Text"))))
|
|
738
|
-
assertFalse("nested percent in a row", shrinkWrapsColumn(sty(), column, listOf(sty()), n("View", null, n("View", mapOf("flexDirection" to "row"), n("Text"), n("View", mapOf("minWidth" to " 30% "))))))
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
// AI-GENERATED END: unit tests for the pure drawing decisions extracted from the SDUI Compose renderer
|