app/src/__tests__/e2e/canvas-mount.spec.js
CC Worker 79e7d4df9c test: add Playwright E2E tests for canvas mount, node navigation, transcription
Three spec files with beforeAll skip guards:
- Skip if VITE_TEST_TEACHER_EMAIL/PASSWORD not set
- Skip if dev server at 192.168.0.251:13000 unreachable
Tests exit 0 (3 skipped) when env is unconfigured.
Requires: live dev server + real teacher credentials to run live.
2026-05-31 23:49:41 +00:00

48 lines
1.6 KiB
JavaScript

import { test, expect, request } from '@playwright/test';
const BASE = process.env.PLAYWRIGHT_BASE_URL || 'http://192.168.0.251:13000';
const TEST_EMAIL = process.env.VITE_TEST_TEACHER_EMAIL;
const TEST_PASSWORD = process.env.VITE_TEST_TEACHER_PASSWORD;
async function serverReachable() {
try {
const ctx = await request.newContext();
const res = await ctx.get(BASE, { timeout: 3000 }).catch(() => null);
await ctx.dispose();
return Boolean(res);
} catch {
return false;
}
}
async function login(page) {
await page.goto(`${BASE}/login`);
await page.getByLabel('Email').fill(TEST_EMAIL);
await page.getByLabel('Password').fill(TEST_PASSWORD);
await page.getByRole('button', { name: 'Login' }).click();
await page.waitForURL((url) => /\/dashboard|\/node\//.test(url.pathname), { timeout: 15000 });
}
function skipIfUnconfigured() {
if (!TEST_EMAIL || !TEST_PASSWORD) test.skip(true, 'VITE_TEST_TEACHER_EMAIL / VITE_TEST_TEACHER_PASSWORD not set');
}
test.describe('Canvas mount', () => {
test.beforeAll(async () => {
skipIfUnconfigured();
const reachable = await serverReachable();
test.skip(!reachable, `Dev server not reachable at ${BASE}`);
});
test('login and show lesson canvas within 5s', async ({ page }) => {
await login(page);
const canvasVisible = await page
.locator('[data-testid="tldraw-canvas"], .tl-container')
.waitFor({ timeout: 10000 })
.then(() => true)
.catch(() => false);
expect(canvasVisible).toBe(true);
await expect(page.locator('[class*="error-state"], [data-testid="error"]').first()).toBeHidden({ timeout: 2000 }).catch(() => {});
});
});