2025-12-22 15:56:12 +01:00
|
|
|
import { test, expect } from "@playwright/test";
|
|
|
|
|
import { clearAuth, loginUser, REGULAR_USER, ADMIN_USER } from "./helpers/auth";
|
|
|
|
|
|
|
|
|
|
test.describe("Price History - E2E", () => {
|
2025-12-26 11:38:17 +01:00
|
|
|
test.beforeEach(async ({ context }) => {
|
|
|
|
|
await context.addInitScript(() => {
|
|
|
|
|
window.localStorage.setItem("arbret-locale", "en");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
test("admin can view and use price history page, regular user cannot access", async ({
|
|
|
|
|
page,
|
|
|
|
|
}) => {
|
|
|
|
|
// Test admin access and navigation
|
2025-12-22 15:56:12 +01:00
|
|
|
await clearAuth(page);
|
|
|
|
|
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
2025-12-24 23:52:52 +01:00
|
|
|
await expect(page).toHaveURL("/admin/trades");
|
2025-12-22 15:56:12 +01:00
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
// Test navigation link
|
|
|
|
|
await expect(page.getByRole("link", { name: "Prices" })).toBeVisible();
|
|
|
|
|
await page.getByRole("link", { name: "Prices" }).click();
|
2025-12-22 15:56:12 +01:00
|
|
|
await expect(page).toHaveURL("/admin/price-history");
|
|
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
// Test page structure
|
2025-12-22 15:56:12 +01:00
|
|
|
await expect(page.locator("h2")).toContainText("Bitcoin Price History");
|
|
|
|
|
await expect(page.locator("table")).toBeVisible();
|
|
|
|
|
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeVisible();
|
|
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
// Test fetching price
|
2025-12-22 15:56:12 +01:00
|
|
|
await page.getByRole("button", { name: "Fetch Now" }).click();
|
|
|
|
|
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeEnabled({
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
// Verify fetched data
|
2025-12-22 15:56:12 +01:00
|
|
|
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("€");
|
|
|
|
|
|
2025-12-24 23:52:52 +01:00
|
|
|
// Test regular user cannot access
|
2025-12-22 15:56:12 +01:00
|
|
|
await clearAuth(page);
|
|
|
|
|
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
|
|
|
|
await page.goto("/admin/price-history");
|
2025-12-22 21:42:42 +01:00
|
|
|
await expect(page).toHaveURL("/exchange");
|
2025-12-22 15:56:12 +01:00
|
|
|
});
|
|
|
|
|
});
|