@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,647 +0,0 @@
1
- // File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt
2
- // Created At: 2026-10-27 15:50: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 org.junit.Assert.assertEquals
11
- import org.junit.Assert.assertFalse
12
- import org.junit.Assert.assertNull
13
- import org.junit.Assert.assertTrue
14
- import org.junit.Test
15
- import java.lang.reflect.Proxy
16
- import vn.momo.kits.const.defaultTheme
17
- import vn.momo.maxapi.IMaxApi
18
-
19
- // AI-GENERATED START: unit tests for repeat expansion, the action runner
20
- class SduiActionsTest {
21
- private val features = mutableListOf<Pair<String, Map<String, Any>>>()
22
- private val featureApi: IMaxApi = Proxy.newProxyInstance(IMaxApi::class.java.classLoader, arrayOf(IMaxApi::class.java)) { _, m, args ->
23
- @Suppress("UNCHECKED_CAST")
24
- if (m.name == "startFeatureCode") {
25
- val a = (args!![0] as? Array<*>)?.toList() ?: args.toList()
26
- features += (a[0] as String) to (a[1] as Map<String, Any>)
27
- }
28
- when (m.returnType) { Boolean::class.javaPrimitiveType -> false; Int::class.javaPrimitiveType -> 0; Long::class.javaPrimitiveType -> 0L; else -> null }
29
- } as IMaxApi
30
- private val featureMaxApi = SduiMaxApi({ featureApi })
31
-
32
- private val state = mutableStateMapOf<String, Any?>("onboarded" to false, "page" to 0L)
33
- private val sink = object : TrackSink {
34
- override val id = "rec"
35
- val records = mutableListOf<TrackRecord>()
36
- override fun write(record: TrackRecord) { records += record }
37
- }
38
- private val session = Tracker(listOf(sink), "sess").begin(SessionCtx("sdui:view:t"))
39
- private val runner = SduiActionRunner(state, { defaultTheme }, { session }, featureMaxApi)
40
- private val scope = SduiScope(emptyMap(), state)
41
- private fun run(action: Map<String, Any?>, sc: SduiScope = scope, args: List<Any?> = emptyList()) = runner.runOne(action, sc, args)
42
-
43
- // ---- repeat expansion ---------------------------------------------------------------------------------------
44
- @Test fun repeatExpandsPerItemWithAliasAndIndex() {
45
- val sc = SduiScope(mapOf("categories" to listOf(mapOf("id" to "a"), mapOf("id" to "b"), mapOf("id" to "c"))), state)
46
- val node = mapOf("type" to "Item", "repeat" to mapOf("source" to "categories", "as" to "c", "index" to "i"))
47
- val out = expand(listOf(node), sc, defaultTheme, null)
48
- assertEquals(3, out.size)
49
- assertEquals(listOf("a", "b", "c"), out.map { evalExpr("c.id", it.scope) })
50
- assertEquals(listOf(0L, 1L, 2L), out.map { evalExpr("i", it.scope) })
51
- }
52
-
53
- @Test fun repeatAcceptsBindingSourcesAndFromAndDropsInvisible() {
54
- val sc = SduiScope(mapOf("xs" to listOf(1L, 2L, 3L, 4L)), state)
55
- val filtered = mapOf("type" to "Text", "repeat" to mapOf("source" to "{xs.filter(x => x > 2)}", "as" to "x"))
56
- assertEquals(2, expand(listOf(filtered), sc, defaultTheme, null).size)
57
- val from = mapOf("type" to "Text", "repeat" to mapOf("from" to "xs", "as" to "x"), "visible" to "{x != 2}")
58
- assertEquals(3, expand(listOf(from), sc, defaultTheme, null).size)
59
- val unknown = mapOf("type" to "Text", "repeat" to mapOf("source" to "nope", "as" to "x"))
60
- assertEquals(0, expand(listOf(unknown), sc, defaultTheme, null).size)
61
- val hidden = mapOf("type" to "View", "visible" to "{state.onboarded}")
62
- assertEquals(0, expand(listOf(hidden), sc, defaultTheme, null).size)
63
- }
64
-
65
- // ---- typed form {"type": "startFeatureCode"} -------------------------------------------------------------------
66
- @Test fun typedStartFeatureCodeForwardsFeatureCodeAndRestParamsWithoutNulls() {
67
- val sc = scope.with("p", mapOf("id" to "pvi"))
68
- run(mapOf("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf(
69
- "featureCode" to "ins_marketplace", "screenName" to "detail", "partnerId" to "{p.id}", "gone" to null)), sc)
70
- assertEquals(listOf("ins_marketplace" to mapOf<String, Any>("screenName" to "detail", "partnerId" to "pvi")), features)
71
- }
72
-
73
- @Test fun typedStartFeatureCodeRejectsInvalidFeatureCode() {
74
- run(mapOf("type" to "startFeatureCode", "params" to mapOf("featureCode" to "momo://x")))
75
- run(mapOf("type" to "startFeatureCode", "params" to mapOf("featureCode" to "a b")))
76
- run(mapOf("type" to "startFeatureCode", "params" to mapOf("x" to 1L)))
77
- assertTrue(features.isEmpty())
78
- }
79
-
80
- // ---- typed form {"type": "trackEvent"} -------------------------------------------------------------------------
81
- private val tracked = mutableListOf<Pair<String, Map<String, Any>>>()
82
- private val warnings = mutableListOf<String>()
83
- private val trackApi: IMaxApi = Proxy.newProxyInstance(IMaxApi::class.java.classLoader, arrayOf(IMaxApi::class.java)) { _, m, args ->
84
- @Suppress("UNCHECKED_CAST")
85
- if (m.name == "startFeatureCode") {
86
- val a = (args!![0] as? Array<*>)?.toList() ?: args.toList()
87
- features += (a[0] as String) to (a[1] as Map<String, Any>)
88
- }
89
- if (m.name == "track") tracked += (args!![0] as String) to (args[1] as Map<String, Any>)
90
- when (m.returnType) { Boolean::class.javaPrimitiveType -> false; Int::class.javaPrimitiveType -> 0; Long::class.javaPrimitiveType -> 0L; else -> null }
91
- } as IMaxApi
92
- private val trackLog = capturingLog(warnings)
93
- private val trackRunner = SduiActionRunner(state, { defaultTheme }, { session }, SduiMaxApi({ trackApi }), trackLog)
94
- private fun runTrack(action: Map<String, Any?>, sc: SduiScope = scope) = trackRunner.runOne(action, sc, emptyList())
95
- private fun trackAction(params: Map<String, Any?>, extra: Map<String, Any?> = emptyMap()) =
96
- mapOf("name" to "onPress", "type" to "trackEvent", "params" to params) + extra
97
-
98
- @Test fun typedTrackEventCallsTrackWithCleanedParams() {
99
- val sc = scope.with("total", 1500L)
100
- runTrack(trackAction(mapOf(
101
- "eventName" to "service_component_clicked", "screen_name" to "paylater_bills", "amount" to "{total}", "ok" to true,
102
- "gone" to null, "map" to mapOf("a" to 1L), "list" to listOf(1L), "bad-key" to "x", "1bad" to "y")), sc)
103
- assertEquals(listOf("service_component_clicked" to mapOf<String, Any>(
104
- "screen_name" to "paylater_bills", "amount" to 1500L, "ok" to true)), tracked)
105
- assertTrue(warnings.any { "map" in it }); assertTrue(warnings.any { "list" in it }); assertTrue(warnings.any { "bad-key" in it })
106
- assertFalse(warnings.any { "gone" in it })
107
- }
108
-
109
- @Test fun typedTrackEventRejectsMissingOrInvalidEventName() {
110
- runTrack(trackAction(mapOf("x" to 1L)))
111
- runTrack(trackAction(mapOf("eventName" to "1bad")))
112
- runTrack(trackAction(mapOf("eventName" to "has-dash")))
113
- runTrack(trackAction(mapOf("eventName" to "a".repeat(65))))
114
- runTrack(trackAction(mapOf("eventName" to 5L)))
115
- assertTrue(tracked.isEmpty())
116
- assertEquals(1, warnings.count { it.endsWith("trackEvent: invalid eventName") }) // same message: written once
117
- assertTrue(sink.records.none { it.event.fields["verb"] == "track" })
118
- }
119
-
120
- @Test fun trackEventDropsNonFiniteNumbers() {
121
- runTrack(trackAction(mapOf("eventName" to "tapped", "nan" to Double.NaN, "inf" to Double.POSITIVE_INFINITY, "n" to 2.5)))
122
- assertEquals(listOf("tapped" to mapOf<String, Any>("n" to 2.5)), tracked)
123
- assertEquals(2, warnings.count { "not a finite number" in it })
124
- }
125
-
126
- @Test fun trackEventWithoutApiIsSilentAndDoesNotThrow() {
127
- val lines = ArrayList<String>()
128
- val noApi = SduiActionRunner(state, { defaultTheme }, { session }, SduiMaxApi({ null }), capturingLog(lines))
129
- noApi.runOne(trackAction(mapOf("eventName" to "tapped")), scope, emptyList())
130
- assertTrue(tracked.isEmpty())
131
- assertTrue(lines.isEmpty())
132
- }
133
-
134
- @Test fun trackEventRejectsTheReservedRendererEventName() {
135
- runTrack(trackAction(mapOf("eventName" to "ops_info_checked", "step" to "render_done")))
136
- runTrack(trackAction(mapOf("eventName" to "OPS_Info_Checked")))
137
- assertTrue(tracked.isEmpty())
138
- assertEquals(1, warnings.count { it.endsWith("trackEvent: reserved eventName") })
139
- assertTrue(sink.records.none { it.event.fields["verb"] == "track" })
140
- }
141
-
142
- @Test fun invalidFeatureCodeWarningsDoNotCarryTheValue() {
143
- runTrack(mapOf("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "bad code!SECRET")))
144
- runTrack(trackAction(mapOf("eventName" to "bad-name!SECRET4")))
145
- assertEquals(2, warnings.size)
146
- assertTrue(warnings.none { "SECRET" in it })
147
- assertTrue(warnings.any { it.endsWith("startFeatureCode: invalid featureCode") })
148
- }
149
-
150
- @Test fun paramKeysThatCameFromDataAreNotLogged() {
151
- val sc = scope.with("p", mapOf("eventName" to "tapped", "SECRET-key" to "x", "SECRETmap" to mapOf("a" to 1L)))
152
- runTrack(mapOf("name" to "onPress", "type" to "trackEvent", "params" to "{p}"), sc)
153
- assertEquals(listOf("tapped" to emptyMap<String, Any>()), tracked)
154
- assertEquals(2, warnings.size)
155
- assertTrue(warnings.none { "SECRET" in it })
156
- assertTrue(warnings.all { "dropped param (from binding)" in it })
157
- }
158
-
159
- @Test fun trackEventThenStartFeatureCodeRunInSpecOrder() {
160
- val actions = listOf(
161
- trackAction(mapOf("eventName" to "tapped")),
162
- mapOf("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "ins_marketplace")))
163
- trackRunner.run(actions, "onPress", scope, emptyList())
164
- assertEquals(listOf("tapped"), tracked.map { it.first })
165
- assertEquals(listOf("ins_marketplace"), features.map { it.first })
166
- }
167
-
168
- @Test fun trackEventWithFalseWhenTracksNothing() {
169
- runTrack(trackAction(mapOf("eventName" to "tapped"), mapOf("when" to "{state.page > 5}")))
170
- assertTrue(tracked.isEmpty())
171
- }
172
-
173
- @Test fun unknownTypeIsSkippedAndReported() {
174
- run(mapOf("type" to "teleport", "params" to mapOf("page" to 9L, "featureCode" to "ok")), scope)
175
- assertTrue(features.isEmpty())
176
- assertEquals(0L, state["page"])
177
- val err = sink.records.single { it.event.step == "sdui_node_error" }
178
- assertEquals("invalid_action", err.event.fields["code"])
179
- assertEquals("unknown_type", err.event.fields["reason"])
180
- }
181
-
182
- // ---- every invalid-action warning has its sdui_node_error twin ----------------------------------------------------
183
- private fun nodeErrors() = sink.records.filter { it.event.step == "sdui_node_error" }.map { it.event.fields }
184
-
185
- @Test fun eachRunnerReasonReportsInvalidActionWithNodeContext() {
186
- val undeclared = SduiActionRunner(setState, { defaultTheme }, { session }, featureMaxApi, capturingLog(warnings), declaredState = setOf("a"))
187
- fun case(reason: String, go: (Int) -> Unit) {
188
- val before = nodeErrors().size
189
- go(before)
190
- val got = nodeErrors().drop(before)
191
- assertEquals(reason, 1, got.size)
192
- assertEquals(reason, "invalid_action", got[0]["code"])
193
- assertEquals(reason, got[0]["reason"])
194
- assertEquals("body.children.$reason", got[0]["nodePath"])
195
- assertEquals("n_$reason", got[0]["nodeId"])
196
- assertEquals("Button", got[0]["nodeType"])
197
- }
198
- fun at(r: String, a: Map<String, Any?>, runner: SduiActionRunner = trackRunner) = runner.runOne(a, scope, emptyList(), "body.children.$r", "n_$r", "Button")
199
- case("missing_type") { at("missing_type", mapOf("name" to "onPress")) }
200
- case("unknown_type") { at("unknown_type", mapOf("type" to "teleport")) }
201
- case("invalid_feature_code") { at("invalid_feature_code", mapOf("type" to "startFeatureCode", "params" to mapOf("featureCode" to "a b"))) }
202
- case("invalid_event_name") { at("invalid_event_name", trackAction(mapOf("eventName" to "1bad"))) }
203
- case("reserved_event_name") { at("reserved_event_name", trackAction(mapOf("eventName" to "ops_info_checked"))) }
204
- case("invalid_param") { at("invalid_param", trackAction(mapOf("eventName" to "ok_name", "bad-key" to "x"))) }
205
- case("state_not_declared") { at("state_not_declared", mapOf("type" to "setState", "params" to mapOf("zzz" to 1L)), undeclared) }
206
- }
207
-
208
- // ---- failures deep in value resolution are attributed to the node + path passed in (no ambient frame) ------------------
209
- private fun attributed(data: Map<String, Any?> = emptyMap()): Pair<SduiScope, SduiCtx> {
210
- val sc = SduiScope(data, state, nodeErrors = NodeErrorSink { session })
211
- return sc to SduiCtx(defaultTheme, state, { _, _, _, _, _, _, _ -> }, session = session)
212
- }
213
-
214
- @Test fun brokenExpressionInPropsReportsExprFailedOnThatNode() {
215
- val (sc, ctx) = attributed()
216
- val node = mapOf("type" to "Text", "id" to "t1", "props" to mapOf("children" to "{((}", "other" to "{[[}"))
217
- propsOf(node, sc, ctx, "body.children.3")
218
- val e = nodeErrors().single()
219
- assertEquals(mapOf("step" to "sdui_node_error", "code" to "expr_failed", "reason" to "expr_failed", "nodePath" to "body.children.3", "nodeId" to "t1", "nodeType" to "Text"), e)
220
- }
221
-
222
- @Test fun unknownTokenInStylesReportsUnknownTokenOnThatNode() {
223
- val (sc, ctx) = attributed()
224
- val node = mapOf("type" to "View", "styles" to mapOf("padding" to "Spacing.ZZZ"))
225
- styOf(node, sc, ctx, "body")
226
- val e = nodeErrors().single()
227
- assertEquals("unknown_token", e["code"]); assertEquals("unknown_token", e["reason"]); assertEquals("body", e["nodePath"]); assertEquals("View", e["nodeType"])
228
- assertFalse(e.containsKey("nodeId"))
229
- }
230
-
231
- @Test fun aQuietProbeReportsNothing() {
232
- val (sc, ctx) = attributed()
233
- val child = mapOf("type" to "Text", "styles" to mapOf("color" to "Colors.nope", "flex" to "{((}"))
234
- styOf(child, sc, ctx, null) // a parent probing a child's styles for layout
235
- propsOf(mapOf("props" to mapOf("x" to "{((}")), sc, ctx, null)
236
- assertTrue(nodeErrors().isEmpty())
237
- }
238
-
239
- @Test fun aQuietProbeInsideAReportingStepDoesNotLeakIntoIt() {
240
- val (sc, ctx) = attributed()
241
- val parent = mapOf("type" to "View")
242
- sc.nodeErrors.forNode(parent, "body") { sc.nodeErrors.quiet { evalExpr("{((}", sc) } }
243
- assertTrue(nodeErrors().isEmpty())
244
- }
245
-
246
- @Test fun brokenVisibleAndRepeatAreAttributedToTheChildPathUnderTheGivenBase() {
247
- val (sc, _) = attributed()
248
- val kids = listOf(mapOf("type" to "Text"), mapOf("type" to "Text", "id" to "v", "visible" to "{((}"), mapOf("type" to "Item", "repeat" to mapOf("source" to "{[[}")))
249
- expand(kids, sc, defaultTheme, "body.children.4")
250
- val got = nodeErrors()
251
- assertEquals(listOf("body.children.4.children.1", "body.children.4.children.2"), got.map { it["nodePath"] })
252
- assertEquals(listOf("v", null), got.map { it["nodeId"] }); assertEquals(listOf("Text", "Item"), got.map { it["nodeType"] })
253
- assertTrue(got.all { it["code"] == "expr_failed" })
254
- }
255
-
256
- @Test fun expandWithoutABasePathIsQuiet() {
257
- val (sc, _) = attributed()
258
- expand(listOf(mapOf("type" to "Text", "visible" to "{((}")), sc, defaultTheme, null)
259
- assertTrue(nodeErrors().isEmpty())
260
- }
261
-
262
- @Test fun theSameNodeEvaluatedTwiceReportsOnce() {
263
- val (sc, ctx) = attributed()
264
- val node = mapOf("type" to "Text", "props" to mapOf("children" to "{((}"))
265
- repeat(2) { propsOf(node, sc, ctx, "body.children.0") } // recomposition re-runs the node's composable
266
- repeat(2) { expand(listOf(mapOf("type" to "Text", "visible" to "{((}")), sc, defaultTheme, "body.children.5") }
267
- assertEquals(listOf("body.children.0", "body.children.5.children.0"), nodeErrors().map { it["nodePath"] })
268
- }
269
-
270
- @Test fun aBrokenDataExpressionIsReportedOnEveryNodeThatUsesIt() {
271
- val (sc, ctx) = attributed(mapOf("bad" to "{((}"))
272
- val a = mapOf("type" to "Text", "props" to mapOf("children" to "{bad}")); val b = mapOf("type" to "Title", "props" to mapOf("children" to "{bad}"))
273
- propsOf(a, sc, ctx, "body.children.0")
274
- propsOf(b, sc, ctx, "body.children.1") // the second reader must report too
275
- assertEquals(listOf("body.children.0", "body.children.1"), nodeErrors().map { it["nodePath"] })
276
- }
277
-
278
- @Test fun aBrokenDataExpressionReadThroughAnotherKeyOrInARepeatIsReportedOnEachNode() {
279
- val (sc, ctx) = attributed(mapOf("bad" to "{item.(}", "label" to "{bad ?? 'x'}", "rows" to listOf(1L, 2L)))
280
- propsOf(mapOf("type" to "Text", "props" to mapOf("children" to "{label}")), sc, ctx, "body.children.0")
281
- val kids = listOf(mapOf("type" to "Text", "repeat" to mapOf("source" to "rows"), "props" to mapOf("children" to "{data.bad}")))
282
- expand(kids, sc, defaultTheme, "body.children.1").forEachIndexed { i, x -> propsOf(x.node, x.scope, ctx, "body.children.1.children.$i") }
283
- assertEquals(listOf("body.children.0", "body.children.1.children.0", "body.children.1.children.1"), nodeErrors().map { it["nodePath"] })
284
- assertTrue(nodeErrors().all { it["code"] == "expr_failed" })
285
- }
286
-
287
- @Test fun resolutionOutsideAnyNodeReportsNothing() {
288
- val (sc, ctx) = attributed()
289
- resolveValue(mapOf("x" to "{((}", "y" to "Spacing.ZZZ"), sc, ctx.theme)
290
- assertTrue(nodeErrors().isEmpty())
291
- }
292
-
293
- @Test fun validActionsReportNoNodeError() {
294
- runTrack(trackAction(mapOf("eventName" to "tapped", "n" to 1L)))
295
- run(mapOf("type" to "setState", "params" to mapOf("page" to 1L)))
296
- assertTrue(nodeErrors().isEmpty())
297
- }
298
-
299
- // ---- when / args / code / missing type ------------------------------------------------------------------------
300
- private val typedState = mutableStateMapOf<String, Any?>("page" to 0L, "onboarded" to false)
301
- private val typedRunner = SduiActionRunner(typedState, { defaultTheme }, { session }, featureMaxApi, capturingLog(warnings))
302
- private val typedScope = SduiScope(emptyMap(), typedState)
303
- private fun runTyped(action: Map<String, Any?>, args: List<Any?> = emptyList()) = typedRunner.runOne(action, typedScope, args)
304
-
305
- @Test fun setStateWhenAndArgs() {
306
- runTyped(mapOf("type" to "setState", "params" to mapOf("page" to "{state.page + 1}")))
307
- assertEquals(1L, typedState["page"])
308
- runTyped(mapOf("type" to "setState", "params" to mapOf("onboarded" to true), "when" to "{state.page > 5}"))
309
- assertEquals(false, typedState["onboarded"]) // `when` false: nothing happens
310
- runTyped(mapOf("type" to "setState", "args" to listOf("i"), "params" to mapOf("page" to "{i}")), listOf(2L))
311
- assertEquals(2L, typedState["page"])
312
- runTyped(mapOf("type" to "setState", "params" to mapOf("page" to "{args[0]}")), listOf(1L))
313
- assertEquals(1L, typedState["page"])
314
- }
315
-
316
- @Test fun onPressActionsOfTheSameNameRunInSpecOrderWithWhen() {
317
- val actions = listOf(
318
- mapOf("name" to "onPress", "when" to "{!g.featureCode}", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "ins_marketplace")),
319
- mapOf("name" to "onPress", "when" to "{!!g.featureCode}", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "{g.featureCode}")),
320
- mapOf("name" to "other", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "never")),
321
- )
322
- runner.run(actions, "onPress", scope.with("g", mapOf("featureCode" to "guide_x")), emptyList())
323
- assertEquals(listOf("guide_x"), features.map { it.first })
324
- }
325
-
326
- @Test fun actionWithoutTypeRunsNothingAndWarns() {
327
- warnings.clear()
328
- val legacy = listOf(
329
- mapOf("name" to "a", "set" to mapOf("page" to 9L)),
330
- mapOf("name" to "a", "navigate" to "push", "params" to mapOf("featureCode" to "ok")),
331
- mapOf("name" to "a", "tab" to "t"),
332
- mapOf("name" to "a", "params" to mapOf("page" to 9L)),
333
- )
334
- legacy.forEachIndexed { i, a -> typedRunner.runOne(a, typedScope, emptyList(), path = "body.actions[$i]") }
335
- assertEquals(0L, typedState["page"])
336
- assertTrue(features.isEmpty())
337
- assertEquals(4, warnings.size)
338
- assertEquals((0..3).map { "[SDUI] t: body.actions[$it]: action skipped: missing type" }, warnings)
339
- }
340
-
341
- @Test fun missingTypeIsReportedEvenWhenWhenIsFalse() {
342
- val before = nodeErrors().size
343
- runTyped(mapOf("name" to "a", "when" to false, "params" to mapOf("page" to 9L)))
344
- val got = nodeErrors().drop(before)
345
- assertEquals(1, got.size)
346
- assertEquals("invalid_action", got[0]["code"])
347
- assertEquals("missing_type", got[0]["reason"])
348
- assertEquals(0L, typedState["page"])
349
- }
350
-
351
- @Test fun actionCarryingCodeIsNeverExecuted() {
352
- run(mapOf("code" to "alert(1)", "type" to "setState", "params" to mapOf("page" to 99L)))
353
- assertEquals(0L, state["page"])
354
- assertFalse(state.containsKey("x"))
355
- }
356
-
357
- @Test fun anActionNeverThrows() {
358
- run(mapOf("type" to "setState", "params" to mapOf("page" to "{((}")))
359
- run(mapOf("type" to 5L, "params" to "nope"))
360
- run(emptyMap())
361
- }
362
-
363
- // ---- typed form {"type": "set"} --------------------------------------------------------------------------------
364
- private val setState = mutableStateMapOf<String, Any?>("expanded" to false, "query" to "", "count" to 0L)
365
- private val setLog = capturingLog(warnings)
366
- private val setRunner = SduiActionRunner(setState, { defaultTheme }, { session }, featureMaxApi, setLog, declaredState = setState.keys.toSet())
367
- private val setScope = SduiScope(emptyMap(), setState)
368
- private fun runSet(action: Map<String, Any?>, args: List<Any?> = emptyList()) = setRunner.runOne(action, setScope, args)
369
- private fun setAction(params: Map<String, Any?>, extra: Map<String, Any?> = emptyMap()) =
370
- mapOf<String, Any?>("name" to "onPress", "type" to "setState", "params" to params) + extra
371
-
372
- @Test fun typedSetStateWritesDeclaredKeys() {
373
- runSet(setAction(mapOf("expanded" to true, "count" to 5L)))
374
- assertEquals(true, setState["expanded"]); assertEquals(5L, setState["count"])
375
- }
376
-
377
- @Test fun typedSetStateSkipsUndeclaredKeyWithWarningButWritesTheRest() {
378
- warnings.clear()
379
- runSet(setAction(mapOf("ghost" to 1L, "count" to 2L)))
380
- assertEquals(2L, setState["count"])
381
- assertFalse(setState.containsKey("ghost"))
382
- assertTrue(warnings.any { it.contains("setState: 'ghost' is not declared in state") })
383
- }
384
-
385
- @Test fun typedSetStateToggleTwiceReturnsToFalse() {
386
- val toggle = setAction(mapOf("expanded" to "{!expanded}"))
387
- runSet(toggle); assertEquals(true, setState["expanded"])
388
- runSet(toggle); assertEquals(false, setState["expanded"])
389
- }
390
-
391
- @Test fun typedSetStateWhenFalseWritesNothing() {
392
- val before = sink.records.size
393
- runSet(setAction(mapOf("count" to 9L), mapOf("when" to "{state.expanded}")))
394
- assertEquals(0L, setState["count"])
395
- assertEquals(before, sink.records.size)
396
- }
397
-
398
- @Test fun typedSetStateOnlyUndeclaredWritesNothingAndReportsStateNotDeclared() {
399
- val before = sink.records.size
400
- runSet(setAction(mapOf("ghost" to 1L)))
401
- assertEquals(before + 1, sink.records.size)
402
- assertEquals("state_not_declared", sink.records.last().event.fields["reason"])
403
- assertFalse(setState.containsKey("ghost"))
404
- }
405
-
406
- @Test fun typedSetStateThenStartFeatureCodeSeesNewValue() {
407
- val actions = listOf(
408
- setAction(mapOf("query" to "{v}"), mapOf("args" to listOf("v"))),
409
- mapOf("name" to "onPress", "type" to "startFeatureCode", "args" to listOf("v"), "params" to mapOf("featureCode" to "search", "q" to "{query}")),
410
- )
411
- setRunner.run(actions, "onPress", setScope, listOf("abc"))
412
- assertEquals(listOf("search" to mapOf<String, Any>("q" to "abc")), features)
413
- }
414
-
415
- @Test fun typedSetStateTakesArgsFromTheCallback() {
416
- runSet(setAction(mapOf("query" to "{v}"), mapOf("args" to listOf("v"))), listOf("hello"))
417
- assertEquals("hello", setState["query"])
418
- }
419
-
420
- // ---- action runner gaps: validation, params, when, args, setState, run(), SduiMaxApi ----------------------------
421
- private fun feature(code: Any?) = mapOf<String, Any?>("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf("featureCode" to code))
422
- private fun nodeErrorReasons() = nodeErrors().map { it["reason"] }
423
-
424
- @Test fun featureCodeAllowsDotSlashDashAfterFirstChar() {
425
- run(feature("a.b/c-d_1"))
426
- run(feature("_x"))
427
- run(feature("9a"))
428
- assertEquals(listOf("a.b/c-d_1", "_x", "9a"), features.map { it.first })
429
- }
430
-
431
- @Test fun featureCodeRejectsBadFirstCharEmptySpaceAndColon() {
432
- listOf(".a", "-a", "/a", "", " ", "a b", "a:b", " a").forEach { run(feature(it)) }
433
- assertTrue(features.isEmpty())
434
- assertEquals(listOf<Any?>("invalid_feature_code"), nodeErrorReasons()) // same path/code/reason: one event
435
- }
436
-
437
- @Test fun featureCodeRegexDirectly() {
438
- assertTrue(FEATURE_CODE_RE.matches("a.b/c-d_1"))
439
- listOf(".", "-", "/", "", " ", ":", "a b", "a:b", "a\n").forEach { assertFalse("'$it'", FEATURE_CODE_RE.matches(it)) }
440
- }
441
-
442
- @Test fun numericFeatureCodeIsRejectedAsInvalidFeatureCode() {
443
- run(feature(123L), args = emptyList())
444
- assertTrue(features.isEmpty())
445
- assertEquals(listOf<Any?>("invalid_feature_code"), nodeErrorReasons())
446
- }
447
-
448
- @Test fun eventNameOf64CharsIsAcceptedAnd65Rejected() {
449
- runTrack(trackAction(mapOf("eventName" to "a".repeat(64))))
450
- runTrack(trackAction(mapOf("eventName" to "a".repeat(65))))
451
- assertEquals(listOf("a".repeat(64)), tracked.map { it.first })
452
- assertEquals(listOf<Any?>("invalid_event_name"), nodeErrorReasons())
453
- }
454
-
455
- @Test fun eventNameRejectsLeadingDigitOrUnderscore() {
456
- runTrack(trackAction(mapOf("eventName" to "9tap")))
457
- runTrack(trackAction(mapOf("eventName" to "_tap")))
458
- runTrack(trackAction(mapOf("eventName" to "")))
459
- runTrack(trackAction(mapOf("eventName" to "tap_9")))
460
- assertEquals(listOf("tap_9"), tracked.map { it.first })
461
- }
462
-
463
- @Test fun reservedEventNameIsCaseInsensitive() {
464
- runTrack(trackAction(mapOf("eventName" to "OPS_INFO_CHECKED")), scope)
465
- runTrack(trackAction(mapOf("eventName" to "Ops_Info_Checked")), scope)
466
- assertTrue(tracked.isEmpty())
467
- assertEquals(listOf<Any?>("reserved_event_name"), nodeErrorReasons()) // same path/code/reason: one event
468
- }
469
-
470
- @Test fun trackEventKeepsTypedValuesAndDropsEventNameNullAndInvalidKeys() {
471
- runTrack(trackAction(mapOf(
472
- "eventName" to "typed", "l" to 5L, "i" to 6, "d" to 1.5, "b" to true, "s" to "x", "nul" to null,
473
- "1abc" to "v", "a-b" to "v", "_ok" to 1L)))
474
- val (name, p) = tracked.single()
475
- assertEquals("typed", name)
476
- assertEquals(mapOf<String, Any>("l" to 5L, "i" to 6, "d" to 1.5, "b" to true, "s" to "x", "_ok" to 1L), p)
477
- assertEquals(Long::class, p["l"]!!::class); assertEquals(Int::class, p["i"]!!::class); assertEquals(Double::class, p["d"]!!::class)
478
- assertFalse(p.containsKey("eventName"))
479
- assertFalse(warnings.any { "nul" in it })
480
- }
481
-
482
- @Test fun trackEventDropsMapListAndNonFiniteFloatAndDouble() {
483
- runTrack(trackAction(mapOf(
484
- "eventName" to "bad", "m" to mapOf("a" to 1L), "l" to listOf(1L),
485
- "fnan" to Float.NaN, "finf" to Float.POSITIVE_INFINITY, "dninf" to Double.NEGATIVE_INFINITY, "ok" to 1.5f)))
486
- assertEquals(listOf("bad" to mapOf<String, Any>("ok" to 1.5f)), tracked)
487
- assertEquals(5, warnings.size)
488
- }
489
-
490
- @Test fun severalBadParamsGiveOneNodeErrorButOneLogLineEach() {
491
- val r = SduiActionRunner(state, { defaultTheme }, { session }, SduiMaxApi({ trackApi }), trackLog)
492
- r.runOne(trackAction(mapOf("eventName" to "t", "1abc" to "x", "a-b" to "y", "m" to mapOf("a" to 1L), "n" to Double.NaN)), scope, emptyList(), "body.children.0", "n0", "Button")
493
- assertEquals(listOf<Any?>("invalid_param"), nodeErrorReasons())
494
- assertEquals(4, warnings.count { "dropped param" in it })
495
- assertEquals(listOf("t" to emptyMap<String, Any>()), tracked)
496
- }
497
-
498
- @Test fun startFeatureCodeForwardsMapAndListValuesUnchanged() {
499
- val m = mapOf("a" to 1L); val l = listOf(1L, "x")
500
- run(mapOf("type" to "startFeatureCode", "params" to mapOf("featureCode" to "fc", "m" to m, "l" to l, "gone" to null, "s" to "v")))
501
- assertEquals(listOf("fc" to mapOf<String, Any>("m" to m, "l" to l, "s" to "v")), features)
502
- }
503
-
504
- private fun whenRuns(w: Any?, sc: SduiScope = scope): Boolean {
505
- val s = mutableStateMapOf<String, Any?>("hit" to 0L)
506
- SduiActionRunner(s, { defaultTheme }, { session }).runOne(mapOf("type" to "setState", "when" to w, "params" to mapOf("hit" to 1L)), SduiScope(emptyMap(), s), emptyList())
507
- return s["hit"] == 1L
508
- }
509
-
510
- @Test fun whenLiteralBooleanControlsExecution() {
511
- assertTrue(whenRuns(true)); assertFalse(whenRuns(false))
512
- }
513
-
514
- @Test fun whenExpressionsResolvingToZeroEmptyOrNullSkip() {
515
- assertFalse(whenRuns("{0}")); assertFalse(whenRuns("{''}")); assertFalse(whenRuns("{state.missing}"))
516
- assertFalse(whenRuns("{0.0}")); assertFalse(whenRuns("{false}"))
517
- }
518
-
519
- @Test fun whenNonEmptyStringOrNonZeroNumberRuns() {
520
- assertTrue(whenRuns("{'x'}")); assertTrue(whenRuns("{1}")); assertTrue(whenRuns("{-1}")); assertTrue(whenRuns("{1.5}"))
521
- }
522
-
523
- @Test fun whenPlainStringWithoutBindingIsTruthyEvenIfItSaysFalse() {
524
- // NOTE: a literal (non-binding) string such as "false" or "0" is a non-empty string, so it counts as true.
525
- assertTrue(whenRuns("false")); assertTrue(whenRuns("0"))
526
- }
527
-
528
- @Test fun whenOnlyNullMeansNoCondition() {
529
- assertTrue(whenRuns(null))
530
- }
531
-
532
- @Test fun argsWithMoreNamesThanCallArgsBindNull() {
533
- setState.clear(); setState["w"] = "old"; setState["v"] = "old"
534
- val r = SduiActionRunner(setState, { defaultTheme }, { session })
535
- r.runOne(mapOf("type" to "setState", "args" to listOf("v", "w"), "params" to mapOf("v" to "{v}", "w" to "{w}")), setScope, listOf("one"))
536
- assertEquals("one", setState["v"]); assertTrue(setState.containsKey("w")); assertNull(setState["w"])
537
- }
538
-
539
- @Test fun nonStringArgsEntryIsIgnoredWithoutShiftingPositions() {
540
- val s = mutableStateMapOf<String, Any?>()
541
- val r = SduiActionRunner(s, { defaultTheme }, { session })
542
- r.runOne(mapOf("type" to "setState", "args" to listOf(1L, "b", null, "d"), "params" to mapOf("b" to "{b}", "d" to "{d}")), SduiScope(emptyMap(), s), listOf("A", "B", "C", "D"))
543
- assertEquals("B", s["b"]); assertEquals("D", s["d"])
544
- }
545
-
546
- @Test fun argsIndexExpressionReadsCallbackValues() {
547
- val s = mutableStateMapOf<String, Any?>()
548
- val r = SduiActionRunner(s, { defaultTheme }, { session })
549
- r.runOne(mapOf("type" to "setState", "params" to mapOf("a" to "{args[0]}", "b" to "{args[1]}", "c" to "{args[2]}", "n" to "{args.length}")), SduiScope(emptyMap(), s), listOf("x", 7L))
550
- assertEquals("x", s["a"]); assertEquals(7L, s["b"]); assertNull(s["c"]); assertEquals(2L, s["n"])
551
- }
552
-
553
- @Test fun argsDotIndexReadsCallbackValueToo() {
554
- val s = mutableStateMapOf<String, Any?>("a" to "old")
555
- val r = SduiActionRunner(s, { defaultTheme }, { session })
556
- r.runOne(mapOf("type" to "setState", "params" to mapOf("a" to "{args.0}")), SduiScope(emptyMap(), s), listOf("x"))
557
- assertEquals("x", s["a"])
558
- }
559
-
560
- @Test fun setStateSwapsTwoKeysUsingValuesFromBeforeAnyWrite() {
561
- val s = mutableStateMapOf<String, Any?>("a" to 1L, "b" to 2L)
562
- val r = SduiActionRunner(s, { defaultTheme }, { session }, declaredState = setOf("a", "b"))
563
- r.runOne(mapOf("type" to "setState", "params" to mapOf("a" to "{state.b}", "b" to "{state.a}")), SduiScope(emptyMap(), s), emptyList())
564
- assertEquals(2L, s["a"]); assertEquals(1L, s["b"])
565
- }
566
-
567
- @Test fun setStateWithoutDeclaredStateWritesAnyKey() {
568
- run(mapOf("type" to "setState", "params" to mapOf("brandNew" to "v", "nul" to null)))
569
- assertEquals("v", state["brandNew"]); assertTrue(state.containsKey("nul"))
570
- assertTrue(nodeErrors().isEmpty())
571
- }
572
-
573
- @Test fun runOnlyExecutesActionsWithMatchingName() {
574
- val actions = listOf(
575
- feature("one"), feature("two") + ("name" to "other"), feature("three") + ("name" to null))
576
- runner.run(actions, "onPress", scope, emptyList())
577
- assertEquals(listOf("one"), features.map { it.first })
578
- }
579
-
580
- @Test fun runIgnoresNullListNonMapEntriesAndNamelessEntries() {
581
- runner.run(null, "onPress", scope, emptyList())
582
- runner.run(listOf(null, "str", 5L, listOf(1L), mapOf("type" to "startFeatureCode", "params" to mapOf("featureCode" to "nameless"))), "onPress", scope, emptyList())
583
- assertTrue(features.isEmpty())
584
- assertTrue(nodeErrors().isEmpty())
585
- assertTrue(warnings.isEmpty())
586
- }
587
-
588
- // SduiMaxApi
589
- @Test fun maxApiResolvesTheApiOnEveryCall() {
590
- val a = ArrayList<String>(); val b = ArrayList<String>()
591
- val apiA = fakeMaxApi { n, _ -> a += n }; val apiB = fakeMaxApi { n, _ -> b += n }
592
- var cur: IMaxApi? = apiA
593
- val m = SduiMaxApi({ cur })
594
- m.track("e", emptyMap())
595
- cur = apiB
596
- m.track("e", emptyMap()); m.startFeatureCode("f", emptyMap()); m.logFile("l")
597
- cur = null
598
- m.track("e", emptyMap())
599
- assertEquals(listOf("track"), a)
600
- assertEquals(listOf("track", "startFeatureCode", "logFile"), b)
601
- }
602
-
603
- @Test fun maxApiSwallowsThrowingTrackAndStartFeatureCodeAndKeepsWorking() {
604
- val calls = ArrayList<String>()
605
- val api = fakeMaxApi { n, _ -> calls += n; if (n == "track" || n == "startFeatureCode") error("boom") }
606
- val m = SduiMaxApi({ api })
607
- m.track("e", emptyMap()); m.startFeatureCode("f", emptyMap()); m.logFile("still works")
608
- assertEquals(listOf("track", "startFeatureCode", "logFile"), calls)
609
- }
610
-
611
- @Test fun runnerWithThrowingApiDoesNotEscapeOrReportAnError() {
612
- val api = fakeMaxApi { _, _ -> error("boom") }
613
- val r = SduiActionRunner(state, { defaultTheme }, { session }, SduiMaxApi({ api }))
614
- r.runOne(trackAction(mapOf("eventName" to "t")), scope, emptyList())
615
- r.runOne(feature("fc"), scope, emptyList())
616
- assertTrue(nodeErrors().isEmpty())
617
- }
618
-
619
- @Test fun unexpectedThrowReportsActionErrorOnceWithNodeContextAndDoesNotEscape() {
620
- // the theme provider throws while the action's params are resolved: the only path that reaches runOne's catch
621
- val r = SduiActionRunner(state, { error("boom") }, { session }, featureMaxApi, capturingLog(warnings))
622
- val before = nodeErrors().size
623
- r.runOne(mapOf("type" to "setState", "params" to mapOf("page" to 1L)), scope, emptyList(), "body.children.x", "n_x", "Button")
624
- val got = nodeErrors().drop(before)
625
- assertEquals(1, got.size)
626
- assertEquals("invalid_action", got[0]["code"])
627
- assertEquals("action_error", got[0]["reason"])
628
- assertEquals("body.children.x", got[0]["nodePath"])
629
- assertEquals("n_x", got[0]["nodeId"])
630
- assertEquals("Button", got[0]["nodeType"])
631
- assertEquals(0L, state["page"])
632
- }
633
-
634
- @Test fun throwingSessionDuringActionErrorReportDoesNotEscape() {
635
- val bad = object : RenderSession by RenderSession.NOOP {
636
- override fun nodeError(code: String, reason: String, nodePath: String, nodeType: String?, nodeId: String?) = error("sink down")
637
- }
638
- SduiActionRunner(state, { error("boom") }, { bad }).runOne(mapOf("type" to "setState", "params" to mapOf("page" to 1L)), scope, emptyList())
639
- }
640
-
641
- @Test fun maxApiWithNoApiIsANoOpForAllThreeCalls() {
642
- val m = SduiMaxApi({ null })
643
- m.track("e", mapOf("a" to 1L)); m.startFeatureCode("f", emptyMap()); m.logFile("x")
644
- SduiMaxApi.NONE.track("e", emptyMap())
645
- }
646
- }
647
- // AI-GENERATED END: unit tests for repeat expansion, the action runner