glam/apps/archief-assistent/e2e/chat.spec.ts
kempersc ea35da02dc test(archief-assistent): add Playwright E2E test suite
- Add chat.spec.ts for RAG query testing
- Add count-queries.spec.ts for aggregation validation
- Add map-panel.spec.ts for geographic feature testing
- Add cache.spec.ts for response caching verification
- Add auth.setup.ts for authentication handling
- Configure playwright.config.ts for multi-browser testing
- Tests run against production archief.support
2026-01-09 21:09:56 +01:00

104 lines
3.5 KiB
TypeScript

import { test, expect } from '@playwright/test'
import { loginAndNavigate, waitForChatReady } from './auth.setup'
/**
* Basic chat functionality tests for ArchiefAssistent
*
* These tests verify the core chat UI works correctly:
* - Input field accepts text
* - Send button submits query
* - Messages appear in chat history
* - Assistant responds to queries
*/
test.describe('Chat UI', () => {
test.beforeEach(async ({ page }) => {
await loginAndNavigate(page)
await waitForChatReady(page)
})
test('should display chat input and send button', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
const sendButton = page.getByTestId('send-button')
await expect(chatInput).toBeVisible()
await expect(sendButton).toBeVisible()
})
test('should accept text input', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
await chatInput.fill('Test bericht')
await expect(chatInput).toHaveValue('Test bericht')
})
test('should submit query and show user message', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
const sendButton = page.getByTestId('send-button')
const testQuery = 'Hoeveel archieven zijn er in Utrecht?'
await chatInput.fill(testQuery)
await sendButton.click()
// Wait for user message to appear
const userMessage = page.getByTestId('user-message').filter({ hasText: testQuery })
await expect(userMessage).toBeVisible({ timeout: 5000 })
})
test('should receive assistant response', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
const sendButton = page.getByTestId('send-button')
await chatInput.fill('Hoeveel archieven zijn er in Utrecht?')
await sendButton.click()
// Wait for assistant message to appear (RAG can take time)
const assistantMessage = page.getByTestId('assistant-message')
await expect(assistantMessage.first()).toBeVisible({ timeout: 45000 })
// Assistant should have some content
await expect(assistantMessage.first()).not.toBeEmpty()
})
test('should clear input after sending', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
const sendButton = page.getByTestId('send-button')
await chatInput.fill('Test vraag')
await sendButton.click()
// Input should be cleared after sending
await expect(chatInput).toHaveValue('')
})
test('should allow multiple messages in conversation', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
const sendButton = page.getByTestId('send-button')
// Send first message
await chatInput.fill('Hoeveel musea zijn er in Gelderland?')
await sendButton.click()
// Wait for first response
await page.getByTestId('assistant-message').first().waitFor({ timeout: 45000 })
// Send second message
await chatInput.fill('En hoeveel bibliotheken?')
await sendButton.click()
// Should have 2 user messages
const userMessages = page.getByTestId('user-message')
await expect(userMessages).toHaveCount(2, { timeout: 10000 })
})
test('should support Enter key to submit', async ({ page }) => {
const chatInput = page.getByTestId('chat-input')
await chatInput.fill('Test met Enter toets')
await chatInput.press('Enter')
// User message should appear
const userMessage = page.getByTestId('user-message').filter({ hasText: 'Test met Enter toets' })
await expect(userMessage).toBeVisible({ timeout: 5000 })
})
})