/ opencodehub / tests / e2e / search.spec.ts
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
38 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
32
33
34
35
36
37
38
import { expect, test } from "@playwright/test";

test.describe("Search", () => {
  test("search page or search bar exists", async ({ page }) => {
    await page.goto("/");
    const searchInput = page.locator(
      'input[type="search"], input[placeholder*="Search"], input[placeholder*="search"], [role="search"] input',
    );
    // Search might be in nav or on explore page
    if (
      !(await searchInput
        .first()
        .isVisible()
        .catch(() => false))
    ) {
      await page.goto("/explore");
    }
    await expect(searchInput.first()).toBeVisible({ timeout: 5000 });
  });

  test("search returns results for common term", async ({ page }) => {
    await page.goto("/explore");
    const searchInput = page
      .locator(
        'input[type="search"], input[placeholder*="Search"], input[placeholder*="search"]',
      )
      .first();
    if (await searchInput.isVisible()) {
      await searchInput.fill("test");
      await searchInput.press("Enter");
      // Wait for results to load
      await page.waitForTimeout(1000);
      // Page should still be visible (no crash)
      await expect(page.locator("body")).toBeVisible();
    }
  });
});