@momo-kits/native-kits 0.169.13-beta.4-debug → 0.169.13

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.
Files changed (173) hide show
  1. package/CLAUDE.md +1 -4
  2. package/ios/Navigation/BottomTab/BottomTabBar.swift +14 -4
  3. package/ios/native-kits.podspec +1 -1
  4. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  5. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +16 -3
  6. package/package.json +1 -1
  7. package/build.gradle.kts +0 -11
  8. package/compose/build.gradle.kts +0 -202
  9. package/compose/compose.podspec +0 -47
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  14. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  15. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  16. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  17. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +0 -647
  18. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +0 -1411
  19. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +0 -130
  20. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +0 -524
  21. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +0 -559
  22. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +0 -741
  23. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +0 -221
  24. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +0 -270
  25. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +0 -849
  26. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +0 -212
  27. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +0 -239
  28. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +0 -252
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -206
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -421
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -750
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -398
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -103
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -400
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +0 -154
  139. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +0 -1038
  140. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +0 -848
  141. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +0 -47
  142. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +0 -39
  143. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +0 -463
  144. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +0 -1146
  145. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +0 -667
  146. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +0 -240
  147. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +0 -185
  148. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +0 -200
  149. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  150. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  151. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  152. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
  153. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  154. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  155. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  156. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  157. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
  158. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
  159. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  160. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
  161. package/gradle/libs.versions.toml +0 -69
  162. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  163. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  164. package/gradle.properties +0 -24
  165. package/gradlew +0 -252
  166. package/gradlew.bat +0 -94
  167. package/ios-demo/README.md +0 -120
  168. package/scripts/sdui-visual/README.md +0 -64
  169. package/scripts/sdui-visual/diff.py +0 -65
  170. package/scripts/sdui-visual/drive.py +0 -234
  171. package/scripts/sdui-visual/plan.json +0 -713
  172. package/scripts/sdui-visual/run.sh +0 -92
  173. package/settings.gradle.kts +0 -64
