arbret/frontend/e2e/price-history.spec.ts
2025-12-24 23:52:52 +01:00

41 lines
1.6 KiB
TypeScript

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 and use price history page, regular user cannot access", async ({
page,
}) => {
// Test admin access and navigation
await clearAuth(page);
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
await expect(page).toHaveURL("/admin/trades");
// Test navigation link
await expect(page.getByRole("link", { name: "Prices" })).toBeVisible();
await page.getByRole("link", { name: "Prices" }).click();
await expect(page).toHaveURL("/admin/price-history");
// Test page structure
await expect(page.locator("h2")).toContainText("Bitcoin Price History");
await expect(page.locator("table")).toBeVisible();
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeVisible();
// Test fetching price
await page.getByRole("button", { name: "Fetch Now" }).click();
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeEnabled({
timeout: 10000,
});
// Verify fetched data
await expect(page.locator("table tbody")).toContainText("bitfinex");
await expect(page.locator("table tbody")).toContainText("BTC/EUR");
const priceCell = page.locator("table tbody tr td").nth(2);
await expect(priceCell).toContainText("€");
// Test regular user cannot access
await clearAuth(page);
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
await page.goto("/admin/price-history");
await expect(page).toHaveURL("/exchange");
});
});