@rocapine/react-native-onboarding 1.74.1 → 1.75.0

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 (50) hide show
  1. package/dist/evaluateCondition.d.ts.map +1 -1
  2. package/dist/evaluateCondition.js +103 -4
  3. package/dist/evaluateCondition.js.map +1 -1
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +25 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/onboarding-example.d.ts +235 -99
  9. package/dist/onboarding-example.d.ts.map +1 -1
  10. package/dist/onboarding-example.js +77 -0
  11. package/dist/onboarding-example.js.map +1 -1
  12. package/dist/screens/completingActions.d.ts +43 -0
  13. package/dist/screens/completingActions.d.ts.map +1 -0
  14. package/dist/screens/completingActions.js +108 -0
  15. package/dist/screens/completingActions.js.map +1 -0
  16. package/dist/screens/elementTypeRegistry.d.ts +31 -0
  17. package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
  18. package/dist/screens/elementTypeRegistry.js +82 -0
  19. package/dist/screens/elementTypeRegistry.js.map +1 -0
  20. package/dist/screens/resolveRenderableStep.d.ts +42 -0
  21. package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
  22. package/dist/screens/resolveRenderableStep.js +28 -0
  23. package/dist/screens/resolveRenderableStep.js.map +1 -0
  24. package/dist/screens/unknownElementTypes.d.ts +94 -0
  25. package/dist/screens/unknownElementTypes.d.ts.map +1 -0
  26. package/dist/screens/unknownElementTypes.js +141 -0
  27. package/dist/screens/unknownElementTypes.js.map +1 -0
  28. package/dist/screens/unknownKeys.d.ts +5 -2
  29. package/dist/screens/unknownKeys.d.ts.map +1 -1
  30. package/dist/screens/unknownKeys.js +7 -52
  31. package/dist/screens/unknownKeys.js.map +1 -1
  32. package/dist/steps/common.types.d.ts +84 -3
  33. package/dist/steps/common.types.d.ts.map +1 -1
  34. package/dist/steps/common.types.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/__tests__/completingActions.test.ts +139 -0
  37. package/src/__tests__/elementTypeRegistry.test.ts +48 -0
  38. package/src/__tests__/evaluateCondition.test.ts +228 -3
  39. package/src/__tests__/onboardingExampleElements.test.ts +27 -0
  40. package/src/__tests__/resolveRenderableStep.test.ts +117 -0
  41. package/src/__tests__/unknownElementTypes.test.ts +240 -0
  42. package/src/evaluateCondition.ts +107 -4
  43. package/src/index.ts +23 -0
  44. package/src/onboarding-example.ts +78 -0
  45. package/src/screens/completingActions.ts +108 -0
  46. package/src/screens/elementTypeRegistry.ts +88 -0
  47. package/src/screens/resolveRenderableStep.ts +59 -0
  48. package/src/screens/unknownElementTypes.ts +204 -0
  49. package/src/screens/unknownKeys.ts +7 -50
  50. package/src/steps/common.types.ts +84 -3
