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:
@@ -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 />);
|
||||
|
||||
@@ -93,7 +93,7 @@ export function MessagesPage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (messages.length > 0) {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
messagesEndRef.current?.scrollIntoView?.({ behavior: "smooth" });
|
||||
}
|
||||
}, [messages]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user