@@ -1,559 +0,0 @@
1
- // File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt
2
- // Created At: 2026-10-30 11: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.runtime.mutableStateMapOf
10
- import androidx.compose.ui.graphics.Color
11
- import androidx.compose.ui.text.input.KeyboardType
12
- import androidx.compose.ui.unit.dp
13
- import kotlinx.serialization.json.Json
14
- import java.io.File
15
- import org.junit.Assert.assertArrayEquals
16
- import org.junit.Assert.assertEquals
17
- import org.junit.Assert.assertFalse
18
- import org.junit.Assert.assertTrue
19
- import org.junit.Test
20
- import vn.momo.kits.components.AvatarSize
21
- import vn.momo.kits.components.ButtonType
22
- import vn.momo.kits.components.CollapseTitleSize
23
- import vn.momo.kits.components.DividerType
24
- import vn.momo.kits.components.IconShape
25
- import vn.momo.kits.components.IconSize
26
- import vn.momo.kits.components.InformationState
27
- import vn.momo.kits.components.InputFontWeight
28
- import vn.momo.kits.components.InputPhoneNumberSize
29
- import vn.momo.kits.components.InputSize
30
- import vn.momo.kits.components.LoaderType
31
- import vn.momo.kits.components.PopupActionDirection
32
- import vn.momo.kits.components.ProgressInfoAlign
33
- import vn.momo.kits.components.ProgressInfoSize
34
- import vn.momo.kits.components.RatingSize
35
- import vn.momo.kits.components.StepItem
36
- import vn.momo.kits.components.StepperSize
37
- import vn.momo.kits.components.StepsAlign
38
- import vn.momo.kits.components.StepsSize
39
- import vn.momo.kits.components.TagColor
40
- import vn.momo.kits.components.UploadImage
41
- import vn.momo.kits.const.defaultTheme
42
-
43
- // AI-GENERATED START: unit tests for the kit-backed SDUI nodes: prop -> kit mapping and callback -> action dispatch
44
- class SduiKitNodesTest {
45
- private val state = mutableStateMapOf<String, Any?>()
46
- private val runner = SduiActionRunner(state, { defaultTheme })
47
- private val scope = SduiScope(emptyMap(), state)
48
-
49
- private fun node(json: String): Node = Json.parseToJsonElement(json).toPlain().asMap()!!
50
-
51
- /** Fires the callback [name] of [json] with [args], exactly like KitNode.fire does. */
52
- private fun fire(json: String, name: String, vararg args: Any?) {
53
- runner.run(actionsFor(node(json), name), name, scope, args.toList())
54
- }
55
-
56
- @Test fun everyKitTypeIsRegistered() {
57
- assertEquals(27, KIT_NODE_TYPES.size)
58
- listOf("Avatar", "Swipe", "Uploader", "PopupNotify", "PopupPromotion").forEach { assertTrue(it in KIT_NODE_TYPES) }
59
- }
60
-
61
- // ---- Avatar / Divider / Loader / Skeleton / TrustBanner: props only ----------------------------------------------
62
- @Test fun avatarSizeSnapsToTheKitSizes() {
63
- assertEquals(AvatarSize.SIZE_24, avatarSizeOf(24L))
64
- assertEquals(AvatarSize.SIZE_32, avatarSizeOf(null))
65
- assertEquals(AvatarSize.SIZE_40, avatarSizeOf(40L))
66
- assertEquals(AvatarSize.SIZE_48, avatarSizeOf(48.0))
67
- assertEquals(AvatarSize.SIZE_56, avatarSizeOf("56"))
68
- assertEquals(AvatarSize.SIZE_72, avatarSizeOf(72L))
69
- assertEquals(AvatarSize.SIZE_72, avatarSizeOf(200L))
70
- }
71
-
72
- @Test fun dividerAndLoaderEnums() {
73
- assertEquals(DividerType.DASH, dividerTypeOf("dash"))
74
- assertEquals(DividerType.DEFAULT, dividerTypeOf(null))
75
- assertEquals(LoaderType.SPINNER, loaderTypeOf("spinner"))
76
- assertEquals(LoaderType.DOT, loaderTypeOf("anything else"))
77
- }
78
-
79
- @Test fun skeletonAndTrustBannerTakeNoCallbacks() {
80
- assertTrue(actionsFor(node("""{"type":"Skeleton","styles":{"width":160,"height":24}}"""), "onPress").isEmpty())
81
- assertTrue(actionsFor(node("""{"type":"TrustBanner","props":{"screenName":"S","serviceName":"x"}}"""), "onPress").isEmpty())
82
- }
83
-
84
- // ---- value controls: callback writes spec state ---------------------------------------------------------------
85
- @Test fun checkBoxWritesTheNewBoolean() {
86
- fire("""{"type":"CheckBox","props":{"value":"{agreed}"},"actions":[{"name":"onChange","args":["next"],"type":"setState","params":{"agreed":"{next}"}}]}""", "onChange", true)
87
- assertEquals(true, state["agreed"])
88
- }
89
-
90
- @Test fun switchWritesTheNewBoolean() {
91
- fire("""{"type":"Switch","props":{"value":"{on}"},"actions":[{"name":"onChange","args":["next"],"type":"setState","params":{"on":"{next}"}}]}""", "onChange", true)
92
- assertEquals(true, state["on"])
93
- }
94
-
95
- @Test fun radioOnChangeHasNoArgsAndSetsItsOwnValue() {
96
- val json = """{"type":"Radio","props":{"value":"momo","groupValue":"{pay}"},"actions":[{"name":"onChange","type":"setState","params":{"pay":"{'momo'}"}}]}"""
97
- fire(json, "onChange")
98
- assertEquals("momo", state["pay"])
99
- }
100
-
101
- @Test fun inputsWriteTheTypedText() {
102
- listOf("Input", "InputMoney", "InputPhoneNumber", "InputTextArea", "InputOTP").forEach { type ->
103
- state.remove("v")
104
- fire("""{"type":"$type","props":{"value":"{v}"},"actions":[{"name":"onChangeText","args":["t"],"type":"setState","params":{"v":"{t}"}}]}""", "onChangeText", "123")
105
- assertEquals("$type", "123", state["v"])
106
- }
107
- }
108
-
109
- @Test fun inputTypedSetStateWritesTheTypedText() {
110
- val typed = SduiActionRunner(state, { defaultTheme }, declaredState = setOf("query"))
111
- val n = node("""{"type":"Input","props":{"value":"{query}"},"actions":[{"name":"onChangeText","args":["v"],"type":"setState","params":{"query":"{v}"}}]}""")
112
- typed.run(actionsFor(n, "onChangeText"), "onChangeText", scope, listOf("xin chao"))
113
- assertEquals("xin chao", state["query"])
114
- }
115
-
116
- @Test fun inputFocusBlurAndTrailingDispatch() {
117
- val json = """{"type":"Input","actions":[{"name":"onFocus","type":"setState","params":{"f":true}},{"name":"onBlur","type":"setState","params":{"b":true}},{"name":"onPressTrailing","type":"setState","params":{"t":true}}]}"""
118
- fire(json, "onFocus"); fire(json, "onBlur"); fire(json, "onPressTrailing")
119
- assertEquals(listOf(true, true, true), listOf(state["f"], state["b"], state["t"]))
120
- }
121
-
122
- @Test fun inputDropDownOnPressRunsItsAction() {
123
- fire("""{"type":"InputDropDown","props":{"value":"{p}"},"actions":[{"name":"onPress","type":"setState","params":{"opened":true}}]}""", "onPress")
124
- assertEquals(true, state["opened"])
125
- }
126
-
127
- @Test fun ratingReportsTheOneBasedStarAndIsReadOnlyWithoutHandler() {
128
- val json = """{"type":"Rating","props":{"numOfStars":5,"rating":"{stars}"},"actions":[{"name":"onRatingChange","args":["v"],"type":"setState","params":{"stars":"{v}"}}]}"""
129
- fire(json, "onRatingChange", 4L)
130
- assertEquals(4L, state["stars"])
131
- assertTrue(actionsFor(node("""{"type":"Rating","props":{"numOfStars":5,"rating":3}}"""), "onRatingChange").isEmpty())
132
- assertEquals(RatingSize.SMALL, ratingSizeOf("small"))
133
- assertEquals(RatingSize.LARGE, ratingSizeOf("nope"))
134
- }
135
-
136
- @Test fun sliderReportsLowHighByUser() {
137
- val json = """{"type":"Slider","props":{"min":0,"max":100},"actions":[{"name":"onValueChanged","args":["low","high","byUser"],"type":"setState","params":{"lo":"{low}","hi":"{high}","u":"{byUser}"}}]}"""
138
- fire(json, "onValueChanged", actionNumber(10f), actionNumber(72.5f), true)
139
- assertEquals(listOf<Any?>(10L, 72.5, true), listOf(state["lo"], state["hi"], state["u"]))
140
- assertTrue(sliderDisabled(mapOf("disabled" to true)))
141
- assertTrue(sliderDisabled(mapOf("disabledLow" to true, "disabledHigh" to true)))
142
- assertFalse(sliderDisabled(mapOf("disabledLow" to true)))
143
- }
144
-
145
- @Test fun stepperReportsTheClampedNumberAndDisabledPair() {
146
- fire("""{"type":"Stepper","props":{"defaultValue":"{q}"},"actions":[{"name":"onValueChange","args":["n"],"type":"setState","params":{"q":"{n}"}}]}""", "onValueChange", 3L)
147
- assertEquals(3L, state["q"])
148
- assertEquals(StepperSize.SMALL, stepperSizeOf("small"))
149
- // the kit checks `is BooleanArray`, so a List would silently mean "enabled"
150
- assertArrayEquals(booleanArrayOf(true, false), stepperDisabled(listOf(true, false)) as BooleanArray)
151
- assertArrayEquals(booleanArrayOf(false, true), stepperDisabled(listOf(false, true)) as BooleanArray)
152
- assertEquals(true, stepperDisabled(true))
153
- assertEquals(false, stepperDisabled(null))
154
- }
155
-
156
- @Test fun stepperWithMinAboveMaxDoesNotThrowInTheKit() {
157
- val a = stepperArgs(node("""{"min":10,"max":3,"defaultValue":1}"""))
158
- assertEquals(StepperArgs(defaultValue = 10, min = 10, max = 10, step = 1), a)
159
- // what the kit does with the arguments: coerceIn throws when min > max
160
- assertEquals(10, a.defaultValue.coerceIn(a.min, a.max))
161
- assertEquals(StepperArgs(5, 0, 100, 1), stepperArgs(node("""{"defaultValue":5}""")))
162
- assertEquals(StepperArgs(100, 0, 100, 2), stepperArgs(node("""{"defaultValue":900,"step":2}""")))
163
- }
164
-
165
- @Test fun sliderFloatsDoNotLeakBinaryNoise() {
166
- assertEquals(0.3, actionNumber(0.3f))
167
- assertEquals(72.5, actionNumber(72.5f))
168
- }
169
-
170
- @Test fun sizePropsUseTokensAndNeverGoNegative() {
171
- assertTrue(dpProp(resolveValue("Spacing.M", scope, defaultTheme), 99.dp) != 99.dp) // theme token -> Dp
172
- assertEquals(64.dp, dpProp(null, 64.dp))
173
- assertEquals(0.dp, dpProp(-5, 64.dp))
174
- assertEquals(80.dp, dpProp("80", 64.dp))
175
- assertEquals(null, countProp(-1L))
176
- assertEquals(4, countProp("4"))
177
- assertEquals(null, countProp(null))
178
- }
179
-
180
- @Test fun otpReKeysOnlyWhenTheBoundValueChangesAwayFromWhatWasTyped() {
181
- val s = OtpSync("")
182
- assertEquals(0, s.tokenFor(""))
183
- s.lastEmitted = "12" // user typed
184
- assertEquals(0, s.tokenFor("12")) // spec echoed it back: no re-create
185
- assertEquals(1, s.tokenFor("")) // set: {otp: ""} clears
186
- assertEquals(1, s.tokenFor("")) // stable on recomposition
187
- s.lastEmitted = "9"
188
- assertEquals(1, s.tokenFor("")) // unbound/constant value never resets typing
189
- }
190
-
191
- // ---- button-style action lists inside props -------------------------------------------------------------------------
192
- @Test fun propActionsDefaultTheNameAndFollowBindings() {
193
- val raw = node("""{"b":{"title":"x","actions":[{"type":"setState","params":{"k":"{v}"}},{"name":"onPress","type":"setState","params":{"j":1}}]}}""")["b"]
194
- assertEquals(listOf("onPress", "onPress"), propActions(raw, null).map { it.asMap()!!["name"] })
195
- // a binding string prop resolves to the map: use the resolved one
196
- val resolved = node("""{"title":"x","actions":[{"type":"setState","params":{"k":2}}]}""")
197
- assertEquals(1, propActions("{btn}", resolved).size)
198
- assertTrue(propActions(null, null).isEmpty())
199
- }
200
-
201
- @Test fun popupButtonActionsRunOnPress() {
202
- val raw = node("""{"primary":{"title":"OK","actions":[{"type":"setState","params":{"ok":true}}]}}""")["primary"]
203
- runner.run(propActions(raw, raw), "onPress", scope, emptyList())
204
- assertEquals(true, state["ok"])
205
- }
206
-
207
- @Test fun swipeActionsCarryTheirPressActions() {
208
- val props = node("""{"rightActions":[{"label":"del","icon":"i","actions":[{"type":"setState","params":{"gone":"{'x'}"}}]},{"label":"b"},{"label":"c"},{"label":"d"}]}""")
209
- val specs = swipeSpecs(props["rightActions"], props["rightActions"])
210
- assertEquals(3, specs.size)
211
- assertEquals("del", specs[0].label)
212
- runner.run(specs[0].actions, "onPress", scope, emptyList())
213
- assertEquals("x", state["gone"])
214
- assertTrue(specs[1].actions.isEmpty())
215
- // a binding string resolves to the list
216
- assertEquals(1, swipeSpecs("{rows}", props["rightActions"].asList()!!.take(1)).size)
217
- }
218
-
219
- // ---- validateStructure sees actions inside props ---------------------------------------------------------------------
220
- private fun errorsOf(props: String): List<String> =
221
- validateStructure(Json.parseToJsonElement("""{"meta":{},"body":{"type":"View","children":[{"type":"X","props":$props}]}}""").toPlain()).errors
222
-
223
- @Test fun validatorChecksActionsInCallbackPropsAndButtons() {
224
- assertTrue(errorsOf("""{"onPress":{"type":"setState","params":{"a":1}},"primary":{"actions":[{"type":"setState","params":{"a":1}}]},"rightActions":[{"actions":[{"type":"startFeatureCode","params":{"featureCode":"f"}}]}]}""").isEmpty())
225
- assertTrue(errorsOf("""{"onChange":{"bogus":1}}""").any { "onChange" in it && "bogus" in it })
226
- assertTrue(errorsOf("""{"primary":{"actions":[{"set":{"a":1}}]}}""").any { "primary.actions" in it })
227
- assertTrue(errorsOf("""{"leftActions":[{"actions":[{"navigate":"pop"}]}]}""").any { "leftActions[0].actions" in it })
228
- assertTrue(errorsOf("""{"onAdd":[{"type":"setState","params":{}},5]}""").any { "onAdd[1]" in it })
229
- // button-style `actions` are read as a list: a single object would be dropped at runtime
230
- assertTrue(errorsOf("""{"primary":{"actions":{"type":"setState","params":{"a":1}}}}""").any { "primary.actions must be a list" in it })
231
- assertTrue(errorsOf("""{"rightActions":[{"actions":{"type":"setState","params":{"a":1}}}]}""").any { "rightActions[0].actions must be a list" in it })
232
- assertTrue(errorsOf("""{"primary":{"actions":"{acts}"}}""").isEmpty())
233
- }
234
-
235
- @Test fun validatorChecksTrustBannerTrackEventPropActions() {
236
- assertTrue(errorsOf("""{"trackEvent":{"type":"trackEvent","when":true,"params":{"eventName":"e"}}}""").isEmpty())
237
- assertTrue(errorsOf("""{"trackEvent":[{"type":"trackEvent","when":"{x}","params":{"eventName":"e"}}]}""").isEmpty())
238
- assertTrue(errorsOf("""{"trackEvent":{"type":"trackEvent","when":"false","params":{"eventName":"e"}}}""").any { "props.trackEvent.when must be a boolean or a {binding}" in it })
239
- assertTrue(errorsOf("""{"trackEvent":{"params":{"eventName":"e"}}}""").any { "props.trackEvent" in it })
240
- assertTrue(errorsOf("""{"trackEvent":[{"type":"trackEvent","params":{}},{"bogus":1}]}""").any { "props.trackEvent[1]" in it })
241
- }
242
-
243
- private fun nodeErrorsOf(extra: String): List<String> =
244
- validateStructure(Json.parseToJsonElement("""{"meta":{},"body":{"type":"View","children":[{"type":"X",$extra}]}}""").toPlain()).errors
245
-
246
- // ---- validateStructure rejects style keys with no native equivalent ---------------------------------------------------
247
- private fun bodyErrorsOf(body: String): List<String> =
248
- validateStructure(Json.parseToJsonElement("""{"meta":{},"body":$body}""").toPlain()).errors
249
-
250
- @Test fun validatorRejectsUnsupportedStyleKeys() {
251
- UNSUPPORTED_STYLES.forEach { k ->
252
- val errs = nodeErrorsOf(""""styles":{"$k":1,"padding":4}""")
253
- assertEquals(k, listOf("body.children[0].styles.$k is not supported"), errs)
254
- assertTrue(k, bodyErrorsOf("""{"type":"View","styles":{"$k":"x"}}""").contains("body.styles.$k is not supported"))
255
- }
256
- // nested deeper: the path names the node
257
- val deep = bodyErrorsOf("""{"type":"View","children":[{"type":"View","children":[{"type":"Text","styles":{"transform":[{"rotate":"45deg"}]}}]}]}""")
258
- assertEquals(listOf("body.children[0].children[0].styles.transform is not supported"), deep)
259
- }
260
-
261
- @Test fun validatorRejectsExactlyTheKeysWithNoNativeMeaning() {
262
- assertEquals(
263
- setOf(
264
- "transform", "elevation", "shadowColor", "shadowOffset", "shadowOpacity", "shadowRadius", "backgroundImage", "display",
265
- "columnGap",
266
- ),
267
- UNSUPPORTED_STYLES,
268
- )
269
- assertTrue(UNSUPPORTED_STYLES.none { it in IGNORED_STYLES })
270
- }
271
-
272
- @Test fun validatorAcceptsTheIgnoredTextAndAlignSelfKeys() {
273
- assertEquals(listOf("fontSize", "fontWeight", "lineHeight", "letterSpacing", "color", "alignSelf"), IGNORED_STYLES.keys.toList())
274
- IGNORED_STYLES.keys.forEach { k ->
275
- assertTrue(k, nodeErrorsOf(""""styles":{"$k":"x","padding":4}""").isEmpty())
276
- assertTrue(k, bodyErrorsOf("""{"type":"View","styles":{"$k":1}}""").isEmpty())
277
- }
278
- }
279
-
280
- @Test fun validatorAcceptsSupportedAndUnlistedStyleKeys() {
281
- val ok = listOf(
282
- "opacity" to "0.5", "zIndex" to "2", "minWidth" to "10", "maxWidth" to "20", "minHeight" to "1", "maxHeight" to "2",
283
- "width" to "\"50%\"", "height" to "\"25%\"", "paddingStart" to "4", "paddingEnd" to "4", "marginStart" to "4",
284
- "marginEnd" to "4", "textAlign" to "\"center\"", "textTransform" to "\"uppercase\"", "borderTopWidth" to "1",
285
- "borderTopColor" to "\"#000\"", "borderBottomLeftRadius" to "4", "borderBottomRightRadius" to "4",
286
- "borderBottomWidth" to "1", "borderBottomColor" to "\"#000\"", "borderLeftWidth" to "1",
287
- "borderLeftColor" to "\"#000\"", "borderRightWidth" to "1", "borderRightColor" to "\"#000\"",
288
- "someFutureKey" to "1",
289
- )
290
- ok.forEach { (k, v) -> assertTrue(k, nodeErrorsOf(""""styles":{"$k":$v}""").isEmpty()) }
291
- // a whole-binding styles string is only known at render time
292
- assertTrue(nodeErrorsOf(""""styles":"{rowStyle}"""").isEmpty())
293
- assertTrue(bodyErrorsOf("""{"type":"View","styles":"{s}"}""").isEmpty())
294
- }
295
-
296
- @Test fun validatorAcceptsBooleanOrBindingConditions() {
297
- listOf("true", "false", "\"{state.a}\"", "\"{!x}\"", "\"{a} and {b}\"", "null").forEach { v ->
298
- assertTrue("when $v", nodeErrorsOf(""""actions":[{"name":"onPress","type":"setState","when":$v,"params":{}}]""").isEmpty())
299
- assertTrue("prop when $v", nodeErrorsOf(""""props":{"onPress":{"type":"setState","when":$v,"params":{}}}""").isEmpty())
300
- assertTrue("visible $v", nodeErrorsOf(""""visible":$v""").isEmpty())
301
- assertTrue("visibleWhen $v", nodeErrorsOf(""""visibleWhen":$v""").isEmpty())
302
- }
303
- }
304
-
305
- @Test fun validatorRejectsPlainStringNumberMapAndListConditions() {
306
- listOf("\"false\"", "\"0\"", "\"yes\"", "1", "{}", "[]").forEach { v ->
307
- assertTrue("when $v", nodeErrorsOf(""""actions":[{"name":"onPress","type":"setState","when":$v,"params":{}}]""").any { "actions[0].when must be a boolean or a {binding}" in it })
308
- assertTrue("prop when $v", nodeErrorsOf(""""props":{"onPress":{"type":"setState","when":$v,"params":{}}}""").any { "props.onPress.when must be a boolean or a {binding}" in it })
309
- assertTrue("visible $v", nodeErrorsOf(""""visible":$v""").any { ".visible must be a boolean or a {binding}" in it })
310
- assertTrue("visibleWhen $v", nodeErrorsOf(""""visibleWhen":$v""").any { ".visibleWhen must be a boolean or a {binding}" in it })
311
- }
312
- val body = validateStructure(Json.parseToJsonElement("""{"meta":{},"body":{"type":"View","visible":"false"}}""").toPlain()).errors
313
- assertTrue(body.any { "body.visible is not supported: the block body is always drawn once" in it })
314
- val repeated = nodeErrorsOf(""""repeat":{"source":"xs","as":"x"},"visible":"no"""")
315
- assertTrue(repeated.any { "visible must be a boolean" in it })
316
- }
317
-
318
- @Test fun validatorRejectsBareThenOnAction() {
319
- assertTrue(errorsOf("""{"onPress":{"type":"setState","params":{"a":1},"then":{"type":"setState","params":{"b":2}}}}""").any { "unknown field \"then\"" in it })
320
- }
321
-
322
- // ---- the gallery specs (sample resources) must validate and map without throwing, for all 27 kit types ---------------------
323
- private val sduiFiles = File("../sample/shared/src/commonMain/composeResources/files/sdui")
324
- private val galleryDir = File(sduiFiles, "gallery")
325
-
326
- @Test fun everyBundledSampleSpecValidates() {
327
- listOf("gallery", "showcase", "blocks").forEach { d ->
328
- val files = File(sduiFiles, d).listFiles { f -> f.extension == "json" }.orEmpty()
329
- assertTrue("$d missing at ${File(sduiFiles, d).absolutePath}", files.isNotEmpty())
330
- files.forEach { f ->
331
- val errs = validateStructure(Json.parseToJsonElement(f.readText()).toPlain()).errors
332
- assertTrue("$d/${f.name}: $errs", errs.isEmpty())
333
- }
334
- }
335
- }
336
-
337
- private fun kitNodes(n: Any?, out: MutableList<Node>) {
338
- n.asList()?.forEach { kitNodes(it, out) }
339
- val m = n.asMap() ?: return
340
- if (m["type"] in KIT_NODE_TYPES) out += m
341
- kitNodes(m["children"], out)
342
- }
343
-
344
- @Test fun everyKitTypeMapsItsGalleryPropsWithoutThrowing() {
345
- val files = galleryDir.listFiles { f -> f.extension == "json" }.orEmpty()
346
- assertTrue("gallery missing at ${galleryDir.absolutePath}", files.isNotEmpty())
347
- val seen = HashSet<String>()
348
- files.forEach { f ->
349
- val spec = Json.parseToJsonElement(f.readText()).toPlain()
350
- val errs = validateStructure(spec).errors
351
- assertTrue("${f.name}: $errs", errs.isEmpty())
352
- val nodes = ArrayList<Node>()
353
- kitNodes(spec.asMap()!!["body"], nodes)
354
- nodes.forEach { n ->
355
- val type = n["type"] as String
356
- seen += type
357
- val p = resolveValue(n.props(), scope, defaultTheme).asMap().orEmpty()
358
- val raw = n.props()
359
- // every normaliser KitNode feeds from props, applied to this node's real props
360
- avatarSizeOf(p["size"]); inputSizeOf(p["size"]); phoneSizeOf(p["size"]); dividerTypeOf(p["type"]); loaderTypeOf(p["type"])
361
- iconButtonTypeOf(p["type"]); iconButtonSizeOf(p["size"]); iconShapeOf(p["shape"]); informationStateOf(p["state"])
362
- collapseTitleSizeOf(p["titleSize"]); tagColorOf(p["tagProps"].asMap()?.get("color")); ratingSizeOf(p["size"])
363
- stepperSizeOf(p["size"]); stepsSizeOf(p["size"]); stepsAlignOf(p["align"]); progressSizeOf(p["size"])
364
- progressAlignOf(p["align"]); popupDirectionOf(p["buttonDirection"]); keyboardTypeOf(p["keyboardType"])
365
- dpProp(p["width"], 64.dp); dpProp(p["height"], 56.dp); countProp(p["maxLength"]); countProp(p["length"])
366
- progressItems(p["steps"]); stepItems(p["steps"]); uploadImages(p["images"])
367
- sliderDisabled(p)
368
- if (type == "Stepper") {
369
- val a = stepperArgs(p)
370
- a.defaultValue.coerceIn(a.min, a.max)
371
- stepperDisabled(p["disabled"])
372
- }
373
- if (type == "Swipe") { swipeSpecs(raw["leftActions"], p["leftActions"]); swipeSpecs(raw["rightActions"], p["rightActions"]) }
374
- if (type == "PopupNotify") { propActions(raw["primary"], p["primary"]); propActions(raw["secondary"], p["secondary"]) }
375
- listOf("onPress", "onChange", "onChangeText", "onValueChange", "onValueChanged", "onAdd").forEach { actionsFor(n, it) }
376
- }
377
- }
378
- assertEquals("kit types with no gallery node: ${KIT_NODE_TYPES - seen}", KIT_NODE_TYPES, seen)
379
- }
380
-
381
- // ---- display + press components ----------------------------------------------------------------------------------
382
- @Test fun collapseOnPressCarriesTheToggleState() {
383
- fire("""{"type":"Collapse","props":{"title":"t"},"actions":[{"name":"onPress","args":["was"],"type":"setState","params":{"open":"{!was}"}}]}""", "onPress", false)
384
- assertEquals(true, state["open"])
385
- assertEquals(CollapseTitleSize.Large, collapseTitleSizeOf("large"))
386
- assertEquals(CollapseTitleSize.Medium, collapseTitleSizeOf(null))
387
- assertEquals(TagColor.Green, tagColorOf("green"))
388
- }
389
-
390
- @Test fun iconButtonOnPressAndEnums() {
391
- fire("""{"type":"IconButton","props":{"icon":"x"},"actions":[{"name":"onPress","type":"setState","params":{"hit":true}}]}""", "onPress")
392
- assertEquals(true, state["hit"])
393
- assertEquals(ButtonType.TONAL, iconButtonTypeOf("tonal"))
394
- assertEquals(ButtonType.PRIMARY, iconButtonTypeOf(null))
395
- assertEquals(IconSize.SMALL, iconButtonSizeOf("small")); assertEquals(IconSize.SMALL, iconButtonSizeOf(null)); assertEquals(IconSize.LARGE, iconButtonSizeOf("large"))
396
- assertEquals(IconShape.SQUARE, iconShapeOf("square"))
397
- }
398
-
399
- @Test fun buttonExtraPropsNormalise() {
400
- val p = mapOf("iconLeft" to "arrow_back", "iconRight" to 5, "loading" to true, "useTintColor" to false)
401
- assertEquals("arrow_back", buttonIconOf(p["iconLeft"]))
402
- assertEquals("", buttonIconOf(p["iconRight"]))
403
- assertEquals("", buttonIconOf(null))
404
- assertEquals(true, buttonArgsOf(p).loading)
405
- assertEquals(false, buttonArgsOf(mapOf("loading" to "yes")).loading)
406
- assertEquals(false, boolOr(p["useTintColor"], true))
407
- assertEquals(true, boolOr(null, true))
408
- assertEquals(true, boolOr("no", true))
409
- assertEquals(false, boolOr(null, false))
410
- }
411
-
412
- @Test fun informationCtaAndCloseDispatchAndStates() {
413
- val json = """{"type":"Information","props":{"CTA":"c"},"actions":[{"name":"onPressCTA","type":"setState","params":{"cta":true}},{"name":"onPressClose","type":"setState","params":{"shown":false}}]}"""
414
- fire(json, "onPressCTA"); fire(json, "onPressClose")
415
- assertEquals(true, state["cta"]); assertEquals(false, state["shown"])
416
- assertEquals(InformationState.WARNING, informationStateOf("warning"))
417
- assertEquals(InformationState.ERROR, informationStateOf("error"))
418
- assertEquals(InformationState.DEFAULT, informationStateOf(null))
419
- }
420
-
421
- @Test fun inputSizeKeyboardAndPhoneSize() {
422
- assertEquals(InputSize.LARGE, inputSizeOf("large"))
423
- assertEquals(InputSize.SMALL, inputSizeOf(null))
424
- assertEquals(InputPhoneNumberSize.LARGE, phoneSizeOf("large"))
425
- assertEquals(KeyboardType.Number, keyboardTypeOf("number-pad"))
426
- assertEquals(KeyboardType.Email, keyboardTypeOf("email-address"))
427
- assertEquals(KeyboardType.Text, keyboardTypeOf(null))
428
- }
429
-
430
- @Test fun stepsMapItemsAndPassStepAndIndexToOnPress() {
431
- val items = stepItems(node("""{"s":[{"title":"A","description":"d","time":"t"},{"title":"B","error":true}]}""")["s"])
432
- assertEquals(listOf(StepItem("A", "d", false, "t"), StepItem("B", null, true, null)), items)
433
- fire("""{"type":"Steps","props":{"steps":[]},"actions":[{"name":"onPress","args":["step","index"],"type":"setState","params":{"title":"{step.title}","i":"{index}"}}]}""",
434
- "onPress", stepArg(items[0]), 0L)
435
- assertEquals("A", state["title"]); assertEquals(0L, state["i"])
436
- assertEquals(StepsSize.SMALL, stepsSizeOf("small")); assertEquals(StepsSize.LARGE, stepsSizeOf(null))
437
- assertEquals(StepsAlign.STRETCH, stepsAlignOf("stretch")); assertEquals(StepsAlign.CENTER, stepsAlignOf(null))
438
- }
439
-
440
- @Test fun progressInfoMapsItemsSizeAndAlign() {
441
- val items = progressItems(node("""{"s":[{"title":"A","description":"d"},{"title":"B"}]}""")["s"])
442
- assertEquals(listOf("A", "B"), items.map { it.title })
443
- assertEquals(listOf<String?>("d", null), items.map { it.description })
444
- assertEquals(ProgressInfoSize.Small, progressSizeOf("small"))
445
- assertEquals(ProgressInfoAlign.Right, progressAlignOf("right"))
446
- assertEquals(ProgressInfoAlign.Center, progressAlignOf(null))
447
- }
448
-
449
- @Test fun suggestActionDispatchesButtonAndClose() {
450
- val json = """{"type":"SuggestAction","props":{"message":"m","buttonTitle":"b"},"actions":[{"name":"onPressButton","type":"setState","params":{"b":true}},{"name":"onClose","type":"setState","params":{"c":true}}]}"""
451
- fire(json, "onPressButton"); fire(json, "onClose")
452
- assertEquals(true, state["b"]); assertEquals(true, state["c"])
453
- }
454
-
455
- // ---- KB form: the callback is itself a prop ----------------------------------------------------------------------
456
- @Test fun uploaderPropCallbacksReceiveImageAndIndex() {
457
- val json = """{"type":"Uploader","props":{"images":[],"onAdd":{"type":"setState","params":{"added":true}},
458
- "onCancel":{"args":["image","index"],"type":"setState","params":{"gone":"{image.uri}","at":"{index}"}}}}"""
459
- fire(json, "onAdd"); fire(json, "onCancel", imageArg(UploadImage("u1", false)), 2L)
460
- assertEquals(true, state["added"]); assertEquals("u1", state["gone"]); assertEquals(2L, state["at"])
461
- assertEquals(listOf(UploadImage("a", false), UploadImage(null, true)),
462
- uploadImages(node("""{"i":[{"uri":"a"},{"loading":true}]}""")["i"]))
463
- }
464
-
465
- @Test fun swipeOpenCallbacksAreReadFromProps() {
466
- val json = """{"type":"Swipe","props":{"height":64,"onSwipeableRightOpen":{"type":"setState","params":{"pending":"id1"}}}}"""
467
- fire(json, "onSwipeableRightOpen")
468
- assertEquals("id1", state["pending"])
469
- assertTrue(actionsFor(node(json), "onSwipeableLeftOpen").isEmpty())
470
- }
471
-
472
- @Test fun popupNotifyReadsButtonActionsRawAndMapsDirection() {
473
- assertEquals(PopupActionDirection.AUTO, popupDirectionOf("auto"))
474
- assertEquals(PopupActionDirection.COLUMN, popupDirectionOf("column"))
475
- assertEquals(PopupActionDirection.ROW, popupDirectionOf(null))
476
- // the callback-shaped prop is read raw by actionsFor, so its args exist when it runs
477
- val n = node("""{"type":"PopupNotify","props":{"title":"t","onIconClose":{"type":"setState","params":{"closed":true}}}}""")
478
- runner.run(actionsFor(n, "onIconClose"), "onIconClose", scope, emptyList())
479
- assertEquals(true, state["closed"])
480
- }
481
-
482
- @Test fun popupPromotionDispatchesActionClickAndClose() {
483
- val json = """{"type":"PopupPromotion","props":{"image":"u"},"actions":[{"name":"onActionClick","type":"setState","params":{"go":true}},{"name":"onIconClose","type":"setState","params":{"seen":true}}]}"""
484
- fire(json, "onActionClick"); fire(json, "onIconClose")
485
- assertEquals(true, state["go"]); assertEquals(true, state["seen"])
486
- }
487
-
488
- @Test fun actionNumberKeepsWholeValuesAsLong() {
489
- assertEquals(5L, actionNumber(5f))
490
- assertEquals(2.5, actionNumber(2.5f))
491
- }
492
-
493
- // ---- kit-only params exposed (absent prop = kit default) -----------------------------------------------------------
494
- @Test fun inputFontWeightFollowsTheComponentDefault() {
495
- assertEquals(InputFontWeight.BOLD, inputFontWeightOf("bold", InputFontWeight.REGULAR))
496
- assertEquals(InputFontWeight.REGULAR, inputFontWeightOf("regular", InputFontWeight.BOLD))
497
- // absent / unknown -> the kit default of that component (Input: REGULAR, InputMoney: BOLD)
498
- assertEquals(InputFontWeight.REGULAR, inputFontWeightOf(null, InputFontWeight.REGULAR))
499
- assertEquals(InputFontWeight.BOLD, inputFontWeightOf("heavy", InputFontWeight.BOLD))
500
- }
501
-
502
- @Test fun inputColorsFallBackToTheThemeColour() {
503
- val theme = Color(0xFF123456)
504
- assertEquals(theme, colorOr(null, theme))
505
- assertEquals(theme, colorOr("not-a-colour", theme))
506
- assertEquals(Color(0xFFFF0000), colorOr("#FF0000", theme))
507
- }
508
-
509
- @Test fun keyboardTypeKeepsTheKitDefaultPerComponent() {
510
- // InputMoney defaults to Number, Input / InputTextArea to Text
511
- assertEquals(KeyboardType.Number, keyboardTypeOr(null, KeyboardType.Number))
512
- assertEquals(KeyboardType.Number, keyboardTypeOr("bogus", KeyboardType.Number))
513
- assertEquals(KeyboardType.Text, keyboardTypeOf(null))
514
- assertEquals(KeyboardType.Email, keyboardTypeOr("email", KeyboardType.Number))
515
- assertEquals(KeyboardType.NumberPassword, keyboardTypeOr("number_password", KeyboardType.Text))
516
- assertEquals(KeyboardType.Phone, keyboardTypeOf("phone-pad"))
517
- }
518
-
519
- @Test fun avatarIconSupportDefaultsToTheKitUrl() {
520
- assertEquals(AVATAR_ICON_SUPPORT_DEFAULT, textOr(emptyMap(), "iconSupport", AVATAR_ICON_SUPPORT_DEFAULT))
521
- assertEquals("u", textOr(mapOf("iconSupport" to "u"), "iconSupport", AVATAR_ICON_SUPPORT_DEFAULT))
522
- }
523
-
524
- @Test fun dropDownAndTextAreaIconDefaults() {
525
- assertEquals("arrow_chevron_down_small", textOr(emptyMap(), "icon", "arrow_chevron_down_small"))
526
- assertEquals("x", textOr(mapOf("icon" to "x"), "icon", "arrow_chevron_down_small"))
527
- assertEquals(InputSize.SMALL, inputSizeOf(null)); assertEquals(InputSize.LARGE, inputSizeOf("large"))
528
- val json = """{"type":"InputTextArea","props":{},"actions":[{"name":"onRightIconPressed","type":"setState","params":{"tap":true}}]}"""
529
- fire(json, "onRightIconPressed")
530
- assertEquals(true, state["tap"])
531
- }
532
-
533
- @Test fun phoneNumberIconColorDefaultsToTheTheme() {
534
- val theme = Color(0xFF00FF00)
535
- assertEquals(theme, colorOr(null, theme)); assertEquals(Color.White, colorOr("white", theme))
536
- }
537
-
538
- @Test fun trustBannerCallbacksAreOptionalAndPassTheirData() {
539
- val json = """{"type":"TrustBanner","props":{},"actions":[{"name":"onPress","args":["data"],"type":"setState","params":{"link":"{data.url_config}"}},
540
- {"name":"trackEvent","args":["name","data"],"type":"setState","params":{"ev":"{name}"}}]}"""
541
- fire(json, "onPress", trustArg(mapOf("url_config" to "u1")))
542
- fire(json, "trackEvent", "service_component_clicked", trustArg(mapOf("screen_name" to "s")))
543
- assertEquals("u1", state["link"]); assertEquals("service_component_clicked", state["ev"])
544
- assertTrue(actionsFor(node("""{"type":"TrustBanner","props":{}}"""), "onPress").isEmpty())
545
- }
546
-
547
- // ---- already-mapped props now follow the kit default when absent --------------------------------------------------
548
- @Test fun absentBooleanPropsFollowTheKitDefault() {
549
- assertEquals(false, boolOr(null, false)) // Divider.useMargin, SuggestAction.visible
550
- assertEquals(true, boolOr(null, true)) // PopupNotify.isShowCloseIcon, Information.showIcon / showIconClose
551
- assertEquals(true, boolOr(true, false)); assertEquals(false, boolOr(false, true))
552
- }
553
-
554
- @Test fun informationHandlersExistOnlyWhenDeclared() {
555
- assertTrue(actionsFor(node("""{"type":"Information","props":{}}"""), "onPressClose").isEmpty())
556
- assertTrue(actionsFor(node("""{"type":"Information","props":{},"actions":[{"name":"onPressClose"}]}"""), "onPressClose").isNotEmpty())
557
- }
558
- }
559
- // AI-GENERATED END: kit node tests