From dd7bec6091b06287c2a3ba6696ddc8b80c90f937 Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 22 Dec 2025 15:56:12 +0100 Subject: [PATCH] test: add E2E tests for price history feature --- frontend/e2e/price-history.spec.ts | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 frontend/e2e/price-history.spec.ts diff --git a/frontend/e2e/price-history.spec.ts b/frontend/e2e/price-history.spec.ts new file mode 100644 index 0000000..10be191 --- /dev/null +++ b/frontend/e2e/price-history.spec.ts @@ -0,0 +1,74 @@ +import { test, expect } from "@playwright/test"; +import { clearAuth, loginUser, REGULAR_USER, ADMIN_USER } from "./helpers/auth"; + +test.describe("Price History - E2E", () => { + test("admin can view price history page", async ({ page }) => { + await clearAuth(page); + await loginUser(page, ADMIN_USER.email, ADMIN_USER.password); + + await page.goto("/admin/price-history"); + await expect(page).toHaveURL("/admin/price-history"); + + // Page title should be visible + await expect(page.locator("h2")).toContainText("Bitcoin Price History"); + + // Table should exist + await expect(page.locator("table")).toBeVisible(); + + // Fetch Now button should exist + await expect(page.getByRole("button", { name: "Fetch Now" })).toBeVisible(); + }); + + test("admin can manually fetch price from Bitfinex", async ({ page }) => { + await clearAuth(page); + await loginUser(page, ADMIN_USER.email, ADMIN_USER.password); + + await page.goto("/admin/price-history"); + await expect(page).toHaveURL("/admin/price-history"); + + // Click the Fetch Now button + await page.getByRole("button", { name: "Fetch Now" }).click(); + + // Wait for the button to become enabled again (fetch completed) + await expect(page.getByRole("button", { name: "Fetch Now" })).toBeEnabled({ + timeout: 10000, + }); + + // The table should now contain a record with bitfinex as source + await expect(page.locator("table tbody")).toContainText("bitfinex"); + + // Should have BTC/EUR pair + await expect(page.locator("table tbody")).toContainText("BTC/EUR"); + + // Price should be visible and formatted as EUR + // The price cell should contain a € symbol + const priceCell = page.locator("table tbody tr td").nth(2); + await expect(priceCell).toContainText("€"); + }); + + test("regular user cannot access price history page", async ({ page }) => { + await clearAuth(page); + await loginUser(page, REGULAR_USER.email, REGULAR_USER.password); + + // Try to navigate directly to the admin page + await page.goto("/admin/price-history"); + + // Should be redirected away (to "/" since fallbackRedirect is "/") + await expect(page).toHaveURL("/"); + }); + + test("price history shows in navigation for admin", async ({ page }) => { + await clearAuth(page); + await loginUser(page, ADMIN_USER.email, ADMIN_USER.password); + + // Admin should be on audit page by default + await expect(page).toHaveURL("/audit"); + + // Prices nav link should be visible + await expect(page.getByRole("link", { name: "Prices" })).toBeVisible(); + + // Click on Prices link + await page.getByRole("link", { name: "Prices" }).click(); + await expect(page).toHaveURL("/admin/price-history"); + }); +});