chatbot-template/tests/e2e/chat.test.ts

173 lines
6 KiB
TypeScript
Raw Normal View History

import { expect, test } from "../fixtures";
import { ChatPage } from "../pages/chat";
2025-03-04 17:25:46 -08:00
test.describe("Chat activity", () => {
2025-03-04 17:25:46 -08:00
let chatPage: ChatPage;
test.beforeEach(async ({ page }) => {
chatPage = new ChatPage(page);
2025-03-09 21:02:19 -07:00
await chatPage.createNewChat();
2025-03-04 17:25:46 -08:00
});
test("Send a user message and receive response", async () => {
await chatPage.sendUserMessage("Why is grass green?");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
2025-03-11 14:39:36 -07:00
expect(assistantMessage.content).toContain("It's just green duh!");
2025-03-04 17:25:46 -08:00
});
test("Redirect to /chat/:id after submitting message", async () => {
await chatPage.sendUserMessage("Why is grass green?");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
2025-03-11 14:39:36 -07:00
expect(assistantMessage.content).toContain("It's just green duh!");
2025-03-04 17:25:46 -08:00
await chatPage.hasChatIdInUrl();
});
test("Send a user message from suggestion", async () => {
2025-03-04 17:25:46 -08:00
await chatPage.sendUserMessageFromSuggestion();
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toContain(
"With Next.js, you can ship fast!"
2025-03-04 17:25:46 -08:00
);
});
test("Toggle between send/stop button based on activity", async () => {
2025-03-04 17:25:46 -08:00
await expect(chatPage.sendButton).toBeVisible();
await expect(chatPage.sendButton).toBeDisabled();
await chatPage.sendUserMessage("Why is grass green?");
2025-03-04 17:25:46 -08:00
await expect(chatPage.sendButton).not.toBeVisible();
await expect(chatPage.stopButton).toBeVisible();
await chatPage.isGenerationComplete();
await expect(chatPage.stopButton).not.toBeVisible();
await expect(chatPage.sendButton).toBeVisible();
});
test("Stop generation during submission", async () => {
await chatPage.sendUserMessage("Why is grass green?");
2025-03-09 21:02:19 -07:00
await expect(chatPage.stopButton).toBeVisible();
2025-03-04 17:25:46 -08:00
await chatPage.stopButton.click();
await expect(chatPage.sendButton).toBeVisible();
});
test("Edit user message and resubmit", async () => {
await chatPage.sendUserMessage("Why is grass green?");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
2025-03-11 14:39:36 -07:00
expect(assistantMessage.content).toContain("It's just green duh!");
2025-03-09 21:02:19 -07:00
const userMessage = await chatPage.getRecentUserMessage();
await userMessage.edit("Why is the sky blue?");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const updatedAssistantMessage = await chatPage.getRecentAssistantMessage();
2025-03-11 14:39:36 -07:00
expect(updatedAssistantMessage.content).toContain("It's just blue duh!");
2025-03-04 17:25:46 -08:00
});
test("Hide suggested actions after sending message", async () => {
await chatPage.isElementVisible("suggested-actions");
2025-03-04 17:25:46 -08:00
await chatPage.sendUserMessageFromSuggestion();
await chatPage.isElementNotVisible("suggested-actions");
2025-03-04 17:25:46 -08:00
});
test("Upload file and send image attachment with message", async () => {
2025-03-04 17:25:46 -08:00
await chatPage.addImageAttachment();
await chatPage.isElementVisible("attachments-preview");
await chatPage.isElementVisible("input-attachment-loader");
await chatPage.isElementNotVisible("input-attachment-loader");
2025-03-04 17:25:46 -08:00
await chatPage.sendUserMessage("Who painted this?");
2025-03-09 21:02:19 -07:00
const userMessage = await chatPage.getRecentUserMessage();
expect(userMessage.attachments).toHaveLength(1);
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toBe("This painting is by Monet!");
2025-03-11 14:39:36 -07:00
});
test("Call weather tool", async () => {
2025-03-11 14:39:36 -07:00
await chatPage.sendUserMessage("What's the weather in sf?");
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toBe(
"The current temperature in San Francisco is 17°C."
2025-03-11 14:39:36 -07:00
);
});
test("Upvote message", async () => {
await chatPage.sendUserMessage("Why is the sky blue?");
2025-03-11 14:39:36 -07:00
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
await assistantMessage.upvote();
await chatPage.isVoteComplete();
});
test("Downvote message", async () => {
await chatPage.sendUserMessage("Why is the sky blue?");
2025-03-11 14:39:36 -07:00
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
await assistantMessage.downvote();
await chatPage.isVoteComplete();
});
test("Update vote", async () => {
await chatPage.sendUserMessage("Why is the sky blue?");
2025-03-11 14:39:36 -07:00
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
await assistantMessage.upvote();
await chatPage.isVoteComplete();
await assistantMessage.downvote();
await chatPage.isVoteComplete();
2025-03-04 17:25:46 -08:00
});
test("Create message from url query", async ({ page }) => {
await page.goto("/?query=Why is the sky blue?");
await chatPage.isGenerationComplete();
2025-04-29 00:20:10 -07:00
const userMessage = await chatPage.getRecentUserMessage();
expect(userMessage.content).toBe("Why is the sky blue?");
2025-04-29 00:20:10 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toContain("It's just blue duh!");
});
test("auto-scrolls to bottom after submitting new messages", async () => {
test.fixme();
await chatPage.sendMultipleMessages(5, (i) => `filling message #${i}`);
await chatPage.waitForScrollToBottom();
});
test("scroll button appears when user scrolls up, hides on click", async () => {
test.fixme();
await chatPage.sendMultipleMessages(5, (i) => `filling message #${i}`);
await expect(chatPage.scrollToBottomButton).not.toBeVisible();
await chatPage.scrollToTop();
await expect(chatPage.scrollToBottomButton).toBeVisible();
await chatPage.scrollToBottomButton.click();
await chatPage.waitForScrollToBottom();
await expect(chatPage.scrollToBottomButton).not.toBeVisible();
});
2025-03-04 17:25:46 -08:00
});