Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

1.6 KB
Raw Blame
import type { Page } from "playwright/test";
import { chromium, expect } from "playwright/test";
import { inject, it as base } from "vitest";

import { createTestUser } from "./api";
import { getTrpcClient } from "./trpc";

export const it = base.extend<{ page: Page }>({
  // Vitest requires destructuring, even when no other fixtures are needed.
  // oxlint-disable-next-line no-empty-pattern
  page: async ({}, use) => {
    const browser = await chromium.launch();
    try {
      const page = await browser.newPage({
        baseURL: `http://localhost:${inject("karakeepPort")}`,
        viewport: { width: 1440, height: 900 },
        locale: "en-US",
      });
      page.setDefaultTimeout(10000);
      await use(page);
    } finally {
      await browser.close();
    }
  },
});

export async function signIn(page: Page, email: string) {
  await page.goto("/signin");
  await page.getByLabel("Email", { exact: true }).fill(email);
  await page.getByLabel("Password", { exact: true }).fill("test1234");
  await page.getByRole("button", { name: "Sign In", exact: true }).click();
  // Signing in verifies the password and then redirects through / to the
  // dashboard. While other test files are hashing passwords for their users,
  // this can take well over the default 5s expect timeout.
  await expect(page).toHaveURL(/\/dashboard\/bookmarks$/, { timeout: 30000 });
}

export async function createWebTestUser() {
  const trpc = getTrpcClient(await createTestUser());
  const { email } = await trpc.users.whoami.query();
  if (!email) {
    throw new Error("The test user must have an email address");
  }
  return { trpc, email };
}