/ opencodehub / tests / e2e / auth-register.spec.ts
Swadhin Biswas test(e2e): fix 19 failing Playwright tests + a11y/UX/accessibility polish · 6/4/2026
aa23026
31 lines · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { expect, test } from "@playwright/test";

test.describe("Authentication - Register", () => {
  test("register page loads", async ({ page }) => {
    await page.goto("/register");
    await expect(page.locator("form")).toBeVisible();
  });

  test("shows validation errors for empty form", async ({ page }) => {
    await page.goto("/register");
    // HTML5 native validation prevents submit, so required inputs must exist
    const requiredInputs = page.locator("input[required]");
    await expect(requiredInputs.first()).toBeVisible();
    expect(await requiredInputs.count()).toBeGreaterThan(0);
  });

  test("register with valid data", async ({ page }) => {
    const ts = Date.now();
    await page.goto("/register");
    await page.fill('input[name="username"]', `e2euser${ts}`);
    await page.fill('input[name="email"]', `e2e${ts}@test.com`);
    await page.fill('input[name="password"]', `Test1234!`);
    if (await page.locator('input[name="displayName"]').isVisible()) {
      await page.fill('input[name="displayName"]', `E2E User ${ts}`);
    }
    await page.click('button[type="submit"]');
    // Should redirect to dashboard or show success
    await page.waitForURL(/\/(dashboard|explore|\/)/, { timeout: 10000 });
  });
});