fix(GRO-985): fix Messages test mocks and scrollIntoView guard

- Wrap conversation mocks in { items, nextCursor } response shape
  (loadConversations reads json.items, bare array caused undefined.length crash)
- Guard scrollIntoView with ?. (jsdom doesn't implement it)
- Use getAllByText for text appearing in both preview and thread

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-05-14 16:12:31 +00:00
committed by The Dogfather [agent]
parent e605e1be74
commit 9d9d7da13d
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -96,7 +96,7 @@ describe("MessagesPage", () => {
vi.mocked(global.fetch).mockImplementation((input) => {
const url = String(input);
if (url === "/api/conversations?limit=20") {
return Promise.resolve(makeResponse(mockConversations));
return Promise.resolve(makeResponse({ items: mockConversations, nextCursor: null }));
}
if (url === "/api/conversations/conv-1/messages?limit=50") {
return Promise.resolve(makeResponse({ items: mockMessages, nextCursor: null }));
@@ -110,7 +110,7 @@ describe("MessagesPage", () => {
fireEvent.click(screen.getByText("Alice Smith"));
await waitFor(() => {
expect(screen.getByText("Hello, is my dog ready?")).toBeInTheDocument();
expect(screen.getAllByText("Hello, is my dog ready?").length).toBeGreaterThanOrEqual(1);
expect(screen.getByText("Yes, she is all done!")).toBeInTheDocument();
});
});
@@ -130,7 +130,7 @@ describe("MessagesPage", () => {
sentByStaffId: "staff-1",
}, 201));
}
return Promise.resolve(makeResponse(mockConversations));
return Promise.resolve(makeResponse({ items: mockConversations, nextCursor: null }));
});
render(<MessagesPage />);
+1 -1
View File
@@ -93,7 +93,7 @@ export function MessagesPage() {
useEffect(() => {
if (messages.length > 0) {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
messagesEndRef.current?.scrollIntoView?.({ behavior: "smooth" });
}
}, [messages]);