import { chromium, expect } from "@playwright/test"; import { describe, test } from "vitest"; import { createHomarrContainer } from "./shared/create-homarr-container"; import { createSqliteDbFileAsync } from "./shared/e2e-db"; import { loginAsync } from "./shared/login"; import { startMockApiServerAsync } from "./shared/mock-api-server"; import { seedAdminUserAsync } from "./shared/seed-admin-user"; const adminCredentials = { username: "admin", password: "Comp(exP4sswOrd", }; const initialTemplate = '{data.title}{data.status}'; const updatedTemplate = '{data.title}{data.value}'; describe("Custom JSX custom widgets", () => { test("reliably creates, previews, and edits a customJsx widget", async () => { const mockApi = await startMockApiServerAsync({ title: "E2E Widget", status: "online", value: 42, }); const { db, localMountPath } = await createSqliteDbFileAsync(); await seedAdminUserAsync(db, adminCredentials); const homarrContainer = await createHomarrContainer({ environment: { AUTH_PROVIDERS: "credentials", }, mounts: { "/appdata": localMountPath, }, }).start(); const baseUrl = `http://${homarrContainer.getHost()}:${homarrContainer.getMappedPort(7575)}`; const browser = await chromium.launch(); const destination = "/manage/custom-widgets/new"; try { for (const attempt of [1, 2, 3]) { const context = await browser.newContext(); const page = await context.newPage(); const widgetName = `E2E Custom JSX ${attempt}`; try { await loginAsync({ page, baseUrl, credentials: adminCredentials, destination }); await expect(page.getByRole("textbox", { name: "Name" })).toBeVisible({ timeout: 30_000 }); await page.getByRole("textbox", { name: "Name" }).fill(widgetName); await page.getByRole("textbox", { name: "URL", exact: true }).fill(`${mockApi.url}/status`); await page.getByRole("combobox", { name: "Display Type" }).click(); await page.getByRole("option", { name: "Custom JSX" }).click(); await page.getByLabel("JSX Template").fill(initialTemplate); await page.getByRole("button", { name: "Test" }).first().click(); const previewPanel = page.locator(".mantine-Card-root").filter({ hasText: "Preview" }); await expect(previewPanel.getByRole("heading", { name: "E2E Widget" }).first()).toBeVisible({ timeout: 15_000, }); const editNavigation = page.waitForURL((url) => url.pathname.startsWith("/manage/custom-widgets/edit/"), { timeout: 15_000, waitUntil: "domcontentloaded", }); await page.getByRole("button", { name: "Create" }).first().click(); await editNavigation; await expect(page.getByText(`Widget "${widgetName}" created successfully.`)).toBeVisible({ timeout: 15_000, }); await expect(page.getByLabel("JSX Template")).toHaveValue(initialTemplate); await page.getByLabel("JSX Template").fill(updatedTemplate); await expect(page.getByLabel("JSX Template")).toHaveValue(updatedTemplate); await page.getByRole("button", { name: "Save" }).first().click(); await expect(page.getByText(`Widget "${widgetName}" updated successfully.`)).toBeVisible({ timeout: 15_000, }); await expect(page.getByLabel("JSX Template")).toHaveValue(updatedTemplate); } finally { await context.close(); } } } finally { await browser.close(); await homarrContainer.stop(); await mockApi.close(); } }, 180_000); });