feat: Add Playwright testing scaffolding infrastructure

Implements complete Playwright testing infrastructure for manual MCP testing and
as foundation for Magnitude tests.

Created:
- playwright.config.ts - Main configuration with setup project
- tests/playwright/auth.setup.ts - Authentication setup (placeholder)
- tests/playwright/fixtures.ts - Custom fixtures for authenticated/page contexts
- tests/playwright/helpers/chat.ts - Chat interaction helpers
- tests/playwright/helpers/galaxy.ts - Galaxy visualization helpers
- tests/playwright/helpers/node.ts - Node creation/management helpers
- tests/playwright/smoke.spec.ts - Basic smoke tests
- .env.test - Environment variables template

Updated:
- package.json - Added test:playwright scripts
- .gitignore - Added tests/playwright/.auth/ exclusion

Ready for manual Playwright MCP testing and Magnitude test creation.

Resolves plan: 01-playwright-scaffolding.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-09 21:14:35 +00:00
parent b96159ec02
commit 4967ce3cd1
10 changed files with 174 additions and 12 deletions

View File

@@ -0,0 +1,12 @@
import { test as setup, expect } from '@playwright/test';
const authFile = 'tests/playwright/.auth/user.json';
setup('authenticate', async ({ page }) => {
// For now, just create an empty auth file
// TODO: Implement actual OAuth flow when test credentials are available
console.log('[Auth Setup] Skipping authentication - implement OAuth flow with test credentials');
// Save empty state for now
await page.context().storageState({ path: authFile });
});

View File

@@ -0,0 +1,26 @@
import { test as base, Page } from '@playwright/test';
type Fixtures = {
authenticatedPage: Page;
chatPage: Page;
galaxyPage: Page;
};
export const test = base.extend<Fixtures>({
authenticatedPage: async ({ page }, use) => {
await page.goto('/');
await use(page);
},
chatPage: async ({ page }, use) => {
await page.goto('/chat');
await use(page);
},
galaxyPage: async ({ page }, use) => {
await page.goto('/galaxy');
await use(page);
},
});
export { expect } from '@playwright/test';

View File

@@ -0,0 +1,35 @@
import { Page, expect } from '@playwright/test';
export class ChatHelper {
constructor(private page: Page) {}
async sendMessage(message: string) {
const input = this.page.locator('textarea[placeholder*="Type"], input[placeholder*="Type"]');
await input.fill(message);
await input.press('Enter');
}
async waitForAIResponse() {
// Wait for typing indicator to appear then disappear
const typingIndicator = this.page.locator('[data-testid="typing-indicator"]').first();
try {
await typingIndicator.waitFor({ state: 'visible', timeout: 2000 });
await typingIndicator.waitFor({ state: 'hidden', timeout: 30000 });
} catch {
// Typing indicator might not appear for fast responses
await this.page.waitForTimeout(1000);
}
}
async getLastMessage() {
const messages = this.page.locator('[data-testid="chat-message"]');
const count = await messages.count();
return count > 0 ? messages.nth(count - 1) : null;
}
async getMessageCount() {
const messages = this.page.locator('[data-testid="chat-message"]');
return await messages.count();
}
}

View File

@@ -0,0 +1,28 @@
import { Page } from '@playwright/test';
export class GalaxyHelper {
constructor(private page: Page) {}
async waitForGalaxyLoad() {
// Wait for canvas to be visible
await this.page.waitForSelector('canvas', { timeout: 10000 });
// Give R3F time to render
await this.page.waitForTimeout(2000);
}
async clickNode(nodeId: string) {
// Simulate node click via JavaScript event
await this.page.evaluate((id) => {
const event = new CustomEvent('node-click', { detail: { nodeId: id } });
window.dispatchEvent(event);
}, nodeId);
}
async getNodeCount() {
return await this.page.evaluate(() => {
// Access window globals set by galaxy component
return (window as any).__galaxyNodes?.length || 0;
});
}
}

View File

@@ -0,0 +1,36 @@
import { Page } from '@playwright/test';
export class NodeHelper {
constructor(private page: Page) {}
async createNode(title: string, body: string) {
// This will vary based on actual implementation
// For now, placeholder that navigates to chat
await this.page.goto('/chat');
// TODO: Implement actual node creation flow
// This depends on how nodes are created in the UI
}
async waitForUMAPCalculation(timeoutMs: number = 60000) {
// Poll /api/galaxy until nodes have coords_3d
const startTime = Date.now();
while (Date.now() - startTime < timeoutMs) {
try {
const response = await this.page.request.get('/api/galaxy');
const data = await response.json();
if (data.nodes && data.nodes.every((n: any) => n.coords_3d !== null)) {
return true;
}
} catch {
// Continue polling
}
await this.page.waitForTimeout(2000);
}
return false;
}
}

View File

@@ -0,0 +1,21 @@
import { test, expect } from './fixtures';
test.describe('Smoke Tests', () => {
test('homepage loads', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Ponderants/);
});
test('chat page loads', async ({ page }) => {
await page.goto('/chat');
// Check for chat interface element
await expect(page.locator('textarea, input[type="text"]').first()).toBeVisible({ timeout: 10000 });
});
test('galaxy page loads', async ({ page }) => {
await page.goto('/galaxy');
// Check for canvas or empty state
const canvasOrEmpty = page.locator('canvas, [data-testid="empty-state"]').first();
await expect(canvasOrEmpty).toBeVisible({ timeout: 10000 });
});
});