/ opencodehub / tests / e2e / auth-login.spec.ts
Swadhin Biswas test(e2e): fix 19 failing Playwright tests + a11y/UX/accessibility polish · 6/4/2026
aa23026
53 lines · 1.6 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expect, test } from "@playwright/test";

test.describe("Authentication - Login", () => {
  test("login page loads", async ({ page }) => {
    await page.goto("/login");
    await expect(page.locator("form")).toBeVisible();
    await expect(
      page
        .locator(
          'input[name="login"], input[name="username"], input[type="text"]',
        )
        .first(),
    ).toBeVisible();
    await expect(
      page.locator('input[name="password"], input[type="password"]').first(),
    ).toBeVisible();
  });

  test("shows error for invalid credentials", async ({ page }) => {
    await page.goto("/login");
    await page.fill(
      'input[name="login"], input[name="username"], input[type="text"]',
      "nonexistent_user",
    );
    await page.fill(
      'input[name="password"], input[type="password"]',
      "wrongpassword",
    );
    await page.click('button[type="submit"]');
    await expect(
      page
        .locator("text=Invalid")
        .or(page.locator("text=incorrect"))
        .or(page.locator("[role=alert]"))
        .first(),
    ).toBeVisible({ timeout: 5000 });
  });

  test("has link to register page", async ({ page }) => {
    await page.goto("/login");
    const registerLink = page.locator('a[href*="register"]').first();
    await expect(registerLink).toBeVisible();
  });

  test("has link to forgot password", async ({ page }) => {
    await page.goto("/login");
    const forgotLink = page.locator('a[href*="forgot"], a[href*="reset"]');
    if (await forgotLink.isVisible()) {
      await expect(forgotLink).toBeVisible();
    }
  });
});