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

142 lines
4.8 KiB
TypeScript
Raw Normal View History

import { ChatPage } from '../pages/chat';
2025-03-11 14:39:36 -07:00
import { test, expect } from '@playwright/test';
2025-03-04 17:25:46 -08:00
test.describe('chat activity', () => {
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 () => {
2025-03-11 14:39:36 -07:00
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 () => {
2025-03-11 14:39:36 -07:00
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 () => {
await chatPage.sendUserMessageFromSuggestion();
await chatPage.isGenerationComplete();
2025-03-09 21:02:19 -07:00
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toContain(
2025-03-11 14:39:36 -07:00
'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 () => {
await expect(chatPage.sendButton).toBeVisible();
await expect(chatPage.sendButton).toBeDisabled();
2025-03-11 14:39:36 -07:00
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 () => {
2025-03-11 14:39:36 -07:00
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 () => {
2025-03-11 14:39:36 -07:00
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();
2025-03-11 14:39:36 -07:00
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');
await chatPage.sendUserMessageFromSuggestion();
await chatPage.isElementNotVisible('suggested-actions');
});
2025-03-09 21:02:19 -07: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-11 14:39:36 -07: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();
2025-03-11 14:39:36 -07:00
expect(assistantMessage.content).toBe('This painting is by Monet!');
});
test('call weather tool', async () => {
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.',
);
});
test('upvote message', async () => {
await chatPage.sendUserMessage('Why is the sky blue?');
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?');
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?');
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
});
});