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

154 lines
5.3 KiB
TypeScript
Raw Normal View History

import { ChatPage } from '../pages/chat';
2025-04-25 23:40:15 -07:00
import { test, expect } from '../fixtures';
2025-03-04 17:25:46 -08:00
2025-04-25 23:40:15 -07: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
});
2025-04-25 23:40:15 -07: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
});
2025-04-25 23:40:15 -07: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();
});
2025-04-25 23:40:15 -07:00
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(
2025-03-11 14:39:36 -07:00
'With Next.js, you can ship fast!',
2025-03-04 17:25:46 -08:00
);
});
2025-04-25 23:40:15 -07: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();
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();
});
2025-04-25 23:40:15 -07:00
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();
});
2025-04-25 23:40:15 -07:00
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
});
2025-04-25 23:40:15 -07:00
test('Hide suggested actions after sending message', async () => {
2025-03-04 17:25:46 -08:00
await chatPage.isElementVisible('suggested-actions');
await chatPage.sendUserMessageFromSuggestion();
await chatPage.isElementNotVisible('suggested-actions');
});
2025-04-25 23:40:15 -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!');
});
2025-04-25 23:40:15 -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-04-25 23:40:15 -07:00
test('Upvote message', async () => {
2025-03-11 14:39:36 -07:00
await chatPage.sendUserMessage('Why is the sky blue?');
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
await assistantMessage.upvote();
await chatPage.isVoteComplete();
});
2025-04-25 23:40:15 -07:00
test('Downvote message', async () => {
2025-03-11 14:39:36 -07:00
await chatPage.sendUserMessage('Why is the sky blue?');
await chatPage.isGenerationComplete();
const assistantMessage = await chatPage.getRecentAssistantMessage();
await assistantMessage.downvote();
await chatPage.isVoteComplete();
});
2025-04-25 23:40:15 -07:00
test('Update vote', async () => {
2025-03-11 14:39:36 -07:00
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
});
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?');
const assistantMessage = await chatPage.getRecentAssistantMessage();
expect(assistantMessage.content).toContain("It's just blue duh!");
});
2025-03-04 17:25:46 -08:00
});