@assistant-ui/react-native 0.1.29 → 0.1.31
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/index.d.ts +2 -2
- package/dist/primitives/actionBar/ActionBarCopy.d.ts +1 -8
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.d.ts +1 -6
- package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts +1 -5
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts +1 -5
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.d.ts +1 -6
- package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
- package/dist/primitives/actionBar.d.ts +0 -2
- package/dist/primitives/attachment/AttachmentName.d.ts +0 -1
- package/dist/primitives/attachment/AttachmentName.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentName.js.map +1 -1
- package/dist/primitives/attachment/AttachmentRemove.d.ts +1 -5
- package/dist/primitives/attachment/AttachmentRemove.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentRoot.d.ts +1 -5
- package/dist/primitives/attachment/AttachmentRoot.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.d.ts +0 -1
- package/dist/primitives/attachment/AttachmentThumb.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
- package/dist/primitives/attachment.d.ts +0 -2
- package/dist/primitives/branchPicker/BranchPickerCount.d.ts +0 -1
- package/dist/primitives/branchPicker/BranchPickerCount.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts +1 -6
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.d.ts +0 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts +1 -6
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
- package/dist/primitives/branchPicker.d.ts +0 -2
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts +1 -5
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.d.ts +1 -5
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.d.ts.map +1 -1
- package/dist/primitives/chainOfThought.d.ts +0 -2
- package/dist/primitives/composer/ComposerAddAttachment.d.ts +1 -6
- package/dist/primitives/composer/ComposerAddAttachment.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachments.d.ts +3 -16
- package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts +1 -6
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts +1 -8
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +15 -2
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerRoot.d.ts +1 -5
- package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerSend.d.ts +1 -6
- package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
- package/dist/primitives/composer.d.ts +3 -5
- package/dist/primitives/composer.js.map +1 -1
- package/dist/primitives/error/ErrorMessage.d.ts +1 -5
- package/dist/primitives/error/ErrorMessage.d.ts.map +1 -1
- package/dist/primitives/error/ErrorMessage.js.map +1 -1
- package/dist/primitives/error/ErrorRoot.d.ts +1 -5
- package/dist/primitives/error/ErrorRoot.d.ts.map +1 -1
- package/dist/primitives/error/index.d.ts +0 -2
- package/dist/primitives/message/MessageAttachments.d.ts +2 -9
- package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/primitives/message/MessageContent.d.ts +1 -10
- package/dist/primitives/message/MessageContent.d.ts.map +1 -1
- package/dist/primitives/message/MessageIf.d.ts +1 -8
- package/dist/primitives/message/MessageIf.d.ts.map +1 -1
- package/dist/primitives/message/MessageIf.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts +0 -1
- package/dist/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/primitives/message/MessageRoot.d.ts +1 -5
- package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
- package/dist/primitives/message.d.ts +3 -5
- package/dist/primitives/message.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.d.ts +1 -5
- package/dist/primitives/suggestion/SuggestionDescription.d.ts.map +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.d.ts +1 -5
- package/dist/primitives/suggestion/SuggestionTitle.d.ts.map +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.d.ts +1 -8
- package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -1
- package/dist/primitives/suggestion.d.ts +0 -2
- package/dist/primitives/thread/ThreadEmpty.d.ts +1 -4
- package/dist/primitives/thread/ThreadEmpty.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadIf.d.ts +1 -6
- package/dist/primitives/thread/ThreadIf.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadIf.js.map +1 -1
- package/dist/primitives/thread/ThreadMessages.d.ts +14 -12
- package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadMessages.js +376 -33
- package/dist/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/primitives/thread/ThreadRoot.d.ts +1 -5
- package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts +3 -10
- package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
- package/dist/primitives/thread.d.ts +3 -5
- package/dist/primitives/thread.js +3 -2
- package/dist/primitives/thread.js.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.d.ts +1 -5
- package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.d.ts +1 -5
- package/dist/primitives/threadList/ThreadListNew.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListRoot.d.ts +1 -5
- package/dist/primitives/threadList/ThreadListRoot.d.ts.map +1 -1
- package/dist/primitives/threadList.d.ts +0 -2
- package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts +1 -5
- package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts +1 -5
- package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.d.ts +1 -5
- package/dist/primitives/threadListItem/ThreadListItemRoot.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTrigger.d.ts +1 -5
- package/dist/primitives/threadListItem/ThreadListItemTrigger.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts +1 -5
- package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts.map +1 -1
- package/dist/primitives/threadListItem.d.ts +0 -2
- package/package.json +9 -9
- package/src/index.ts +2 -0
- package/src/primitives/composer/ComposerAttachments.tsx +3 -15
- package/src/primitives/composer/ComposerInput.test.tsx +106 -8
- package/src/primitives/composer/ComposerInput.tsx +21 -2
- package/src/primitives/composer.ts +2 -0
- package/src/primitives/message/MessageAttachments.tsx +3 -8
- package/src/primitives/message.ts +2 -0
- package/src/primitives/thread/ThreadMessages.test.tsx +444 -10
- package/src/primitives/thread/ThreadMessages.tsx +320 -29
- package/src/primitives/thread.ts +2 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { act } from "react";
|
|
1
|
+
import { act, createRef } from "react";
|
|
2
2
|
import { createRoot, type Root } from "react-dom/client";
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
import {
|
|
4
|
+
import type { FlatList } from "react-native";
|
|
5
|
+
import type { ThreadMessage } from "@assistant-ui/core";
|
|
6
|
+
import { ThreadMessages, ThreadMessagesFlatList } from "./ThreadMessages";
|
|
5
7
|
|
|
6
8
|
type Msg = { id: string; role: string };
|
|
7
9
|
|
|
@@ -11,16 +13,96 @@ const h = vi.hoisted(() => ({
|
|
|
11
13
|
message: { role: "user" as string, composer: { isEditing: false } },
|
|
12
14
|
},
|
|
13
15
|
itemState: { role: "user" } as { role: string },
|
|
16
|
+
events: {} as Record<string, Set<() => void>>,
|
|
17
|
+
flatListProps: null as Record<string, unknown> | null,
|
|
18
|
+
scrollToEnd: vi.fn(),
|
|
14
19
|
}));
|
|
15
20
|
|
|
16
|
-
vi.mock("
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
vi.mock("react-native", async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import("react-native")>();
|
|
23
|
+
const React = await import("react");
|
|
24
|
+
|
|
25
|
+
const FlatListMock = React.forwardRef(function FlatListMock(
|
|
26
|
+
props: Record<string, unknown>,
|
|
27
|
+
ref,
|
|
28
|
+
) {
|
|
29
|
+
h.flatListProps = props;
|
|
30
|
+
|
|
31
|
+
React.useImperativeHandle(ref, () => ({
|
|
32
|
+
scrollToEnd: h.scrollToEnd,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const data = (props.data as unknown[]) ?? [];
|
|
36
|
+
const renderItem = props.renderItem as
|
|
37
|
+
| ((value: {
|
|
38
|
+
item: unknown;
|
|
39
|
+
index: number;
|
|
40
|
+
separators: {
|
|
41
|
+
highlight: () => void;
|
|
42
|
+
unhighlight: () => void;
|
|
43
|
+
updateProps: () => void;
|
|
44
|
+
};
|
|
45
|
+
}) => React.ReactNode)
|
|
46
|
+
| undefined;
|
|
47
|
+
const keyExtractor = props.keyExtractor as
|
|
48
|
+
| ((item: unknown, index: number) => string)
|
|
49
|
+
| undefined;
|
|
50
|
+
|
|
51
|
+
return React.createElement(
|
|
52
|
+
"div",
|
|
53
|
+
{ "data-testid": "flatlist" },
|
|
54
|
+
data.map((item, index) =>
|
|
55
|
+
React.createElement(
|
|
56
|
+
"div",
|
|
57
|
+
{ key: keyExtractor?.(item, index) ?? index },
|
|
58
|
+
renderItem?.({
|
|
59
|
+
item,
|
|
60
|
+
index,
|
|
61
|
+
separators: {
|
|
62
|
+
highlight: vi.fn(),
|
|
63
|
+
unhighlight: vi.fn(),
|
|
64
|
+
updateProps: vi.fn(),
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...actual,
|
|
74
|
+
FlatList: FlatListMock,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
vi.mock("@assistant-ui/store", async () => {
|
|
79
|
+
const React = await import("react");
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
useAuiState: <T,>(selector: (s: typeof h.state) => T) => selector(h.state),
|
|
83
|
+
useAuiEvent: (
|
|
84
|
+
selector: string | { scope: string; event: string },
|
|
85
|
+
callback: () => void,
|
|
86
|
+
) => {
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
const event =
|
|
89
|
+
typeof selector === "string"
|
|
90
|
+
? selector
|
|
91
|
+
: `${selector.scope}.${selector.event}`;
|
|
92
|
+
const callbacks = (h.events[event] ??= new Set());
|
|
93
|
+
callbacks.add(callback);
|
|
94
|
+
return () => {
|
|
95
|
+
callbacks.delete(callback);
|
|
96
|
+
};
|
|
97
|
+
}, [selector, callback]);
|
|
98
|
+
},
|
|
99
|
+
RenderChildrenWithAccessor: ({
|
|
100
|
+
children,
|
|
101
|
+
}: {
|
|
102
|
+
children: (getItem: () => unknown) => unknown;
|
|
103
|
+
}) => children(() => h.itemState),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
24
106
|
|
|
25
107
|
vi.mock("@assistant-ui/core/react", () => ({
|
|
26
108
|
MessageByIndexProvider: ({ children }: { children: unknown }) => children,
|
|
@@ -37,6 +119,9 @@ describe("ThreadMessages", () => {
|
|
|
37
119
|
h.state.message.role = "user";
|
|
38
120
|
h.state.message.composer.isEditing = false;
|
|
39
121
|
h.itemState = { role: "user" };
|
|
122
|
+
h.events = {};
|
|
123
|
+
h.flatListProps = null;
|
|
124
|
+
h.scrollToEnd.mockReset();
|
|
40
125
|
|
|
41
126
|
container = document.createElement("div");
|
|
42
127
|
document.body.appendChild(container);
|
|
@@ -56,6 +141,37 @@ describe("ThreadMessages", () => {
|
|
|
56
141
|
});
|
|
57
142
|
};
|
|
58
143
|
|
|
144
|
+
const mountFlatList = async (
|
|
145
|
+
props: Parameters<typeof ThreadMessagesFlatList>[0],
|
|
146
|
+
) => {
|
|
147
|
+
await act(async () => {
|
|
148
|
+
root.render(<ThreadMessagesFlatList {...props} />);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const getFlatListProps = () => {
|
|
153
|
+
const props = h.flatListProps as {
|
|
154
|
+
onContentSizeChange?: (width: number, height: number) => void;
|
|
155
|
+
onLayout?: (event: unknown) => void;
|
|
156
|
+
onScroll?: (event: unknown) => void;
|
|
157
|
+
scrollEventThrottle?: number;
|
|
158
|
+
} | null;
|
|
159
|
+
if (!props) throw new Error("FlatList was not rendered");
|
|
160
|
+
return props;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const emit = async (event: string) => {
|
|
164
|
+
await act(async () => {
|
|
165
|
+
h.events[event]?.forEach((callback) => {
|
|
166
|
+
callback();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const messageComponents = {
|
|
172
|
+
Message: () => <span data-testid="c-message">message</span>,
|
|
173
|
+
};
|
|
174
|
+
|
|
59
175
|
describe("components mode dispatch", () => {
|
|
60
176
|
const makeComponents = () => ({
|
|
61
177
|
Message: vi.fn(() => <span data-testid="c-message">message</span>),
|
|
@@ -189,4 +305,322 @@ describe("ThreadMessages", () => {
|
|
|
189
305
|
});
|
|
190
306
|
expect(container.querySelector('[data-testid="c-message"]')).toBeNull();
|
|
191
307
|
});
|
|
308
|
+
|
|
309
|
+
it("forwards refs to the underlying FlatList", async () => {
|
|
310
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
311
|
+
const ref = createRef<FlatList<ThreadMessage>>();
|
|
312
|
+
|
|
313
|
+
await act(async () => {
|
|
314
|
+
root.render(
|
|
315
|
+
<ThreadMessages
|
|
316
|
+
ref={ref}
|
|
317
|
+
components={{
|
|
318
|
+
Message: () => <span data-testid="c-message">message</span>,
|
|
319
|
+
}}
|
|
320
|
+
/>,
|
|
321
|
+
);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(ref.current).not.toBeNull();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("keeps deprecated Messages off the scroll-tracking path", async () => {
|
|
328
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
329
|
+
await mount({ components: messageComponents });
|
|
330
|
+
const props = getFlatListProps();
|
|
331
|
+
|
|
332
|
+
expect(props.onScroll).toBeUndefined();
|
|
333
|
+
expect(props.onLayout).toBeUndefined();
|
|
334
|
+
expect(props.onContentSizeChange).toBeUndefined();
|
|
335
|
+
expect(props.scrollEventThrottle).toBeUndefined();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("keeps deprecated Messages from auto-scrolling by default", async () => {
|
|
339
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
340
|
+
await mount({ components: messageComponents });
|
|
341
|
+
const props = getFlatListProps();
|
|
342
|
+
|
|
343
|
+
await act(async () => {
|
|
344
|
+
props.onLayout?.({
|
|
345
|
+
nativeEvent: { layout: { height: 100 } },
|
|
346
|
+
});
|
|
347
|
+
props.onScroll?.({
|
|
348
|
+
nativeEvent: {
|
|
349
|
+
contentOffset: { y: 0 },
|
|
350
|
+
contentSize: { height: 100, width: 0 },
|
|
351
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
props.onContentSizeChange?.(0, 140);
|
|
355
|
+
});
|
|
356
|
+
await emit("thread.runStart");
|
|
357
|
+
await emit("threadListItem.switchedTo");
|
|
358
|
+
|
|
359
|
+
expect(h.scrollToEnd).not.toHaveBeenCalled();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
describe("MessagesFlatList auto-scroll", () => {
|
|
363
|
+
it("scrolls to the bottom when messages first appear", async () => {
|
|
364
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
365
|
+
|
|
366
|
+
await mountFlatList({ components: messageComponents });
|
|
367
|
+
|
|
368
|
+
expect(h.scrollToEnd).toHaveBeenCalledWith({ animated: false });
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("scrolls to the bottom when a run starts", async () => {
|
|
372
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
373
|
+
await mountFlatList({ components: messageComponents });
|
|
374
|
+
h.scrollToEnd.mockClear();
|
|
375
|
+
|
|
376
|
+
await emit("thread.runStart");
|
|
377
|
+
|
|
378
|
+
expect(h.scrollToEnd).toHaveBeenCalledWith({ animated: true });
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("scrolls when content grows while already at the bottom", async () => {
|
|
382
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
383
|
+
await mountFlatList({ components: messageComponents });
|
|
384
|
+
const props = getFlatListProps();
|
|
385
|
+
h.scrollToEnd.mockClear();
|
|
386
|
+
|
|
387
|
+
await act(async () => {
|
|
388
|
+
props.onLayout?.({
|
|
389
|
+
nativeEvent: { layout: { height: 100 } },
|
|
390
|
+
});
|
|
391
|
+
props.onScroll?.({
|
|
392
|
+
nativeEvent: {
|
|
393
|
+
contentOffset: { y: 0 },
|
|
394
|
+
contentSize: { height: 100, width: 0 },
|
|
395
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
props.onContentSizeChange?.(0, 140);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
expect(h.scrollToEnd).toHaveBeenCalledWith({ animated: false });
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it("does not treat the first content-size event as automatic content growth", async () => {
|
|
405
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
406
|
+
await mountFlatList({
|
|
407
|
+
components: messageComponents,
|
|
408
|
+
scrollToBottomOnInitialize: false,
|
|
409
|
+
});
|
|
410
|
+
const props = getFlatListProps();
|
|
411
|
+
|
|
412
|
+
await act(async () => {
|
|
413
|
+
props.onContentSizeChange?.(0, 140);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(h.scrollToEnd).not.toHaveBeenCalled();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it("lands the initialize scroll on the first content-size event", async () => {
|
|
420
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
421
|
+
await mountFlatList({ components: messageComponents });
|
|
422
|
+
const props = getFlatListProps();
|
|
423
|
+
|
|
424
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(1);
|
|
425
|
+
|
|
426
|
+
await act(async () => {
|
|
427
|
+
props.onContentSizeChange?.(0, 140);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(2);
|
|
431
|
+
|
|
432
|
+
await act(async () => {
|
|
433
|
+
props.onContentSizeChange?.(0, 140);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(2);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("lands the thread-switch scroll on the next content-size event", async () => {
|
|
440
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
441
|
+
await mountFlatList({ components: messageComponents });
|
|
442
|
+
const props = getFlatListProps();
|
|
443
|
+
h.scrollToEnd.mockClear();
|
|
444
|
+
|
|
445
|
+
await emit("threadListItem.switchedTo");
|
|
446
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(1);
|
|
447
|
+
|
|
448
|
+
await act(async () => {
|
|
449
|
+
props.onContentSizeChange?.(0, 80);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(2);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it("keeps following through consecutive growth events without scroll echoes", async () => {
|
|
456
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
457
|
+
await mountFlatList({ components: messageComponents });
|
|
458
|
+
const props = getFlatListProps();
|
|
459
|
+
|
|
460
|
+
await act(async () => {
|
|
461
|
+
props.onLayout?.({
|
|
462
|
+
nativeEvent: { layout: { height: 100 } },
|
|
463
|
+
});
|
|
464
|
+
props.onScroll?.({
|
|
465
|
+
nativeEvent: {
|
|
466
|
+
contentOffset: { y: 0 },
|
|
467
|
+
contentSize: { height: 100, width: 0 },
|
|
468
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
h.scrollToEnd.mockClear();
|
|
473
|
+
|
|
474
|
+
await act(async () => {
|
|
475
|
+
props.onContentSizeChange?.(0, 140);
|
|
476
|
+
});
|
|
477
|
+
await act(async () => {
|
|
478
|
+
props.onContentSizeChange?.(0, 180);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(2);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("does not scroll when content grows after the user scrolled away", async () => {
|
|
485
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
486
|
+
await mountFlatList({ components: messageComponents });
|
|
487
|
+
const props = getFlatListProps();
|
|
488
|
+
h.scrollToEnd.mockClear();
|
|
489
|
+
|
|
490
|
+
await act(async () => {
|
|
491
|
+
props.onLayout?.({
|
|
492
|
+
nativeEvent: { layout: { height: 100 } },
|
|
493
|
+
});
|
|
494
|
+
props.onScroll?.({
|
|
495
|
+
nativeEvent: {
|
|
496
|
+
contentOffset: { y: 200 },
|
|
497
|
+
contentSize: { height: 300, width: 0 },
|
|
498
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
props.onScroll?.({
|
|
502
|
+
nativeEvent: {
|
|
503
|
+
contentOffset: { y: 50 },
|
|
504
|
+
contentSize: { height: 300, width: 0 },
|
|
505
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
props.onContentSizeChange?.(0, 340);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
expect(h.scrollToEnd).not.toHaveBeenCalled();
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it("lands the run-start scroll once the appended message resizes content", async () => {
|
|
515
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
516
|
+
await mountFlatList({ components: messageComponents });
|
|
517
|
+
const props = getFlatListProps();
|
|
518
|
+
|
|
519
|
+
await act(async () => {
|
|
520
|
+
props.onLayout?.({
|
|
521
|
+
nativeEvent: { layout: { height: 100 } },
|
|
522
|
+
});
|
|
523
|
+
props.onScroll?.({
|
|
524
|
+
nativeEvent: {
|
|
525
|
+
contentOffset: { y: 200 },
|
|
526
|
+
contentSize: { height: 300, width: 0 },
|
|
527
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
props.onScroll?.({
|
|
531
|
+
nativeEvent: {
|
|
532
|
+
contentOffset: { y: 50 },
|
|
533
|
+
contentSize: { height: 300, width: 0 },
|
|
534
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
h.scrollToEnd.mockClear();
|
|
539
|
+
|
|
540
|
+
await emit("thread.runStart");
|
|
541
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(1);
|
|
542
|
+
|
|
543
|
+
await act(async () => {
|
|
544
|
+
props.onScroll?.({
|
|
545
|
+
nativeEvent: {
|
|
546
|
+
contentOffset: { y: 120 },
|
|
547
|
+
contentSize: { height: 300, width: 0 },
|
|
548
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
549
|
+
},
|
|
550
|
+
});
|
|
551
|
+
props.onContentSizeChange?.(0, 360);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
expect(h.scrollToEnd).toHaveBeenCalledTimes(2);
|
|
555
|
+
expect(h.scrollToEnd).toHaveBeenLastCalledWith({ animated: true });
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("scrolls to the bottom when switching threads", async () => {
|
|
559
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
560
|
+
await mountFlatList({ components: messageComponents });
|
|
561
|
+
h.scrollToEnd.mockClear();
|
|
562
|
+
|
|
563
|
+
await emit("threadListItem.switchedTo");
|
|
564
|
+
|
|
565
|
+
expect(h.scrollToEnd).toHaveBeenCalledWith({ animated: false });
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("does not rearm initialize scroll when thread-switch scroll is disabled", async () => {
|
|
569
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
570
|
+
await mountFlatList({
|
|
571
|
+
components: messageComponents,
|
|
572
|
+
scrollToBottomOnThreadSwitch: false,
|
|
573
|
+
});
|
|
574
|
+
h.scrollToEnd.mockClear();
|
|
575
|
+
|
|
576
|
+
await emit("threadListItem.switchedTo");
|
|
577
|
+
|
|
578
|
+
h.state.thread.messages = [
|
|
579
|
+
{ id: "2", role: "user" },
|
|
580
|
+
{ id: "3", role: "assistant" },
|
|
581
|
+
];
|
|
582
|
+
await mountFlatList({
|
|
583
|
+
components: messageComponents,
|
|
584
|
+
scrollToBottomOnThreadSwitch: false,
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
expect(h.scrollToEnd).not.toHaveBeenCalled();
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("honors opt-outs for automatic content growth and run-start scrolls", async () => {
|
|
591
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
592
|
+
await mountFlatList({
|
|
593
|
+
autoScroll: false,
|
|
594
|
+
components: messageComponents,
|
|
595
|
+
scrollToBottomOnInitialize: false,
|
|
596
|
+
scrollToBottomOnRunStart: false,
|
|
597
|
+
});
|
|
598
|
+
const props = getFlatListProps();
|
|
599
|
+
h.scrollToEnd.mockClear();
|
|
600
|
+
|
|
601
|
+
await act(async () => {
|
|
602
|
+
props.onLayout?.({
|
|
603
|
+
nativeEvent: { layout: { height: 100 } },
|
|
604
|
+
});
|
|
605
|
+
props.onScroll?.({
|
|
606
|
+
nativeEvent: {
|
|
607
|
+
contentOffset: { y: 0 },
|
|
608
|
+
contentSize: { height: 100, width: 0 },
|
|
609
|
+
layoutMeasurement: { height: 100, width: 0 },
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
props.onContentSizeChange?.(0, 140);
|
|
613
|
+
});
|
|
614
|
+
await emit("thread.runStart");
|
|
615
|
+
|
|
616
|
+
expect(h.scrollToEnd).not.toHaveBeenCalled();
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it("sets a useful default scroll throttle", async () => {
|
|
620
|
+
h.state.thread.messages = [{ id: "1", role: "user" }];
|
|
621
|
+
await mountFlatList({ components: messageComponents });
|
|
622
|
+
|
|
623
|
+
expect(getFlatListProps().scrollEventThrottle).toBe(16);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
192
626
|
});
|