Skip to content

Commit

Permalink
add chat e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed Feb 27, 2025
1 parent 2682a4d commit 9b3854e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions e2e/tests/chat.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { test, expect } from '@playwright/test';
import { E2E_UI_PORT, cleanDatabase, startServer, stopServer } from '../helpers/database';

let server: any;

test.describe('Chat', () => {
test.beforeAll(async () => {
await cleanDatabase();
server = await startServer();
});

test.afterAll(async () => {
await stopServer(server);
});

test.beforeEach(async ({ page }) => {
await page.goto(`http://localhost:${E2E_UI_PORT}`);
});

test('should send and display chat messages', async ({ page }) => {
// Sign up and login first
await page.click('[data-testid="show-signup-button"]');
await page.fill('[data-testid="signup-username-input"]', 'testuser');
await page.fill('[data-testid="signup-password-input"]', 'testpassword');
await page.click('[data-testid="signup-submit-button"]');
await page.fill('[data-testid="login-username-input"]', 'testuser');
await page.fill('[data-testid="login-password-input"]', 'testpassword');
await page.click('[data-testid="login-submit-button"]');

// Wait for character level to confirm we're logged in
await page.waitForSelector('[data-testid="character-level"]');

// Set up console message monitoring before sending messages
const consoleMessages: string[] = [];
page.on('console', msg => {
consoleMessages.push(msg.text());
});

// Type and send a chat message
const testMessage = 'Hello world!';
await page.fill('#chat-input', testMessage);
await page.click('button[aria-label="send chat"]');

// Wait for the message to appear in the chat
// We need to wait for both the message content and the username
await page.waitForSelector(`text=testuser`, { timeout: 5000 });
await page.waitForSelector(`text=${testMessage}`, { timeout: 5000 });

// Verify the message appears with the correct username
const messageElement = await page.waitForSelector(`text=${testMessage}`, { timeout: 5000 });
expect(messageElement).toBeTruthy();

// Send another message to test callback
const testMessage2 = 'Testing callback!';
await page.fill('#chat-input', testMessage2);
await page.click('button[aria-label="send chat"]');

// Wait for console log that indicates callback was called
await expect.poll(() => {
return consoleMessages.some(msg => msg.includes('Got chat event!'));
}, { timeout: 5000 }).toBeTruthy();

// Also verify the second message appears
await page.waitForSelector(`text=${testMessage2}`, { timeout: 5000 });
});
});

0 comments on commit 9b3854e

Please sign in to comment.