@seriousgaming/sdk 0.0.0-stage → 1.0.0-alpha.2
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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +33 -2
- package/lib/build/callbacks.d.ts +998 -0
- package/lib/build/callbacks.js +32 -0
- package/lib/build/context-merge.d.ts +59 -0
- package/lib/build/context-merge.js +118 -0
- package/lib/build/document.d.ts +36 -0
- package/lib/build/document.js +8 -0
- package/lib/build/encoding.d.ts +26 -0
- package/lib/build/encoding.js +78 -0
- package/lib/build/endpoints.d.ts +421 -0
- package/lib/build/endpoints.js +46 -0
- package/lib/build/hooks.d.ts +74 -0
- package/lib/build/hooks.js +1 -0
- package/lib/build/index.d.ts +18 -0
- package/lib/build/index.js +16 -0
- package/lib/build/llm.d.ts +166 -0
- package/lib/build/llm.js +17 -0
- package/lib/build/resource-schema.d.ts +1048 -0
- package/lib/build/resource-schema.js +7 -0
- package/lib/build/scheduling.d.ts +112 -0
- package/lib/build/scheduling.js +217 -0
- package/lib/build/seed.d.ts +51 -0
- package/lib/build/seed.js +89 -0
- package/lib/build/signatures.d.ts +372 -0
- package/lib/build/signatures.js +1 -0
- package/lib/build/speech.d.ts +102 -0
- package/lib/build/speech.js +11 -0
- package/lib/build/tick-validation.d.ts +23 -0
- package/lib/build/tick-validation.js +96 -0
- package/lib/build/timer.d.ts +74 -0
- package/lib/build/timer.js +1 -0
- package/lib/build/validators.d.ts +116 -0
- package/lib/build/validators.js +1 -0
- package/lib/commands.d.ts +357 -0
- package/lib/commands.js +14 -0
- package/lib/e2e.d.ts +238 -0
- package/lib/e2e.js +248 -0
- package/lib/projection.d.ts +266 -0
- package/lib/projection.js +23 -0
- package/lib/testing/index.d.ts +13 -0
- package/lib/testing/index.js +13 -0
- package/lib/testing/logic-args.d.ts +177 -0
- package/lib/testing/logic-args.js +229 -0
- package/lib/testing/stub-services.d.ts +41 -0
- package/lib/testing/stub-services.js +176 -0
- package/lib/ui/CrossTeamDataContext.d.ts +36 -0
- package/lib/ui/CrossTeamDataContext.js +32 -0
- package/lib/ui/PresentationContext.d.ts +72 -0
- package/lib/ui/PresentationContext.js +13 -0
- package/lib/ui/PresentationWrapper.d.ts +12 -0
- package/lib/ui/PresentationWrapper.js +78 -0
- package/lib/ui/SessionUserInterfaceCallbacksContext.d.ts +3 -0
- package/lib/ui/SessionUserInterfaceCallbacksContext.js +7 -0
- package/lib/ui/SessionUserInterfaceDataContext.d.ts +103 -0
- package/lib/ui/SessionUserInterfaceDataContext.js +17 -0
- package/lib/ui/SessionUserInterfaceHookFailuresContext.d.ts +44 -0
- package/lib/ui/SessionUserInterfaceHookFailuresContext.js +15 -0
- package/lib/ui/SessionUserInterfaceHostOverlaysContext.d.ts +23 -0
- package/lib/ui/SessionUserInterfaceHostOverlaysContext.js +23 -0
- package/lib/ui/SessionUserInterfaceLocaleContext.d.ts +11 -0
- package/lib/ui/SessionUserInterfaceLocaleContext.js +13 -0
- package/lib/ui/SessionUserInterfaceMetaContext.d.ts +39 -0
- package/lib/ui/SessionUserInterfaceMetaContext.js +13 -0
- package/lib/ui/SessionUserInterfaceParticipantsContext.d.ts +12 -0
- package/lib/ui/SessionUserInterfaceParticipantsContext.js +16 -0
- package/lib/ui/SessionUserInterfaceTeamConfigurationContext.d.ts +53 -0
- package/lib/ui/SessionUserInterfaceTeamConfigurationContext.js +23 -0
- package/lib/ui/SessionUserInterfaceTeamLinksContext.d.ts +56 -0
- package/lib/ui/SessionUserInterfaceTeamLinksContext.js +12 -0
- package/lib/ui/SessionUserInterfaceTeamsContext.d.ts +13 -0
- package/lib/ui/SessionUserInterfaceTeamsContext.js +13 -0
- package/lib/ui/SessionUserInterfaceThemeContext.d.ts +9 -0
- package/lib/ui/SessionUserInterfaceThemeContext.js +7 -0
- package/lib/ui/SessionUserInterfaceThemePreferenceContext.d.ts +3 -0
- package/lib/ui/SessionUserInterfaceThemePreferenceContext.js +7 -0
- package/lib/ui/SessionUserInterfaceWalkthroughLinkContext.d.ts +42 -0
- package/lib/ui/SessionUserInterfaceWalkthroughLinkContext.js +26 -0
- package/lib/ui/SessionUserInterfaceWrapper.d.ts +8 -0
- package/lib/ui/SessionUserInterfaceWrapper.js +321 -0
- package/lib/ui/SettingsEditorCallbacksContext.d.ts +3 -0
- package/lib/ui/SettingsEditorCallbacksContext.js +7 -0
- package/lib/ui/SettingsEditorContext.d.ts +33 -0
- package/lib/ui/SettingsEditorContext.js +16 -0
- package/lib/ui/SettingsEditorLocaleContext.d.ts +13 -0
- package/lib/ui/SettingsEditorLocaleContext.js +15 -0
- package/lib/ui/SettingsEditorThemeContext.d.ts +9 -0
- package/lib/ui/SettingsEditorThemeContext.js +7 -0
- package/lib/ui/SettingsEditorThemePreferenceContext.d.ts +3 -0
- package/lib/ui/SettingsEditorThemePreferenceContext.js +7 -0
- package/lib/ui/SettingsEditorWrapper.d.ts +13 -0
- package/lib/ui/SettingsEditorWrapper.js +74 -0
- package/lib/ui/UserInterfaceCallbacksContext.d.ts +3 -0
- package/lib/ui/UserInterfaceCallbacksContext.js +7 -0
- package/lib/ui/UserInterfaceDataContext.d.ts +78 -0
- package/lib/ui/UserInterfaceDataContext.js +11 -0
- package/lib/ui/UserInterfaceLocaleContext.d.ts +13 -0
- package/lib/ui/UserInterfaceLocaleContext.js +15 -0
- package/lib/ui/UserInterfaceOwnTeamContext.d.ts +25 -0
- package/lib/ui/UserInterfaceOwnTeamContext.js +26 -0
- package/lib/ui/UserInterfaceOwnTeamJoinLinkContext.d.ts +52 -0
- package/lib/ui/UserInterfaceOwnTeamJoinLinkContext.js +13 -0
- package/lib/ui/UserInterfaceParticipantContext.d.ts +16 -0
- package/lib/ui/UserInterfaceParticipantContext.js +24 -0
- package/lib/ui/UserInterfaceParticipantsContext.d.ts +12 -0
- package/lib/ui/UserInterfaceParticipantsContext.js +13 -0
- package/lib/ui/UserInterfaceRunKindContext.d.ts +31 -0
- package/lib/ui/UserInterfaceRunKindContext.js +31 -0
- package/lib/ui/UserInterfaceTeamsContext.d.ts +12 -0
- package/lib/ui/UserInterfaceTeamsContext.js +13 -0
- package/lib/ui/UserInterfaceThemeContext.d.ts +9 -0
- package/lib/ui/UserInterfaceThemeContext.js +7 -0
- package/lib/ui/UserInterfaceThemePreferenceContext.d.ts +3 -0
- package/lib/ui/UserInterfaceThemePreferenceContext.js +7 -0
- package/lib/ui/UserInterfaceTimerContext.d.ts +10 -0
- package/lib/ui/UserInterfaceTimerContext.js +12 -0
- package/lib/ui/UserInterfaceValidationContext.d.ts +25 -0
- package/lib/ui/UserInterfaceValidationContext.js +14 -0
- package/lib/ui/UserInterfaceViewerRoleContext.d.ts +14 -0
- package/lib/ui/UserInterfaceViewerRoleContext.js +17 -0
- package/lib/ui/UserInterfaceWrapper.d.ts +8 -0
- package/lib/ui/UserInterfaceWrapper.js +219 -0
- package/lib/ui/expectedParentOrigin.d.ts +10 -0
- package/lib/ui/expectedParentOrigin.js +32 -0
- package/lib/ui/index.d.ts +50 -0
- package/lib/ui/index.js +52 -0
- package/lib/ui/internal/SurfaceGate.d.ts +19 -0
- package/lib/ui/internal/SurfaceGate.js +17 -0
- package/lib/ui/internal/SurfaceScope.d.ts +17 -0
- package/lib/ui/internal/SurfaceScope.js +16 -0
- package/lib/ui/internal/createContexts.d.ts +50 -0
- package/lib/ui/internal/createContexts.js +32 -0
- package/lib/ui/internal/document-attributes.d.ts +9 -0
- package/lib/ui/internal/document-attributes.js +87 -0
- package/lib/ui/internal/surface-timer.d.ts +3 -0
- package/lib/ui/internal/surface-timer.js +11 -0
- package/lib/ui/internal/useLatestRef.d.ts +7 -0
- package/lib/ui/internal/useLatestRef.js +11 -0
- package/lib/ui/internal/useOptimisticMerge.d.ts +19 -0
- package/lib/ui/internal/useOptimisticMerge.js +28 -0
- package/lib/ui/internal/useSurfaceControls.d.ts +52 -0
- package/lib/ui/internal/useSurfaceControls.js +19 -0
- package/lib/ui/internal/useTypedPastState.d.ts +17 -0
- package/lib/ui/internal/useTypedPastState.js +17 -0
- package/lib/ui/mutation-commit.d.ts +32 -0
- package/lib/ui/mutation-commit.js +1 -0
- package/lib/ui/mutation-outcome.d.ts +66 -0
- package/lib/ui/mutation-outcome.js +49 -0
- package/lib/ui/request-id.d.ts +18 -0
- package/lib/ui/request-id.js +44 -0
- package/lib/ui/testing.d.ts +365 -0
- package/lib/ui/testing.js +572 -0
- package/lib/ui/tick-snapshot.d.ts +28 -0
- package/lib/ui/tick-snapshot.js +34 -0
- package/lib/ui/ui-protocol.d.ts +799 -0
- package/lib/ui/ui-protocol.js +50 -0
- package/lib/ui/useAsset.d.ts +80 -0
- package/lib/ui/useAsset.js +139 -0
- package/lib/ui/useEndpointCallbacks.d.ts +31 -0
- package/lib/ui/useEndpointCallbacks.js +68 -0
- package/lib/ui/useHostChannel.d.ts +90 -0
- package/lib/ui/useHostChannel.js +338 -0
- package/lib/ui/useMutationReporter.d.ts +100 -0
- package/lib/ui/useMutationReporter.js +97 -0
- package/lib/ui/usePastState.d.ts +39 -0
- package/lib/ui/usePastState.js +63 -0
- package/lib/ui/useViewerStorage.d.ts +54 -0
- package/lib/ui/useViewerStorage.js +141 -0
- package/package.json +89 -3
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { type RenderResult } from '@testing-library/react';
|
|
2
|
+
import type { Participant, SettingsEditorCallbacks } from '../build/callbacks.js';
|
|
3
|
+
import type { SessionUserInterfaceCallbacks } from '../build/callbacks.js';
|
|
4
|
+
import type { ThemePreference, UserInterfaceCallbacks } from '../build/callbacks.js';
|
|
5
|
+
import { type ContextUpdate } from '../build/context-merge.js';
|
|
6
|
+
import type { TimerState } from '../build/timer.js';
|
|
7
|
+
import type { ValidationRejection } from '../build/validators.js';
|
|
8
|
+
import type { SessionData, SharedState, TeamState } from './SessionUserInterfaceDataContext.js';
|
|
9
|
+
import type { SessionHookFailure } from './SessionUserInterfaceHookFailuresContext.js';
|
|
10
|
+
import type { HostOverlay } from './SessionUserInterfaceHostOverlaysContext.js';
|
|
11
|
+
import type { SessionUserInterfaceLocale } from './SessionUserInterfaceLocaleContext.js';
|
|
12
|
+
import type { SessionMeta } from './SessionUserInterfaceMetaContext.js';
|
|
13
|
+
import type { TeamConfiguration } from './SessionUserInterfaceTeamConfigurationContext.js';
|
|
14
|
+
import type { TeamLinks } from './SessionUserInterfaceTeamLinksContext.js';
|
|
15
|
+
import type { TeamInfo } from './SessionUserInterfaceTeamsContext.js';
|
|
16
|
+
import type { SessionUserInterfaceTheme } from './SessionUserInterfaceThemeContext.js';
|
|
17
|
+
import type { WalkthroughLink } from './SessionUserInterfaceWalkthroughLinkContext.js';
|
|
18
|
+
import type { SettingsEditorLocale } from './SettingsEditorLocaleContext.js';
|
|
19
|
+
import type { SettingsEditorTheme } from './SettingsEditorThemeContext.js';
|
|
20
|
+
import { type SetDataOptions } from './UserInterfaceDataContext.js';
|
|
21
|
+
import type { UserInterfaceLocale } from './UserInterfaceLocaleContext.js';
|
|
22
|
+
import { type OwnTeamJoinLink } from './UserInterfaceOwnTeamJoinLinkContext.js';
|
|
23
|
+
import type { RunKind } from './UserInterfaceRunKindContext.js';
|
|
24
|
+
import type { UserInterfaceTheme } from './UserInterfaceThemeContext.js';
|
|
25
|
+
import type { ViewerRole } from './UserInterfaceViewerRoleContext.js';
|
|
26
|
+
/**
|
|
27
|
+
* Creates a valid UserInterfaceTheme for use in tests.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Basic usage — light mode with default MUI palette
|
|
31
|
+
* <UserInterfaceThemeContext.Provider value={createMockTheme()}>
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Override mode or colours
|
|
35
|
+
* <UserInterfaceThemeContext.Provider value={createMockTheme({ mode: 'dark' })}>
|
|
36
|
+
*/
|
|
37
|
+
export declare function createMockTheme(overrides?: Partial<UserInterfaceTheme>): UserInterfaceTheme;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a valid SettingsEditorTheme for use in tests.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* <SettingsEditorThemeContext.Provider value={createMockSettingsEditorTheme()}>
|
|
43
|
+
*/
|
|
44
|
+
export declare function createMockSettingsEditorTheme(overrides?: Partial<SettingsEditorTheme>): SettingsEditorTheme;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a valid SessionUserInterfaceTheme for use in tests.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createMockSessionTheme(overrides?: Partial<SessionUserInterfaceTheme>): SessionUserInterfaceTheme;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a valid Participant for use in tests — the caller's own
|
|
51
|
+
* identity, as returned by `useUserInterfaceParticipant()`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // The caller, with a custom name
|
|
55
|
+
* renderUserInterface(<App />, { participant: createMockParticipant({ name: 'Alice' }) });
|
|
56
|
+
*/
|
|
57
|
+
export declare function createMockParticipant(overrides?: Partial<Participant>): Participant;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a roster of participants for use in tests — the list returned by
|
|
60
|
+
* `useUserInterfaceParticipants()` (and the session equivalent, which
|
|
61
|
+
* shares the same shape). Ids, names, and indices follow the runtime's
|
|
62
|
+
* conventions (`id` is `String(index + 1)`, `name` is `Participant N`), and
|
|
63
|
+
* every entry is `connected` by default.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // A team of three, all online
|
|
67
|
+
* renderUserInterface(<App />, { participants: createMockParticipants(3) });
|
|
68
|
+
*/
|
|
69
|
+
export declare function createMockParticipants(count?: number, teamId?: string): Participant[];
|
|
70
|
+
/**
|
|
71
|
+
* What a fixture may put in a context typed `T`: any capability `T` holds,
|
|
72
|
+
* each optional, and nothing else, so a capability of the wrong scope fails to
|
|
73
|
+
* compile. Left at its default, `T` accepts any object, as before.
|
|
74
|
+
*/
|
|
75
|
+
type FixtureContext<T> = Record<string, unknown> extends T ? object : Partial<T>;
|
|
76
|
+
/**
|
|
77
|
+
* A `TeamState` for a session-surface fixture, with the fields a test rarely
|
|
78
|
+
* cares about filled in.
|
|
79
|
+
*
|
|
80
|
+
* `revision` is the reason this exists. It is required, because the wrapper
|
|
81
|
+
* needs a baseline to compare an `updateTeamState` delta against, but no
|
|
82
|
+
* surface ever reads it, so making every fixture carry one would be friction
|
|
83
|
+
* for a field with no meaning to the test.
|
|
84
|
+
*
|
|
85
|
+
* Type it with the surface's generated `TeamContext`, and a shared capability
|
|
86
|
+
* left on a team's fixture fails to compile, as reading one through a team
|
|
87
|
+
* does in the surface. Capabilities the fixture leaves out are absent.
|
|
88
|
+
*
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import type { TeamContext } from '../types';
|
|
91
|
+
*
|
|
92
|
+
* createMockTeamState<TeamContext>({ context: { price: { Price: 5 } } });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function createMockTeamState<T extends object = Record<string, unknown>>(overrides?: Partial<Omit<TeamState<T>, 'context'>> & {
|
|
96
|
+
context?: FixtureContext<T>;
|
|
97
|
+
}): TeamState<T>;
|
|
98
|
+
/**
|
|
99
|
+
* A `SharedState` for a session-surface fixture: the shared store's context,
|
|
100
|
+
* with a `revision` filled in for the same reason {@link createMockTeamState}
|
|
101
|
+
* fills one. Type it with the surface's generated `SharedContext`.
|
|
102
|
+
*
|
|
103
|
+
* ```typescript
|
|
104
|
+
* createMockSharedState<SharedContext>({ context: { market: { Price: 5 } } });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function createMockSharedState<T extends object = Record<string, unknown>>(overrides?: Partial<Omit<SharedState<T>, 'context'>> & {
|
|
108
|
+
context?: FixtureContext<T>;
|
|
109
|
+
}): SharedState<T>;
|
|
110
|
+
/**
|
|
111
|
+
* A `setData` for a stateful test harness that writes the way the host does:
|
|
112
|
+
* objects merge recursively, arrays, scalars and `null` replace whole, and
|
|
113
|
+
* any `deletes` are removed after the merge.
|
|
114
|
+
*
|
|
115
|
+
* A hand-rolled `{ ...previous, ...patch }` does not. It replaces a whole
|
|
116
|
+
* capability with whatever the patch names, so a minimal write (the shape
|
|
117
|
+
* every concurrency-safe surface sends) appears to wipe every field it did
|
|
118
|
+
* not mention. Tests then fail on writes that are correct in production, or
|
|
119
|
+
* worse, pass on writes that are not (#520).
|
|
120
|
+
*
|
|
121
|
+
* ```tsx
|
|
122
|
+
* const [data, setLocal] = useState(mockData);
|
|
123
|
+
* const setData = mergingSetData(setLocal);
|
|
124
|
+
* setData({}, { deletes: [`pinboard.Notes.${noteId}`] });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* Wrap it in a `vi.fn()` when the test also asserts on the payload.
|
|
128
|
+
*/
|
|
129
|
+
export declare function mergingSetData<T extends object>(setLocal: (updater: (previous: T) => T) => void): (patch: Record<string, unknown>, options?: SetDataOptions) => void;
|
|
130
|
+
export type RenderUserInterfaceOptions = {
|
|
131
|
+
/**
|
|
132
|
+
* The surface's context. Typed as `object` rather than
|
|
133
|
+
* `Record<string, unknown>` for the same reason {@link mergingSetData} is:
|
|
134
|
+
* a generated `Context` is an interface, an interface has no implicit index
|
|
135
|
+
* signature, and the tighter type would reject the one value every caller
|
|
136
|
+
* actually holds.
|
|
137
|
+
*/
|
|
138
|
+
data?: object;
|
|
139
|
+
/** The surface's settings, keyed by settings identifier (§8). */
|
|
140
|
+
settings?: unknown;
|
|
141
|
+
/** Ticks completed, surfaced through `useUserInterfaceData().completedTicks`. */
|
|
142
|
+
completedTicks?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Whether a round is being processed, surfaced through
|
|
145
|
+
* `useUserInterfaceData().isRoundProcessing`. Defaults to false, which is
|
|
146
|
+
* the state a surface spends nearly all its time in.
|
|
147
|
+
*/
|
|
148
|
+
isRoundProcessing?: boolean;
|
|
149
|
+
setData?: (update: Partial<Record<string, unknown>>) => void;
|
|
150
|
+
/**
|
|
151
|
+
* The key the host would send on `init` (§12.2), which `useViewerStorage`
|
|
152
|
+
* namespaces by. Defaults to a fixed test key; give two renders different
|
|
153
|
+
* keys to show their stored values stay apart.
|
|
154
|
+
*/
|
|
155
|
+
sessionKey?: string;
|
|
156
|
+
theme?: UserInterfaceTheme;
|
|
157
|
+
themePreference?: ThemePreference;
|
|
158
|
+
locale?: UserInterfaceLocale;
|
|
159
|
+
/**
|
|
160
|
+
* Viewer role for the render. Defaults to `'participant'`. Pass
|
|
161
|
+
* `'observer'` to exercise the observation path, where `participant`
|
|
162
|
+
* defaults to `null` (an observer has no caller identity).
|
|
163
|
+
*/
|
|
164
|
+
viewerRole?: ViewerRole;
|
|
165
|
+
/**
|
|
166
|
+
* Which kind of run this surface belongs to, read by `useRunKind()`.
|
|
167
|
+
* Defaults to `'session'`. Pass `'walkthrough'` to exercise the
|
|
168
|
+
* demonstration path (§5.7).
|
|
169
|
+
*/
|
|
170
|
+
runKind?: RunKind;
|
|
171
|
+
participant?: Participant | null;
|
|
172
|
+
participants?: Participant[];
|
|
173
|
+
teams?: TeamInfo[];
|
|
174
|
+
/**
|
|
175
|
+
* The team the surface renders, read by `useUserInterfaceOwnTeam()`. Defaults to the
|
|
176
|
+
* participant's team resolved against `teams`, so a test that already sets
|
|
177
|
+
* both needs nothing extra; set it explicitly to cover an observer, which
|
|
178
|
+
* has no participant to derive it from.
|
|
179
|
+
*/
|
|
180
|
+
ownTeam?: TeamInfo | null;
|
|
181
|
+
/**
|
|
182
|
+
* How to join the rendered team, read by `useUserInterfaceOwnTeamJoinLink()`. Defaults to
|
|
183
|
+
* `null`, matching a surface whose host has not delivered it yet.
|
|
184
|
+
*/
|
|
185
|
+
ownTeamJoinLink?: OwnTeamJoinLink | null;
|
|
186
|
+
timer?: TimerState;
|
|
187
|
+
/**
|
|
188
|
+
* Validator rejections the host has returned for the most recent write,
|
|
189
|
+
* read by `useUserInterfaceValidationRejections()`. Defaults to empty, so a
|
|
190
|
+
* surface that renders them is renderable without saying anything; pass a
|
|
191
|
+
* list to exercise what it shows when a write is refused.
|
|
192
|
+
*/
|
|
193
|
+
validationRejections?: ValidationRejection[];
|
|
194
|
+
/** Spy for the rejection channel's `clearRejections`. Defaults to a no-op. */
|
|
195
|
+
clearRejections?: () => void;
|
|
196
|
+
callbacks?: Partial<UserInterfaceCallbacks>;
|
|
197
|
+
blobPrefix?: string;
|
|
198
|
+
scenarioAssetPrefix?: string;
|
|
199
|
+
sharedAssetPrefix?: string;
|
|
200
|
+
};
|
|
201
|
+
export type RenderUserInterfaceResult = RenderResult & {
|
|
202
|
+
setData: (update: Partial<Record<string, unknown>>) => void;
|
|
203
|
+
callbacks: UserInterfaceCallbacks;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Renders a component wrapped in all UserInterface context providers with
|
|
207
|
+
* sensible defaults. Override any context value via the options object.
|
|
208
|
+
*
|
|
209
|
+
* Returns the standard `@testing-library/react` render result plus the mock
|
|
210
|
+
* `setData` and resolved `callbacks` for assertions.
|
|
211
|
+
*
|
|
212
|
+
* Callbacks you do not supply default to no-ops rather than spies, so pass your
|
|
213
|
+
* own `vi.fn()` for any you intend to assert on.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```tsx
|
|
217
|
+
* const requestTick = vi.fn();
|
|
218
|
+
* const { setData } = renderUserInterface(<App />, {
|
|
219
|
+
* data: { 'com.example.cap': { Score: 42 } },
|
|
220
|
+
* settings: { scoring: { MaxScore: 100 } },
|
|
221
|
+
* callbacks: { requestTick },
|
|
222
|
+
* });
|
|
223
|
+
*
|
|
224
|
+
* fireEvent.click(screen.getByText('Submit'));
|
|
225
|
+
* expect(requestTick).toHaveBeenCalled();
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export declare function renderUserInterface(ui: React.ReactElement, options?: RenderUserInterfaceOptions): RenderUserInterfaceResult;
|
|
229
|
+
export type RenderSettingsEditorOptions = {
|
|
230
|
+
/**
|
|
231
|
+
* The settings the editor is seeded with, keyed by settings identifier:
|
|
232
|
+
* typically the slot's generated `defaultSettings`.
|
|
233
|
+
*/
|
|
234
|
+
settings?: object;
|
|
235
|
+
updateSettings?: (update: Partial<Record<string, unknown>>) => Promise<void> | void;
|
|
236
|
+
/** Defaults to the keys of `settings`, as the host's `setSettings` makes it. */
|
|
237
|
+
configures?: string[];
|
|
238
|
+
/**
|
|
239
|
+
* The key the host would send on `init` (§12.2), which `useViewerStorage`
|
|
240
|
+
* namespaces by. Defaults to a fixed test key; give two renders different
|
|
241
|
+
* keys to show their stored values stay apart.
|
|
242
|
+
*/
|
|
243
|
+
sessionKey?: string;
|
|
244
|
+
theme?: SettingsEditorTheme;
|
|
245
|
+
themePreference?: ThemePreference;
|
|
246
|
+
locale?: SettingsEditorLocale;
|
|
247
|
+
callbacks?: Partial<SettingsEditorCallbacks>;
|
|
248
|
+
blobPrefix?: string;
|
|
249
|
+
scenarioAssetPrefix?: string;
|
|
250
|
+
sharedAssetPrefix?: string;
|
|
251
|
+
};
|
|
252
|
+
export type RenderSettingsEditorResult = RenderResult & {
|
|
253
|
+
updateSettings: (update: Partial<Record<string, unknown>>) => Promise<void>;
|
|
254
|
+
callbacks: SettingsEditorCallbacks;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Renders a component wrapped in every settings editor context provider: the
|
|
258
|
+
* `setup` slot and the `scenario_editor` slot share them.
|
|
259
|
+
*
|
|
260
|
+
* `updateSettings` defaults to a no-op rather than a spy, so pass your own
|
|
261
|
+
* `vi.fn()` to assert on it.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* const updateSettings = vi.fn();
|
|
266
|
+
* renderSettingsEditor(<App />, {
|
|
267
|
+
* settings: { engine: { MaxPlayers: 10 } },
|
|
268
|
+
* updateSettings,
|
|
269
|
+
* });
|
|
270
|
+
*
|
|
271
|
+
* fireEvent.change(screen.getByLabelText('Max Players'), { target: { value: '20' } });
|
|
272
|
+
* expect(updateSettings).toHaveBeenCalled();
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export declare function renderSettingsEditor(ui: React.ReactElement, options?: RenderSettingsEditorOptions): RenderSettingsEditorResult;
|
|
276
|
+
/** The team context a session data type holds. */
|
|
277
|
+
type TeamContextOf<TData> = TData extends SessionData<infer Team, object> ? Team : object;
|
|
278
|
+
/**
|
|
279
|
+
* Options for {@link renderSessionUserInterface}. `TData` is the surface's
|
|
280
|
+
* generated `SessionData`, and types `sessionData` and `setData` to match.
|
|
281
|
+
*/
|
|
282
|
+
export type RenderSessionUserInterfaceOptions<TData extends SessionData<object, object> = SessionData<object, object>> = {
|
|
283
|
+
/** Either half may be omitted, and defaults to empty. */
|
|
284
|
+
sessionData?: Partial<TData>;
|
|
285
|
+
/** The surface's settings, keyed by settings identifier (§8). */
|
|
286
|
+
settings?: unknown;
|
|
287
|
+
/**
|
|
288
|
+
* Receives what the surface's `setData` was called with: `(teamId, update,
|
|
289
|
+
* options?)` for a team write, `(update, options?)` for a shared one.
|
|
290
|
+
*/
|
|
291
|
+
setData?: SessionSetDataMock<TData>;
|
|
292
|
+
/**
|
|
293
|
+
* The key the host would send on `init` (§12.2), which `useViewerStorage`
|
|
294
|
+
* namespaces by. Defaults to a fixed test key; give two renders different
|
|
295
|
+
* keys to show their stored values stay apart.
|
|
296
|
+
*/
|
|
297
|
+
sessionKey?: string;
|
|
298
|
+
theme?: SessionUserInterfaceTheme;
|
|
299
|
+
themePreference?: ThemePreference;
|
|
300
|
+
locale?: SessionUserInterfaceLocale;
|
|
301
|
+
participants?: Participant[];
|
|
302
|
+
teams?: TeamInfo[];
|
|
303
|
+
teamConfiguration?: TeamConfiguration;
|
|
304
|
+
sessionMeta?: SessionMeta;
|
|
305
|
+
teamLinks?: TeamLinks[];
|
|
306
|
+
/**
|
|
307
|
+
* Which kind of run this session surface belongs to, read by `useRunKind()`.
|
|
308
|
+
* Defaults to `'session'`.
|
|
309
|
+
*/
|
|
310
|
+
runKind?: RunKind;
|
|
311
|
+
/**
|
|
312
|
+
* Where to open the walkthrough, as
|
|
313
|
+
* `useSessionUserInterfaceWalkthroughLink()` reports it. Defaults to
|
|
314
|
+
* `null`, the moment before the host has said, so a test covering the
|
|
315
|
+
* control has to supply one.
|
|
316
|
+
*/
|
|
317
|
+
walkthroughLink?: WalkthroughLink | null;
|
|
318
|
+
/**
|
|
319
|
+
* Host overlays this host offers, as
|
|
320
|
+
* `useSessionUserInterfaceHostOverlays()` reports them. Defaults to none,
|
|
321
|
+
* matching a host that delegates nothing — a test covering a guide button
|
|
322
|
+
* has to say so, which is also what stops a surface accidentally passing
|
|
323
|
+
* with a control the host would never light up.
|
|
324
|
+
*/
|
|
325
|
+
hostOverlays?: HostOverlay[];
|
|
326
|
+
/**
|
|
327
|
+
* Hook chains that threw, as `useSessionUserInterfaceHookFailures()` reports
|
|
328
|
+
* them. The context is required rather than defaulted, so a surface reading
|
|
329
|
+
* it throws without this provider whatever the test passes (#366).
|
|
330
|
+
*/
|
|
331
|
+
hookFailures?: SessionHookFailure[];
|
|
332
|
+
/** Called by the surface's `clearFailures`; defaults to a no-op. */
|
|
333
|
+
clearHookFailures?: () => void;
|
|
334
|
+
callbacks?: Partial<SessionUserInterfaceCallbacks>;
|
|
335
|
+
blobPrefix?: string;
|
|
336
|
+
scenarioAssetPrefix?: string;
|
|
337
|
+
sharedAssetPrefix?: string;
|
|
338
|
+
};
|
|
339
|
+
/** What a session surface's `setData` mock receives, typed by the session data. */
|
|
340
|
+
type SessionSetDataMock<TData extends SessionData<object, object>> = (teamId: string, update: ContextUpdate<TeamContextOf<TData>>, options?: SetDataOptions) => void;
|
|
341
|
+
export type RenderSessionUserInterfaceResult<TData extends SessionData<object, object> = SessionData<object, object>> = RenderResult & {
|
|
342
|
+
setData: SessionSetDataMock<TData>;
|
|
343
|
+
callbacks: SessionUserInterfaceCallbacks;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Renders a component wrapped in all SessionUserInterface context providers.
|
|
347
|
+
*
|
|
348
|
+
* Callbacks you do not supply default to no-ops rather than spies, so pass your
|
|
349
|
+
* own `vi.fn()` for any you intend to assert on.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```tsx
|
|
353
|
+
* const resetGame = vi.fn();
|
|
354
|
+
* renderSessionUserInterface(<SessionDashboard />, {
|
|
355
|
+
* sessionData: { teams: { 'team-1': createMockTeamState() } },
|
|
356
|
+
* teams: [{ teamId: 'team-1', index: 0, name: 'Team 1' }],
|
|
357
|
+
* callbacks: { resetGame },
|
|
358
|
+
* });
|
|
359
|
+
*
|
|
360
|
+
* fireEvent.click(screen.getByText('Reset All'));
|
|
361
|
+
* expect(resetGame).toHaveBeenCalled();
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
export declare function renderSessionUserInterface<TData extends SessionData<object, object> = SessionData<object, object>>(ui: React.ReactElement, options?: RenderSessionUserInterfaceOptions<NoInfer<TData>>): RenderSessionUserInterfaceResult<TData>;
|
|
365
|
+
export {};
|