@rocapine/react-native-onboarding 1.74.1 → 1.76.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.
- package/dist/evaluateCondition.d.ts.map +1 -1
- package/dist/evaluateCondition.js +103 -4
- package/dist/evaluateCondition.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/onboarding-example.d.ts +375 -99
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +118 -1
- package/dist/onboarding-example.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +71 -5
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +237 -57
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +31 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- package/dist/paywalls/observer.d.ts +129 -0
- package/dist/paywalls/observer.d.ts.map +1 -0
- package/dist/paywalls/observer.js +211 -0
- package/dist/paywalls/observer.js.map +1 -0
- package/dist/paywalls/present.d.ts +19 -15
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +21 -17
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/types.d.ts +3 -1
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +38 -1
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +509 -75
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/products/index.d.ts +1 -0
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/types.d.ts +13 -0
- package/dist/products/types.d.ts.map +1 -1
- package/dist/screens/completingActions.d.ts +95 -0
- package/dist/screens/completingActions.d.ts.map +1 -0
- package/dist/screens/completingActions.js +302 -0
- package/dist/screens/completingActions.js.map +1 -0
- package/dist/screens/elementTypeRegistry.d.ts +45 -0
- package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
- package/dist/screens/elementTypeRegistry.js +119 -0
- package/dist/screens/elementTypeRegistry.js.map +1 -0
- package/dist/screens/elements/ButtonElement.d.ts +3 -2
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/ButtonElement.js +5 -1
- package/dist/screens/elements/ButtonElement.js.map +1 -1
- package/dist/screens/resolveRenderableStep.d.ts +42 -0
- package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
- package/dist/screens/resolveRenderableStep.js +28 -0
- package/dist/screens/resolveRenderableStep.js.map +1 -0
- package/dist/screens/types.d.ts +2 -2
- package/dist/screens/types.d.ts.map +1 -1
- package/dist/screens/types.js +5 -1
- package/dist/screens/types.js.map +1 -1
- package/dist/screens/unknownElementTypes.d.ts +94 -0
- package/dist/screens/unknownElementTypes.d.ts.map +1 -0
- package/dist/screens/unknownElementTypes.js +141 -0
- package/dist/screens/unknownElementTypes.js.map +1 -0
- package/dist/screens/unknownKeys.d.ts +30 -6
- package/dist/screens/unknownKeys.d.ts.map +1 -1
- package/dist/screens/unknownKeys.js +88 -54
- package/dist/screens/unknownKeys.js.map +1 -1
- package/dist/steps/common.types.d.ts +262 -9
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +64 -3
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/authoringDocEscapes.test.ts +59 -0
- package/src/__tests__/completingActions.test.ts +509 -0
- package/src/__tests__/customActionHooks.test.ts +224 -0
- package/src/__tests__/elementTypeRegistry.test.ts +48 -0
- package/src/__tests__/evaluateCondition.test.ts +228 -3
- package/src/__tests__/onboardingExampleElements.test.ts +74 -0
- package/src/__tests__/requestPermissionAction.test.ts +138 -0
- package/src/__tests__/resolveRenderableStep.test.ts +117 -0
- package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
- package/src/__tests__/unknownElementTypes.test.ts +240 -0
- package/src/__tests__/unknownKeys.test.ts +110 -0
- package/src/evaluateCondition.ts +107 -4
- package/src/index.ts +55 -0
- package/src/onboarding-example.ts +119 -1
- package/src/paywalls/PaywallProvider.tsx +370 -66
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
- package/src/paywalls/__tests__/observer.test.ts +401 -0
- package/src/paywalls/__tests__/present.test.ts +0 -18
- package/src/paywalls/customScreens.ts +34 -1
- package/src/paywalls/observer.ts +308 -0
- package/src/paywalls/present.ts +24 -18
- package/src/paywalls/types.ts +3 -1
- package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
- package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
- package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
- package/src/products/adapters/expoIap.ts +609 -78
- package/src/products/index.ts +1 -0
- package/src/products/types.ts +13 -0
- package/src/screens/completingActions.ts +316 -0
- package/src/screens/elementTypeRegistry.ts +122 -0
- package/src/screens/elements/ButtonElement.ts +9 -1
- package/src/screens/resolveRenderableStep.ts +59 -0
- package/src/screens/types.ts +2 -2
- package/src/screens/unknownElementTypes.ts +204 -0
- package/src/screens/unknownKeys.ts +119 -56
- package/src/steps/common.types.ts +297 -9
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { ButtonActionSchema, CustomButtonActionSchema } from "../steps/common.types";
|
|
3
|
+
import { hasCompletingAction } from "../screens/completingActions";
|
|
4
|
+
|
|
5
|
+
// RNO#191 — the declarative half of an async gate. `custom` gains the same
|
|
6
|
+
// nested-`ButtonAction[]` outcome hooks `purchase`/`restore` already carry,
|
|
7
|
+
// plus a bounded retry. These assert the HEADLESS schema (the one that
|
|
8
|
+
// validates the payload); the UI mirror is asserted in
|
|
9
|
+
// `packages/onboarding-ui/src/UI/Runtime/__tests__/runActions.test.ts`.
|
|
10
|
+
|
|
11
|
+
describe("CustomButtonAction schema — outcome hooks", () => {
|
|
12
|
+
// Asserting the PARSED OUTPUT, not just `success`: Zod strips unrecognized
|
|
13
|
+
// keys, so an unimplemented hook parses "successfully" and silently vanishes
|
|
14
|
+
// before it ever reaches `runActions`.
|
|
15
|
+
it("accepts onResolve and onError action lists and keeps them", () => {
|
|
16
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
17
|
+
type: "custom",
|
|
18
|
+
function: "generatePlan",
|
|
19
|
+
variables: ["goal"],
|
|
20
|
+
onResolve: ["continue"],
|
|
21
|
+
onError: [{ type: "setVariable", name: "planError", value: "true" }],
|
|
22
|
+
});
|
|
23
|
+
expect(parsed.success).toBe(true);
|
|
24
|
+
expect((parsed as any).data.onResolve).toEqual(["continue"]);
|
|
25
|
+
expect((parsed as any).data.onError).toEqual([
|
|
26
|
+
{ type: "setVariable", name: "planError", value: "true" },
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("accepts a nested custom action inside onError (recursion)", () => {
|
|
31
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
32
|
+
type: "custom",
|
|
33
|
+
function: "generatePlan",
|
|
34
|
+
onError: [{ type: "custom", function: "reportFailure" }],
|
|
35
|
+
});
|
|
36
|
+
expect(parsed.success).toBe(true);
|
|
37
|
+
expect((parsed as any).data.onError[0].function).toBe("reportFailure");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("still accepts the pre-#191 three-field shape", () => {
|
|
41
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
42
|
+
type: "custom",
|
|
43
|
+
function: "generatePlan",
|
|
44
|
+
variables: ["goal"],
|
|
45
|
+
});
|
|
46
|
+
expect(parsed.success).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("is reachable through the ButtonAction union with its hooks", () => {
|
|
50
|
+
const parsed = ButtonActionSchema.safeParse({
|
|
51
|
+
type: "custom",
|
|
52
|
+
function: "generatePlan",
|
|
53
|
+
onResolve: ["continue"],
|
|
54
|
+
});
|
|
55
|
+
expect(parsed.success).toBe(true);
|
|
56
|
+
expect((parsed as any).data.onResolve).toEqual(["continue"]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("CustomButtonAction schema — bounded retry", () => {
|
|
61
|
+
it("accepts an explicit attempt cap", () => {
|
|
62
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
63
|
+
type: "custom",
|
|
64
|
+
function: "generatePlan",
|
|
65
|
+
retry: { maxAttempts: 3, delayMs: 500 },
|
|
66
|
+
});
|
|
67
|
+
expect(parsed.success).toBe(true);
|
|
68
|
+
expect((parsed as any).data.retry).toEqual({ maxAttempts: 3, delayMs: 500 });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// The cap is what makes the retry BOUNDED — a payload that forgets it, or
|
|
72
|
+
// asks for an unbounded/absurd number of attempts, must fail at parse time
|
|
73
|
+
// rather than hang a screen behind a dead service.
|
|
74
|
+
it("rejects a retry with no attempt cap", () => {
|
|
75
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
76
|
+
type: "custom",
|
|
77
|
+
function: "generatePlan",
|
|
78
|
+
retry: { delayMs: 500 },
|
|
79
|
+
});
|
|
80
|
+
expect(parsed.success).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("rejects fewer than one attempt", () => {
|
|
84
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
85
|
+
type: "custom",
|
|
86
|
+
function: "generatePlan",
|
|
87
|
+
retry: { maxAttempts: 0 },
|
|
88
|
+
});
|
|
89
|
+
expect(parsed.success).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("rejects more attempts than the runtime will make", () => {
|
|
93
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
94
|
+
type: "custom",
|
|
95
|
+
function: "generatePlan",
|
|
96
|
+
retry: { maxAttempts: 11 },
|
|
97
|
+
});
|
|
98
|
+
expect(parsed.success).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("rejects a fractional attempt cap", () => {
|
|
102
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
103
|
+
type: "custom",
|
|
104
|
+
function: "generatePlan",
|
|
105
|
+
retry: { maxAttempts: 2.5 },
|
|
106
|
+
});
|
|
107
|
+
expect(parsed.success).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// RNO#264 — `maxAttempts` bounds the NUMBER of attempts; nothing bounded ONE
|
|
112
|
+
// attempt's duration, so a handler whose promise never settles held the
|
|
113
|
+
// single-flight claim for the life of the screen and the documented
|
|
114
|
+
// `disabledWhen: actions.pending.<id>` payload greyed the CTA out permanently.
|
|
115
|
+
describe("CustomActionRetry schema — per-attempt timeoutMs (#264)", () => {
|
|
116
|
+
const retry = (retry: Record<string, unknown>) =>
|
|
117
|
+
CustomButtonActionSchema.safeParse({
|
|
118
|
+
type: "custom",
|
|
119
|
+
function: "generatePlan",
|
|
120
|
+
retry,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("accepts a per-attempt timeout and keeps it", () => {
|
|
124
|
+
const parsed = retry({ maxAttempts: 3, delayMs: 400, timeoutMs: 15000 });
|
|
125
|
+
expect(parsed.success).toBe(true);
|
|
126
|
+
expect((parsed as any).data.retry).toEqual({
|
|
127
|
+
maxAttempts: 3,
|
|
128
|
+
delayMs: 400,
|
|
129
|
+
timeoutMs: 15000,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// A timeout without retries is the #264 repro itself — one attempt that never
|
|
134
|
+
// answers — so it must be authorable without pretending to want retries.
|
|
135
|
+
it("accepts a timeout on a single-attempt policy", () => {
|
|
136
|
+
const parsed = retry({ maxAttempts: 1, timeoutMs: 30000 });
|
|
137
|
+
expect(parsed.success).toBe(true);
|
|
138
|
+
expect((parsed as any).data.retry.timeoutMs).toBe(30000);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("is optional — an absent timeout means unbounded, as before", () => {
|
|
142
|
+
const parsed = retry({ maxAttempts: 2 });
|
|
143
|
+
expect(parsed.success).toBe(true);
|
|
144
|
+
expect((parsed as any).data.retry.timeoutMs).toBeUndefined();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// A sub-second timeout cannot be met by any real network call, so it is a
|
|
148
|
+
// typo (milliseconds meant as seconds), not a policy.
|
|
149
|
+
it("rejects a timeout too short for any real handler", () => {
|
|
150
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 0 }).success).toBe(false);
|
|
151
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 250 }).success).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Generous on purpose: a legitimate LLM call can take 60s+, and cutting one
|
|
155
|
+
// off would be a worse bug than the hang. Five minutes is the ceiling.
|
|
156
|
+
it("accepts a generous timeout and rejects one past the ceiling", () => {
|
|
157
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 300000 }).success).toBe(true);
|
|
158
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 300001 }).success).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("rejects a non-numeric timeout", () => {
|
|
162
|
+
expect(retry({ maxAttempts: 1, timeoutMs: "5000" }).success).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe("hasCompletingAction and a custom action's hooks (#209 guard)", () => {
|
|
167
|
+
// Round 1 asserted the opposite of this — that `onResolve: ["continue"]` alone
|
|
168
|
+
// makes the screen completable — and review round 1, finding 6 refuted it.
|
|
169
|
+
// The resolve path is not the user's to reach: `ScreenHost`'s default is
|
|
170
|
+
// `customActions: {}`, and an unregistered name runs `onError` and whatever
|
|
171
|
+
// follows the action, never `onResolve`. So a `"continue"` in `onResolve`
|
|
172
|
+
// alone is not a way off the screen. Read with AND across the outcomes, like
|
|
173
|
+
// `requestPermission` (`completingActions.ts` — `customActionEscapes`), over
|
|
174
|
+
// the action's two paths: the handler resolved, and the handler failed.
|
|
175
|
+
const cta = (actions: unknown[]) => [
|
|
176
|
+
{ type: "Button", id: "cta", props: { label: "Generate", actions } },
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
it("does not count a continue reachable only on the resolve path", () => {
|
|
180
|
+
expect(
|
|
181
|
+
hasCompletingAction(
|
|
182
|
+
cta([{ type: "custom", function: "generatePlan", onResolve: ["continue"] }])
|
|
183
|
+
)
|
|
184
|
+
).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("counts it when the error path also reaches a way off the screen", () => {
|
|
188
|
+
expect(
|
|
189
|
+
hasCompletingAction(
|
|
190
|
+
cta([
|
|
191
|
+
{
|
|
192
|
+
type: "custom",
|
|
193
|
+
function: "generatePlan",
|
|
194
|
+
onResolve: ["continue"],
|
|
195
|
+
onError: ["continue"],
|
|
196
|
+
},
|
|
197
|
+
])
|
|
198
|
+
)
|
|
199
|
+
).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("counts a sibling continue after the custom action", () => {
|
|
203
|
+
// The trailing `"continue"` runs on both of the action's paths — handler
|
|
204
|
+
// resolved, and handler failed however it failed — so it IS the screen's
|
|
205
|
+
// way forward. It used to be reachable on only two of three paths, the
|
|
206
|
+
// throw path having aborted the list; the semantics decision of 2026-09-11
|
|
207
|
+
// removed that path, so this row no longer rests on a retryability
|
|
208
|
+
// argument.
|
|
209
|
+
//
|
|
210
|
+
// Round 2 of this PR required `onError` here, which read every
|
|
211
|
+
// `[{custom}, "continue"]` payload in the field as a trap: Studio's action
|
|
212
|
+
// editor cannot author `onResolve`/`onError` until
|
|
213
|
+
// `rocapine/onboarding-studio#288` lands, so the prescribed fix was not
|
|
214
|
+
// available to anyone the verdict applied to.
|
|
215
|
+
expect(
|
|
216
|
+
hasCompletingAction(cta([{ type: "custom", function: "generatePlan" }, "continue"]))
|
|
217
|
+
).toBe(true);
|
|
218
|
+
expect(
|
|
219
|
+
hasCompletingAction(
|
|
220
|
+
cta([{ type: "custom", function: "generatePlan", onError: ["continue"] }, "continue"])
|
|
221
|
+
)
|
|
222
|
+
).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -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
|
-
|
|
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,74 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { ScreenElementsSchema } from "../screens/types";
|
|
3
|
+
import { actionsCanComplete, hasCompletingAction } from "../screens/completingActions";
|
|
4
|
+
import { onboardingExample } from "../onboarding-example";
|
|
5
|
+
|
|
6
|
+
// The default onboarding is the payload every example app and the studio's
|
|
7
|
+
// seed data render, and CLAUDE.md's element procedure (step 1) requires keeping
|
|
8
|
+
// it in sync with the schema. Nothing enforced that: a `setVariable` action or
|
|
9
|
+
// element prop added to the example but not to the Zod union would ship a
|
|
10
|
+
// payload the runtime refuses to parse, and the only symptom would be a broken
|
|
11
|
+
// example app. This test closes that hole for the ComposableScreen steps.
|
|
12
|
+
describe("onboarding-example ComposableScreen payloads", () => {
|
|
13
|
+
const composableSteps = onboardingExample.steps.filter(
|
|
14
|
+
(s) => s.type === "ComposableScreen"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
it("has ComposableScreen steps to check", () => {
|
|
18
|
+
expect(composableSteps.length).toBeGreaterThan(0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
for (const step of composableSteps) {
|
|
22
|
+
it(`step "${step.name}" validates against ScreenElementsSchema`, () => {
|
|
23
|
+
const result = ScreenElementsSchema.safeParse(step.payload?.elements);
|
|
24
|
+
// Surface the actual zod issues rather than a bare `false`.
|
|
25
|
+
expect(result.success ? [] : result.error.issues).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The exported payload is also the documented `fallbackOnboarding`
|
|
32
|
+
* (`getting-started.mdx`), rendered by apps that pass no `customActions` at all
|
|
33
|
+
* — `ScreenHost`'s default is `{}`. So no step in it may depend on a registered
|
|
34
|
+
* handler for its way forward (review round 1, findings 1 and 7).
|
|
35
|
+
*
|
|
36
|
+
* Round 1 of #191 moved the hero button's only `"continue"` into the
|
|
37
|
+
* `onResolve` of a `{type:"custom", function:"trackCta"}` action. `trackCta` is
|
|
38
|
+
* registered nowhere in the SDK, so on the fallback path the primary CTA logged
|
|
39
|
+
* one line and did nothing: a step with no way off it.
|
|
40
|
+
*/
|
|
41
|
+
describe("onboarding-example ComposableScreen steps stay navigable", () => {
|
|
42
|
+
const composableSteps = onboardingExample.steps.filter(
|
|
43
|
+
(s) => s.type === "ComposableScreen"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
for (const step of composableSteps) {
|
|
47
|
+
it(`step "${step.name}" can be completed with no customActions registered`, () => {
|
|
48
|
+
expect(hasCompletingAction(step.payload?.elements)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Tree-wide is not enough for the PRIMARY CTA: the screen keeping SOME way
|
|
53
|
+
// forward elsewhere in the tree does not make a dead "Get Started" button
|
|
54
|
+
// acceptable. This asserts the button itself.
|
|
55
|
+
const findById = (nodes: unknown, id: string): any => {
|
|
56
|
+
if (!Array.isArray(nodes)) return undefined;
|
|
57
|
+
for (const node of nodes) {
|
|
58
|
+
if (node && typeof node === "object") {
|
|
59
|
+
const n = node as any;
|
|
60
|
+
if (n.id === id) return n;
|
|
61
|
+
const inner = findById(n.children, id);
|
|
62
|
+
if (inner) return inner;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
it("the hero CTA advances on a host with no customActions", () => {
|
|
69
|
+
const step = composableSteps[0];
|
|
70
|
+
const hero = findById(step.payload?.elements, "hero-button");
|
|
71
|
+
expect(hero, "hero-button not found in the example payload").toBeTruthy();
|
|
72
|
+
expect(actionsCanComplete(hero.props.actions)).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|