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

69 lines
2.2 KiB
TypeScript
Raw Normal View History

import { expect, test } from "@playwright/test";
import { ChatPage } from "../pages/chat";
2025-03-04 17:25:46 -08:00
test.describe("Chat", () => {
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("page loads with input ready", async () => {
await chatPage.waitForInputToBeReady();
2025-03-04 17:25:46 -08:00
});
test("send button is disabled when input is empty", async () => {
2025-03-04 17:25:46 -08:00
await expect(chatPage.sendButton).toBeDisabled();
});
test("send button is enabled when input has text", async () => {
await chatPage.multimodalInput.fill("Hello");
await expect(chatPage.sendButton).toBeEnabled();
2025-03-04 17:25:46 -08:00
});
test("can send a message and receive a response", async () => {
await chatPage.sendUserMessage("Hello");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
const userContent = await chatPage.getLastUserMessageContent();
expect(userContent).toBe("Hello");
2025-03-04 17:25:46 -08:00
const assistantContent = await chatPage.getLastAssistantMessageContent();
expect(assistantContent).toBeTruthy();
2025-03-04 17:25:46 -08:00
});
test("redirects to /chat/:id after sending message", async () => {
await chatPage.sendUserMessage("Hello");
2025-03-04 17:25:46 -08:00
await chatPage.isGenerationComplete();
await chatPage.hasChatIdInUrl();
2025-03-11 14:39:36 -07:00
});
test("shows stop button during generation", async () => {
await chatPage.multimodalInput.fill("Hello");
await chatPage.sendButton.click();
await expect(chatPage.stopButton).toBeVisible({ timeout: 5000 });
2025-03-11 14:39:36 -07:00
});
test("can stop generation", async () => {
await chatPage.multimodalInput.fill("Hello");
await chatPage.sendButton.click();
await expect(chatPage.stopButton).toBeVisible({ timeout: 5000 });
await chatPage.stopButton.click();
await expect(chatPage.sendButton).toBeVisible({ timeout: 5000 });
2025-03-04 17:25:46 -08:00
});
});
test.describe("Chat - Guest User", () => {
test("can use chat as guest", async ({ page }) => {
const chatPage = new ChatPage(page);
await chatPage.createNewChat();
await chatPage.waitForInputToBeReady();
await chatPage.sendUserMessage("Hello");
await chatPage.isGenerationComplete();
const content = await chatPage.getLastAssistantMessageContent();
expect(content).toBeTruthy();
});
2025-03-04 17:25:46 -08:00
});