nxtgauge-frontend-solid/tests/e2e/ai-chat-widget.spec.ts
Tracewebstudio Dev 0d63bb304e Add comprehensive test infrastructure and AI guardrails
- Add Vitest unit tests for AiChatWidget component
- Add Playwright E2E tests: ai-chat-widget, api, security, guardrails
- Add AI guardrails tests validating no phone/email leaks from Ollama
- Add security tests: auth, rate limiting, input validation, token handling
- Add API tests for AI endpoints and authentication
- Fix playwright.config.ts reporter path conflict
- Update CompanyJobsPage with AI generate buttons (orange icon, loading state)
- Fix AiChatWidget accessibility (role=dialog, aria-label, aria-modal)
- Add app.css spin animation for AI loading spinner
- Add Gitea Actions workflow for nightly CI tests
- Add TESTING.md documentation
2026-05-01 02:54:25 +02:00

118 lines
No EOL
4 KiB
TypeScript

import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test.describe("AI Chat Widget", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
});
test("widget button is visible and opens chat panel", async ({ page }) => {
const widgetButton = page.locator('button[title="AI Assistant"]');
await expect(widgetButton).toBeVisible();
await widgetButton.click();
await page.waitForTimeout(500);
const chatWindow = page.locator('[role="dialog"]').first();
await expect(chatWindow).toBeVisible();
});
test("widget sends message and shows user message", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
const widgetButton = page.locator('button[title="AI Assistant"]');
await widgetButton.click();
await page.waitForTimeout(300);
const input = page.locator('input[aria-label="Chat message input"]');
await expect(input).toBeVisible();
await input.fill("Hello, what can you help me with?");
await page.keyboard.press("Enter");
await page.waitForTimeout(500);
const userMessage = page.locator('text="Hello, what can you help me with?"').first();
await expect(userMessage).toBeVisible({ timeout: 5000 });
});
test("widget does not send empty message", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
const widgetButton = page.locator('button[title="AI Assistant"]');
await widgetButton.click();
await page.waitForTimeout(300);
const input = page.locator('input[aria-label="Chat message input"]');
await input.fill(" ");
await page.keyboard.press("Enter");
await page.waitForTimeout(500);
const messages = page.locator('[role="log"]');
const count = await messages.count();
expect(count).toBeLessThanOrEqual(1);
});
test("widget does not send message while loading", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
await page.route("**/api/gateway/api/ai/chat/message", async (route) => {
await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ message: "Response", conversation_id: "test", intent: "general", confidence: 0.9 }) });
await page.waitForTimeout(5000);
});
const widgetButton = page.locator('button[title="AI Assistant"]');
await widgetButton.click();
await page.waitForTimeout(300);
const input = page.locator('input[aria-label="Chat message input"]');
await input.fill("Test message");
await page.keyboard.press("Enter");
await page.waitForTimeout(100);
await input.fill("Second message");
await page.keyboard.press("Enter");
await page.waitForTimeout(6000);
const messages = page.locator('[role="log"]');
const count = await messages.count();
expect(count).toBeLessThanOrEqual(2);
});
test("chat widget has no critical accessibility violations", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
const widgetButton = page.locator('button[title="AI Assistant"]');
await widgetButton.click();
await page.waitForTimeout(500);
const dialog = page.locator('[role="dialog"]');
await expect(dialog).toBeVisible();
const results = await new AxeBuilder({ page }).analyze();
const criticalViolations = results.violations.filter(
(v: { impact: string }) => v.impact === "critical"
);
expect(criticalViolations).toEqual([]);
});
test("widget close button works", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
const widgetButton = page.locator('button[title="AI Assistant"]');
await widgetButton.click();
await page.waitForTimeout(300);
const closeButton = page.locator('button[aria-label="Close chat"]');
await closeButton.click();
await page.waitForTimeout(300);
const chatWindow = page.locator('[role="dialog"]');
await expect(chatWindow).not.toBeVisible();
});
});