@@ -0,0 +1,139 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { hasCompletingAction } from "../screens/completingActions";
3
+
4
+ /**
5
+ * "Can the user still get off this screen?" (#209, review finding 1).
6
+ *
7
+ * The unknown-element strip removes a subtree, and a ComposableScreen's CTA is
8
+ * authored INSIDE that tree — `ComposableScreenRenderer` passes no `button` to
9
+ * `OnboardingTemplate`, so nothing outside `ScreenRenderer` can call
10
+ * `onContinue`. Strip the element that happened to be the screen's root
11
+ * container and the payload parses cleanly to `elements: []`: a blank screen,
12
+ * no CTA, and with `displayProgressHeader: false` no back chevron either. The
13
+ * throw that at least reached an error boundary became a silent trap.
14
+ *
15
+ * This predicate is what the renderer consults to decide whether it must supply
16
+ * its own escape. `runActions` is the only thing in the runtime that ever calls
17
+ * `onContinue`, and it does so for exactly two actions — `"continue"` and
18
+ * `{type:"dismiss"}` — so those two, wherever they are reachable from a press,
19
+ * are the whole definition of "this screen can be completed".
20
+ */
21
+
22
+ const button = (id: string, actions: unknown[]) => ({
23
+ id,
24
+ type: "Button",
25
+ props: { label: "Go", actions },
26
+ });
27
+
28
+ describe("hasCompletingAction", () => {
29
+ it("finds a Button whose actions continue", () => {
30
+ expect(hasCompletingAction([button("cta", ["continue"])])).toBe(true);
31
+ });
32
+
33
+ it("finds a continue nested inside a container", () => {
34
+ const tree = [
35
+ { id: "root", type: "YStack", props: {}, children: [button("cta", ["continue"])] },
36
+ ];
37
+ expect(hasCompletingAction(tree)).toBe(true);
38
+ });
39
+
40
+ it("reports no way forward for a screen of static content", () => {
41
+ const tree = [
42
+ {
43
+ id: "root",
44
+ type: "YStack",
45
+ props: {},
46
+ children: [{ id: "t", type: "Text", props: { content: "hello" } }],
47
+ },
48
+ ];
49
+ expect(hasCompletingAction(tree)).toBe(false);
50
+ });
51
+
52
+ it("reports no way forward for an empty screen — the exact post-strip case", () => {
53
+ expect(hasCompletingAction([])).toBe(false);
54
+ });
55
+
56
+ it("accepts the deprecated `action: \"continue\"` shorthand", () => {
57
+ expect(hasCompletingAction([{ id: "cta", type: "Button", props: { label: "Go", action: "continue" } }])).toBe(
58
+ true
59
+ );
60
+ });
61
+
62
+ it("accepts the generic `onPress` any element can carry", () => {
63
+ const tree = [{ id: "card", type: "YStack", props: { onPress: ["continue"] }, children: [] }];
64
+ expect(hasCompletingAction(tree)).toBe(true);
65
+ });
66
+
67
+ it("ignores an `onPress` on a Button, which renderElement never wires", () => {
68
+ // `PRESS_HANDLED_TYPES` in `renderElement.tsx`: Button and the other
69
+ // self-handling elements dispatch their own actions, so the generic
70
+ // `onPress` from BaseBoxProps is not wired for them. Counting it would read
71
+ // as "the user can leave" on a screen whose only control does nothing.
72
+ const tree = [{ id: "cta", type: "Button", props: { label: "Go", onPress: ["continue"] } }];
73
+ expect(hasCompletingAction(tree)).toBe(false);
74
+ });
75
+
76
+ it("counts `dismiss`, which completes the screen just as `continue` does", () => {
77
+ expect(hasCompletingAction([button("x", [{ type: "dismiss" }])])).toBe(true);
78
+ });
79
+
80
+ it("finds a continue in a purchase action's onSuccess branch", () => {
81
+ const tree = [
82
+ button("buy", [
83
+ { type: "purchase", product: "p1", onSuccess: ["continue"] },
84
+ ]),
85
+ ];
86
+ expect(hasCompletingAction(tree)).toBe(true);
87
+ });
88
+
89
+ it("finds a continue in a restore action's onNothingToRestore branch", () => {
90
+ const tree = [
91
+ button("restore", [{ type: "restore", onNothingToRestore: ["continue"] }]),
92
+ ];
93
+ expect(hasCompletingAction(tree)).toBe(true);
94
+ });
95
+
96
+ it("does not count setVariable, which leaves the user on the screen", () => {
97
+ const tree = [button("pick", [{ type: "setVariable", name: "goal", value: "lose" }])];
98
+ expect(hasCompletingAction(tree)).toBe(false);
99
+ });
100
+
101
+ it("does not count presentPaywall — a modal opens over the screen, the step does not advance", () => {
102
+ const tree = [button("open", [{ type: "presentPaywall", placement: "hard_paywall" }])];
103
+ expect(hasCompletingAction(tree)).toBe(false);
104
+ });
105
+
106
+ it("does not count a host `custom` action, whose effect this SDK cannot know", () => {
107
+ // Deliberate, and the safer of the two errors: a host handler that
108
+ // navigates by itself would get a redundant escape CTA on an
109
+ // already-degraded screen, whereas guessing the other way re-creates the
110
+ // trap. `runActions` does not call `onContinue` for `custom`.
111
+ const tree = [button("skip", [{ type: "custom", name: "skipOnboarding" }])];
112
+ expect(hasCompletingAction(tree)).toBe(false);
113
+ });
114
+
115
+ it("looks inside a Repeat's children, where a CTA can legitimately live", () => {
116
+ const tree = [
117
+ {
118
+ id: "rep",
119
+ type: "Repeat",
120
+ props: { over: "goals" },
121
+ children: [button("cta", ["continue"])],
122
+ },
123
+ ];
124
+ expect(hasCompletingAction(tree)).toBe(true);
125
+ });
126
+
127
+ it("survives a malformed payload rather than throwing", () => {
128
+ expect(hasCompletingAction([null, 3, "x", { id: "a" }, { props: null }])).toBe(false);
129
+ expect(hasCompletingAction(undefined)).toBe(false);
130
+ expect(hasCompletingAction({ not: "an array" })).toBe(false);
131
+ });
132
+
133
+ it("ignores a bare `{type:\"continue\"}` object — that is not an action this runtime runs", () => {
134
+ // `ButtonActionSchema` declares continue as the string literal `"continue"`.
135
+ // An object is not it, so the runtime would never advance on it; reading it
136
+ // as a way forward would leave the user stuck with no escape.
137
+ expect(hasCompletingAction([button("cta", [{ type: "continue" }])])).toBe(false);
138
+ });
139
+ });
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { z } from "zod";
3
+ import { deriveElementTypeNames, getKnownElementTypes } from "../screens/elementTypeRegistry";
4
+ import { UIElementSchema } from "../screens/types";
5
+
6
+ /**
7
+ * The type-name derivation is schema-AGNOSTIC on purpose (#209, review
8
+ * finding 2).
9
+ *
10
+ * The strip decides what renders, and what renders is the onboarding-ui
11
+ * package's own re-declared `UIElementSchema` — a different file, in a package
12
+ * joined to this one by a peer-dependency RANGE, so the two versions can
13
+ * legitimately differ in a host app. That package therefore has to derive its
14
+ * OWN capability set with this same mechanism instead of inheriting this
15
+ * package's answer, and these tests pin the mechanism it depends on: give it a
16
+ * union it has never seen, get that union's literals back.
17
+ */
18
+
19
+ const variant = (type: string) =>
20
+ z.object({ id: z.string(), type: z.literal(type), props: z.object({}) });
21
+
22
+ describe("deriveElementTypeNames", () => {
23
+ it("reads the literals of a discriminated union it has never seen", () => {
24
+ const schema = z.discriminatedUnion("type", [variant("Halo"), variant("Sparkle")]);
25
+ expect([...deriveElementTypeNames(schema)].sort()).toEqual(["Halo", "Sparkle"]);
26
+ });
27
+
28
+ it("looks through a z.lazy wrapper, as both packages' real schemas use one", () => {
29
+ const schema = z.lazy(() => z.discriminatedUnion("type", [variant("Halo")]));
30
+ expect([...deriveElementTypeNames(schema)]).toEqual(["Halo"]);
31
+ });
32
+
33
+ it("answers with an empty set — never a partial one — for a schema it cannot read", () => {
34
+ // Empty is the agreed "could not tell" signal every caller reads as "learn
35
+ // nothing". Anything else here would be read as a capability list.
36
+ expect(deriveElementTypeNames(z.string()).size).toBe(0);
37
+ expect(deriveElementTypeNames(undefined).size).toBe(0);
38
+ expect(deriveElementTypeNames({ _zod: { def: "nonsense" } }).size).toBe(0);
39
+ });
40
+
41
+ it("agrees with getKnownElementTypes on this package's own schema", () => {
42
+ // The cached, no-argument accessor must be the same derivation applied to
43
+ // the headless union — otherwise "known" would mean two different things.
44
+ expect([...getKnownElementTypes()].sort()).toEqual(
45
+ [...deriveElementTypeNames(UIElementSchema)].sort()
46
+ );
47
+ });
48
+ });
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from "vitest";
1
+ import { describe, it, expect, vi } from "vitest";
2
2
  import { evaluateLeaf, evaluateCondition } from "../evaluateCondition";
3
3
  import type { Condition } from "../evaluateCondition";
4
4
 
@@ -58,7 +58,9 @@ describe("evaluateLeaf — contains (array)", () => {
58
58
  describe("evaluateLeaf — in", () => {
59
59
  it("passes when variable is in list", () => expect(evaluateLeaf({ variable: "gender", operator: "in", value: ["male", "female"] }, { gender: "male" })).toBe(true));
60
60
  it("fails when variable not in list", () => expect(evaluateLeaf({ variable: "gender", operator: "in", value: ["male", "female"] }, { gender: "other" })).toBe(false));
61
- it("returns false when value is not array", () => expect(evaluateLeaf({ variable: "x", operator: "in", value: "male" as any }, { x: "male" })).toBe(false));
61
+ // A right-hand side that is not literally an array is covered by the `#225`
62
+ // block at the bottom of this file: it is normalized to a member list rather
63
+ // than answering a constant.
62
64
  it("empty list always false", () => expect(evaluateLeaf({ variable: "x", operator: "in", value: [] }, { x: "male" })).toBe(false));
63
65
  it("coerces numeric raw to string before comparison", () => expect(evaluateLeaf({ variable: "age", operator: "in", value: ["18", "25"] }, { age: 18 })).toBe(true));
64
66
  it("numeric raw not in string list returns false", () => expect(evaluateLeaf({ variable: "age", operator: "in", value: ["30", "40"] }, { age: 18 })).toBe(false));
@@ -67,7 +69,6 @@ describe("evaluateLeaf — in", () => {
67
69
  describe("evaluateLeaf — not_in", () => {
68
70
  it("passes when variable not in list", () => expect(evaluateLeaf({ variable: "gender", operator: "not_in", value: ["male", "female"] }, { gender: "other" })).toBe(true));
69
71
  it("fails when variable is in list", () => expect(evaluateLeaf({ variable: "gender", operator: "not_in", value: ["male", "female"] }, { gender: "male" })).toBe(false));
70
- it("returns true when value is not array (safe default)", () => expect(evaluateLeaf({ variable: "x", operator: "not_in", value: "male" as any }, { x: "male" })).toBe(true));
71
72
  it("coerces numeric raw to string before comparison", () => expect(evaluateLeaf({ variable: "age", operator: "not_in", value: ["18", "25"] }, { age: 30 })).toBe(true));
72
73
  it("numeric raw in string list returns false", () => expect(evaluateLeaf({ variable: "age", operator: "not_in", value: ["18", "25"] }, { age: 18 })).toBe(false));
73
74
  });
@@ -200,3 +201,227 @@ describe("evaluateCondition — leaf passthrough", () => {
200
201
  expect(evaluateCondition(leaf, { x: "no" })).toBe(false);
201
202
  });
202
203
  });
204
+
205
+ // ---------------------------------------------------------------------------
206
+ // evaluateLeaf — `{{var}}` references on the RIGHT-hand side
207
+ //
208
+ // `RepeatElement` documents "Repeat plus a per-row gate is a switch" using
209
+ // `{ variable: "item.sign", operator: "eq", value: "{{zodiacSign}}" }`. That
210
+ // only works if the condition's `value` is interpolated against the same
211
+ // variable map, which lets a condition compare two variables rather than a
212
+ // variable against an authored literal. See issue #217.
213
+ // ---------------------------------------------------------------------------
214
+
215
+ describe("evaluateLeaf — variable references in `value`", () => {
216
+ it("matches the documented Repeat-as-Match example", () =>
217
+ expect(
218
+ evaluateLeaf(
219
+ { variable: "item.sign", operator: "eq", value: "{{zodiacSign}}" },
220
+ { "item.sign": "aries", zodiacSign: "aries" }
221
+ )
222
+ ).toBe(true));
223
+
224
+ it("rejects the rows the switch should not select", () =>
225
+ expect(
226
+ evaluateLeaf(
227
+ { variable: "item.sign", operator: "eq", value: "{{zodiacSign}}" },
228
+ { "item.sign": "taurus", zodiacSign: "aries" }
229
+ )
230
+ ).toBe(false));
231
+
232
+ it("compares two variables numerically", () =>
233
+ expect(
234
+ evaluateLeaf(
235
+ { variable: "score", operator: "gt", value: "{{threshold}}" },
236
+ { score: 80, threshold: 50 }
237
+ )
238
+ ).toBe(true));
239
+
240
+ it("resolves a reference embedded in surrounding text", () =>
241
+ expect(
242
+ evaluateLeaf(
243
+ { variable: "sku", operator: "eq", value: "plan_{{tier}}" },
244
+ { sku: "plan_yearly", tier: "yearly" }
245
+ )
246
+ ).toBe(true));
247
+
248
+ it("interpolates references inside an `in` array", () =>
249
+ expect(
250
+ evaluateLeaf(
251
+ { variable: "x", operator: "in", value: ["{{a}}", "{{b}}"] },
252
+ { x: "two", a: "one", b: "two" }
253
+ )
254
+ ).toBe(true));
255
+
256
+ it("resolves an unknown reference to the empty string", () =>
257
+ expect(
258
+ evaluateLeaf(
259
+ { variable: "x", operator: "eq", value: "{{nope}}" },
260
+ { x: "something" }
261
+ )
262
+ ).toBe(false));
263
+
264
+ it("treats a plain literal as a literal", () =>
265
+ expect(
266
+ evaluateLeaf({ variable: "x", operator: "eq", value: "aries" }, { x: "aries" })
267
+ ).toBe(true));
268
+
269
+ it("does not interpolate a literal containing no reference syntax", () =>
270
+ expect(
271
+ evaluateLeaf({ variable: "x", operator: "eq", value: "{not a ref}" }, { x: "{not a ref}" })
272
+ ).toBe(true));
273
+ });
274
+
275
+ // ---------------------------------------------------------------------------
276
+ // evaluateLeaf — `in` / `not_in` right-hand side that is not literally an array
277
+ //
278
+ // Both operators used to answer a CONSTANT whenever `Array.isArray(value)` was
279
+ // false — `in` false for every row, `not_in` true for every row, no warning
280
+ // (issue #225). Two shapes reach them that way, and both are the natural way to
281
+ // author a membership test now that #217 made a `{{ref}}` on the right-hand
282
+ // side resolve:
283
+ //
284
+ // value: "{{selected}}" a reference to a multi-select variable, whose
285
+ // flat value is a JSON-encoded string '["a","b"]'
286
+ // value: ["{{selected}}"] what Studio's condition editor emits — it splits
287
+ // the value field on commas, so the reference lands
288
+ // as the single member of a one-member array
289
+ //
290
+ // Both must flatten to the same member list, else a fix covering only the bare
291
+ // string leaves every Studio-authored payload broken in the same silent way.
292
+ // ---------------------------------------------------------------------------
293
+
294
+ describe("evaluateLeaf — in / not_in against a JSON-array-string reference", () => {
295
+ const vars = (row: string) => ({ selected: '["sleep","energy"]', "item.value": row });
296
+
297
+ it("`in` matches a row that is a member of the referenced selection", () =>
298
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value: "{{selected}}" }, vars("sleep"))).toBe(true));
299
+
300
+ it("`in` rejects a row that is not a member", () =>
301
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value: "{{selected}}" }, vars("focus"))).toBe(false));
302
+
303
+ it("`not_in` rejects a row that is a member", () =>
304
+ expect(evaluateLeaf({ variable: "item.value", operator: "not_in", value: "{{selected}}" }, vars("sleep"))).toBe(false));
305
+
306
+ it("`not_in` matches a row that is not a member", () =>
307
+ expect(evaluateLeaf({ variable: "item.value", operator: "not_in", value: "{{selected}}" }, vars("focus"))).toBe(true));
308
+
309
+ it("an authored JSON-array literal string is also a list", () =>
310
+ expect(evaluateLeaf({ variable: "x", operator: "in", value: '["a","b"]' }, { x: "b" })).toBe(true));
311
+ });
312
+
313
+ describe("evaluateLeaf — in / not_in with the array-wrapped shape Studio emits", () => {
314
+ const vars = (row: string) => ({ selected: '["sleep","energy"]', "item.value": row });
315
+
316
+ it("flattens a one-member array holding the JSON string", () =>
317
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value: ["{{selected}}"] }, vars("sleep"))).toBe(true));
318
+
319
+ it("still rejects a non-member through the flattened shape", () =>
320
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value: ["{{selected}}"] }, vars("focus"))).toBe(false));
321
+
322
+ it("`not_in` is the negation through the flattened shape", () => {
323
+ expect(evaluateLeaf({ variable: "item.value", operator: "not_in", value: ["{{selected}}"] }, vars("energy"))).toBe(false);
324
+ expect(evaluateLeaf({ variable: "item.value", operator: "not_in", value: ["{{selected}}"] }, vars("focus"))).toBe(true);
325
+ });
326
+
327
+ it("mixes a literal member with a referenced list", () => {
328
+ const value = ["mood", "{{selected}}"];
329
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value }, vars("mood"))).toBe(true);
330
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value }, vars("energy"))).toBe(true);
331
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value }, vars("focus"))).toBe(false);
332
+ });
333
+
334
+ it("an empty value field (Studio yields []) keeps its documented constants", () => {
335
+ expect(evaluateLeaf({ variable: "x", operator: "in", value: [] }, { x: "a" })).toBe(false);
336
+ expect(evaluateLeaf({ variable: "x", operator: "not_in", value: [] }, { x: "a" })).toBe(true);
337
+ });
338
+ });
339
+
340
+ describe("evaluateLeaf — an unresolved reference has no members in EITHER shape", () => {
341
+ // The array-wrapped shape is the one Studio actually emits — its condition
342
+ // editor always splits the value field into an array — so an unresolved
343
+ // reference has to mean "no members" there too. Interpolation resolves it to
344
+ // the empty string, and keeping that as a MEMBER makes an empty-string
345
+ // variable a member of a list nobody has written: `in` true, `not_in` false,
346
+ // the exact opposite of the bare-reference shape on the same data. An
347
+ // empty-string variable is reachable — `InputElement` stores "" on clear and
348
+ // `Input.defaultValue: ""` is overlaid into the variable map.
349
+ it("`in` never matches, even when the variable is the empty string", () =>
350
+ expect(evaluateLeaf({ variable: "name", operator: "in", value: ["{{blocked}}"] }, { name: "" })).toBe(false));
351
+
352
+ it("`not_in` matches every row, even when the variable is the empty string", () =>
353
+ expect(evaluateLeaf({ variable: "name", operator: "not_in", value: ["{{blocked}}"] }, { name: "" })).toBe(true));
354
+
355
+ it("answers the same as the bare-reference shape on the same data", () => {
356
+ const vars = { name: "" };
357
+ expect(evaluateLeaf({ variable: "name", operator: "in", value: ["{{blocked}}"] }, vars)).toBe(
358
+ evaluateLeaf({ variable: "name", operator: "in", value: "{{blocked}}" }, vars)
359
+ );
360
+ expect(evaluateLeaf({ variable: "name", operator: "not_in", value: ["{{blocked}}"] }, vars)).toBe(
361
+ evaluateLeaf({ variable: "name", operator: "not_in", value: "{{blocked}}" }, vars)
362
+ );
363
+ });
364
+
365
+ it("drops only the unresolved member, keeping the resolved ones", () => {
366
+ const value = ["{{blocked}}", "{{selected}}"];
367
+ const vars = (row: string) => ({ selected: '["sleep"]', "item.value": row });
368
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value }, vars("sleep"))).toBe(true);
369
+ expect(evaluateLeaf({ variable: "item.value", operator: "in", value }, vars(""))).toBe(false);
370
+ });
371
+ });
372
+
373
+ describe("evaluateLeaf — membership compares members stringified", () => {
374
+ // A payload-authored literal array may hold numbers (ConditionValueSchema
375
+ // permits them), and `Repeat` keeps a numeric row field numeric on purpose
376
+ // (`repeatScope.buildRowFlat`), so `1` and `"1"` must be the same member.
377
+ it("a numeric variable is a member of a numeric list", () =>
378
+ expect(evaluateLeaf({ variable: "id", operator: "in", value: [1, 2] }, { id: 1 })).toBe(true));
379
+
380
+ it("`not_in` agrees with `in` on a numeric list", () =>
381
+ expect(evaluateLeaf({ variable: "id", operator: "not_in", value: [1, 2] }, { id: 1 })).toBe(false));
382
+
383
+ it("a numeric variable is not a member of a list it is absent from", () =>
384
+ expect(evaluateLeaf({ variable: "id", operator: "not_in", value: [1, 2] }, { id: 3 })).toBe(true));
385
+
386
+ it("a numeric row field matches a decoded string list", () =>
387
+ expect(evaluateLeaf({ variable: "item.id", operator: "in", value: "{{picked}}" }, { picked: '["1","2"]', "item.id": 1 })).toBe(true));
388
+
389
+ it("`contains` uses the same member comparison on an array variable", () => {
390
+ expect(evaluateLeaf({ variable: "ids", operator: "contains", value: "1" }, { ids: [1, 2] })).toBe(true);
391
+ expect(evaluateLeaf({ variable: "ids", operator: "contains", value: "{{item.id}}" }, { ids: [1, 2], "item.id": 1 })).toBe(true);
392
+ expect(evaluateLeaf({ variable: "ids", operator: "contains", value: "3" }, { ids: [1, 2] })).toBe(false);
393
+ });
394
+ });
395
+
396
+ describe("evaluateLeaf — in / not_in with a right-hand side that is no list at all", () => {
397
+ it("an unresolved reference has no members, so `in` never matches", () =>
398
+ expect(evaluateLeaf({ variable: "x", operator: "in", value: "{{nope}}" }, { x: "sleep" })).toBe(false));
399
+
400
+ it("an unresolved reference has no members, so `not_in` matches every row", () =>
401
+ expect(evaluateLeaf({ variable: "x", operator: "not_in", value: "{{nope}}" }, { x: "sleep" })).toBe(true));
402
+
403
+ it("a scalar right-hand side reads as a one-member list rather than a constant", () => {
404
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
405
+ expect(evaluateLeaf({ variable: "x", operator: "in", value: "male" }, { x: "male" })).toBe(true);
406
+ expect(evaluateLeaf({ variable: "x", operator: "in", value: "male" }, { x: "female" })).toBe(false);
407
+ expect(evaluateLeaf({ variable: "x", operator: "not_in", value: "male" }, { x: "male" })).toBe(false);
408
+ warn.mockRestore();
409
+ });
410
+
411
+ it("warns once per evaluation about a scalar right-hand side, naming the operator", () => {
412
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
413
+ evaluateLeaf({ variable: "x", operator: "in", value: "male" }, { x: "male" });
414
+ expect(warn).toHaveBeenCalledTimes(1);
415
+ expect(String(warn.mock.calls[0]?.[0])).toContain('operator "in"');
416
+ warn.mockRestore();
417
+ });
418
+
419
+ it("does not warn when the right-hand side is a real list", () => {
420
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
421
+ evaluateLeaf({ variable: "x", operator: "in", value: ["male"] }, { x: "male" });
422
+ evaluateLeaf({ variable: "x", operator: "not_in", value: "{{sel}}" }, { x: "male", sel: '["male"]' });
423
+ evaluateLeaf({ variable: "x", operator: "in", value: "{{nope}}" }, { x: "male" });
424
+ expect(warn).not.toHaveBeenCalled();
425
+ warn.mockRestore();
426
+ });
427
+ });
@@ -0,0 +1,27 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { ScreenElementsSchema } from "../screens/types";
3
+ import { onboardingExample } from "../onboarding-example";
4
+
5
+ // The default onboarding is the payload every example app and the studio's
6
+ // seed data render, and CLAUDE.md's element procedure (step 1) requires keeping
7
+ // it in sync with the schema. Nothing enforced that: a `setVariable` action or
8
+ // element prop added to the example but not to the Zod union would ship a
9
+ // payload the runtime refuses to parse, and the only symptom would be a broken
10
+ // example app. This test closes that hole for the ComposableScreen steps.
11
+ describe("onboarding-example ComposableScreen payloads", () => {
12
+ const composableSteps = onboardingExample.steps.filter(
13
+ (s) => s.type === "ComposableScreen"
14
+ );
15
+
16
+ it("has ComposableScreen steps to check", () => {
17
+ expect(composableSteps.length).toBeGreaterThan(0);
18
+ });
19
+
20
+ for (const step of composableSteps) {
21
+ it(`step "${step.name}" validates against ScreenElementsSchema`, () => {
22
+ const result = ScreenElementsSchema.safeParse(step.payload?.elements);
23
+ // Surface the actual zod issues rather than a bare `false`.
24
+ expect(result.success ? [] : result.error.issues).toEqual([]);
25
+ });
26
+ }
27
+ });
@@ -0,0 +1,117 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { resolveRenderableStep } from "../screens/resolveRenderableStep";
3
+ import { ComposableScreenStepTypeSchema } from "../steps/ComposableScreen/types";
4
+
5
+ /**
6
+ * The whole render-boundary decision for #209, in one pure function, so the
7
+ * ComposableScreen renderer holds no logic that this package's tests cannot
8
+ * reach (the UI package's vitest runs in plain Node and cannot import
9
+ * `react-native`, so anything decided there is only assertable at source level).
10
+ *
11
+ * Two questions, answered together because the second only has meaning after
12
+ * the first: what should be parsed, and can the user still leave the screen?
13
+ */
14
+
15
+ const text = (id: string, content: string) => ({ id, type: "Text", props: { content } });
16
+ const cta = (id: string) => ({
17
+ id,
18
+ type: "Button",
19
+ props: { label: "Continue", actions: ["continue"] },
20
+ });
21
+
22
+ const step = (elements: unknown[]) => ({
23
+ id: "s",
24
+ name: "Step one",
25
+ type: "ComposableScreen",
26
+ displayProgressHeader: false,
27
+ payload: { elements },
28
+ });
29
+
30
+ describe("resolveRenderableStep", () => {
31
+ it("hands back the same step reference when every element type is known", () => {
32
+ const clean = step([text("t", "hi"), cta("go")]);
33
+ const resolved = resolveRenderableStep(clean);
34
+ expect(resolved.step).toBe(clean);
35
+ expect(resolved.omitted).toEqual([]);
36
+ expect(resolved.needsEscape).toBe(false);
37
+ });
38
+
39
+ it("asks for an escape when the strip takes the screen's only way forward", () => {
40
+ // The reviewer's reproduction, and the shape the shipped example payload
41
+ // itself uses: ONE root container holding everything, including the CTA. If
42
+ // that container is a type this build does not know, the strip empties the
43
+ // screen — `[]` parses cleanly, so nothing throws and nothing renders.
44
+ const trapped = step([
45
+ { id: "root", type: "HolographicCard", props: {}, children: [text("t", "hi"), cta("go")] },
46
+ ]);
47
+ const resolved = resolveRenderableStep(trapped);
48
+
49
+ const parsed = ComposableScreenStepTypeSchema.parse(resolved.step);
50
+ expect(parsed.payload.elements).toEqual([]);
51
+ expect(resolved.needsEscape).toBe(true);
52
+ expect(resolved.omitted.map((o) => o.elementType)).toEqual(["HolographicCard"]);
53
+ });
54
+
55
+ it("needs no escape when a CTA survives the strip", () => {
56
+ const resolved = resolveRenderableStep(
57
+ step([{ id: "x", type: "HolographicCard", props: {} }, cta("go")])
58
+ );
59
+ expect(resolved.needsEscape).toBe(false);
60
+ expect(resolved.omitted).toHaveLength(1);
61
+ });
62
+
63
+ it("needs an escape when the surviving tree has content but nothing pressable", () => {
64
+ const resolved = resolveRenderableStep(
65
+ step([text("t", "hi"), { id: "x", type: "TimeOfDayPicker", props: {}, children: [cta("go")] }])
66
+ );
67
+ expect(resolved.needsEscape).toBe(true);
68
+ });
69
+
70
+ it("leaves an authored screen with no CTA alone — nothing was stripped, so nothing is ours to fix", () => {
71
+ // A screen the author gave no way forward is an authoring bug, and the host
72
+ // may well advance it some other way (a custom action that navigates, a
73
+ // timer). Injecting a CTA there would change shipped screens that have
74
+ // nothing to do with an unknown element type.
75
+ const authored = step([text("t", "hi")]);
76
+ const resolved = resolveRenderableStep(authored);
77
+ expect(resolved.step).toBe(authored);
78
+ expect(resolved.needsEscape).toBe(false);
79
+ });
80
+
81
+ it("passes a step with no element payload straight through", () => {
82
+ const ratings = { id: "r", type: "Ratings", payload: { title: "x" } };
83
+ const resolved = resolveRenderableStep(ratings);
84
+ expect(resolved.step).toBe(ratings);
85
+ expect(resolved.needsEscape).toBe(false);
86
+ });
87
+
88
+ it("strips nothing and asks for nothing when it cannot tell which types are known", () => {
89
+ // An empty capability set means the derivation failed, which must read as
90
+ // "learn nothing" — never as "reject everything", which would blank every
91
+ // screen in every app and then cover each one with a fallback CTA.
92
+ const trapped = step([
93
+ { id: "root", type: "HolographicCard", props: {}, children: [cta("go")] },
94
+ ]);
95
+ const resolved = resolveRenderableStep(trapped, new Set<string>());
96
+ expect(resolved.step).toBe(trapped);
97
+ expect(resolved.omitted).toEqual([]);
98
+ expect(resolved.needsEscape).toBe(false);
99
+ });
100
+
101
+ it("keys off the capability set it is given, not the schema it was built from", () => {
102
+ // What renders is the onboarding-ui package's own re-declared union, whose
103
+ // installed version can differ from this one's. The caller supplies the set;
104
+ // here `Button` is deliberately absent from it and must be stripped.
105
+ const resolved = resolveRenderableStep(step([text("t", "hi"), cta("go")]), new Set(["Text"]));
106
+ const parsed = ComposableScreenStepTypeSchema.parse(resolved.step);
107
+ expect(parsed.payload.elements.map((e) => e.id)).toEqual(["t"]);
108
+ expect(resolved.needsEscape).toBe(true);
109
+ });
110
+
111
+ it("does not mutate the step it was given", () => {
112
+ const trapped = step([{ id: "x", type: "HolographicCard", props: {} }, cta("go")]);
113
+ const before = JSON.stringify(trapped);
114
+ resolveRenderableStep(trapped);
115
+ expect(JSON.stringify(trapped)).toBe(before);
116
+ });
117
+ });