Fix e2e tests for pricing page

- Update selectors to use input indices instead of labels (labels not associated)
- Fix validation error status expectation (400 instead of 422)
- Update exchange.spec.ts to check new config fields (eur_min_buy, etc.)
This commit is contained in:
counterweight 2025-12-26 20:59:10 +01:00
parent 2ee27cf5b2
commit 7f547d667d
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 173 additions and 36 deletions

View file

@ -29,15 +29,16 @@ test.describe("Admin Pricing Page - Admin Access", () => {
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible();
await expect(page.getByText("Configure premium pricing and trade amount limits")).toBeVisible();
// Check all form fields are present
await expect(page.getByLabel(/Premium for BUY/i)).toBeVisible();
await expect(page.getByLabel(/Premium for SELL/i)).toBeVisible();
await expect(page.getByLabel(/Small Trade Threshold/i)).toBeVisible();
await expect(page.getByLabel(/Extra Premium for Small Trades/i)).toBeVisible();
await expect(page.getByLabel(/Minimum Amount.*BUY/i)).toBeVisible();
await expect(page.getByLabel(/Maximum Amount.*BUY/i)).toBeVisible();
await expect(page.getByLabel(/Minimum Amount.*SELL/i)).toBeVisible();
await expect(page.getByLabel(/Maximum Amount.*SELL/i)).toBeVisible();
// Check all form fields are present (using text + input selector since labels aren't associated)
await expect(page.getByText(/Premium for BUY/i)).toBeVisible();
await expect(page.locator('input[type="number"]').first()).toBeVisible();
await expect(page.getByText(/Premium for SELL/i)).toBeVisible();
await expect(page.getByText(/Small Trade Threshold/i)).toBeVisible();
await expect(page.getByText(/Extra Premium for Small Trades/i)).toBeVisible();
await expect(page.getByText(/Trade Amount Limits.*BUY/i)).toBeVisible();
await expect(page.getByText(/Minimum Amount/i).first()).toBeVisible();
await expect(page.getByText(/Maximum Amount/i).first()).toBeVisible();
await expect(page.getByText(/Trade Amount Limits.*SELL/i)).toBeVisible();
// Check save button is present
await expect(page.getByRole("button", { name: /Save Changes/i })).toBeVisible();
@ -54,11 +55,10 @@ test.describe("Admin Pricing Page - Admin Access", () => {
const count = await inputs.count();
expect(count).toBeGreaterThan(0);
// Check that premium fields have values
const premiumBuyInput = page.getByLabel(/Premium for BUY/i);
const premiumSellInput = page.getByLabel(/Premium for SELL/i);
const buyValue = await premiumBuyInput.inputValue();
const sellValue = await premiumSellInput.inputValue();
// Check that premium fields have values (inputs are after labels)
const inputs = page.locator('input[type="number"]');
const buyValue = await inputs.nth(0).inputValue(); // First input is premium_buy
const sellValue = await inputs.nth(1).inputValue(); // Second input is premium_sell
expect(buyValue).not.toBe("");
expect(sellValue).not.toBe("");
@ -68,8 +68,9 @@ test.describe("Admin Pricing Page - Admin Access", () => {
await page.goto("/admin/pricing");
await page.waitForLoadState("networkidle");
// Get current values
const premiumBuyInput = page.getByLabel(/Premium for BUY/i);
// Get current values (first input is premium_buy)
const inputs = page.locator('input[type="number"]');
const premiumBuyInput = inputs.nth(0);
const currentBuyValue = await premiumBuyInput.inputValue();
const newBuyValue = currentBuyValue === "5" ? "6" : "5";
@ -110,7 +111,8 @@ test.describe("Admin Pricing Page - Admin Access", () => {
await page.waitForLoadState("networkidle");
// Test premium range validation (should be -100 to 100)
const premiumBuyInput = page.getByLabel(/Premium for BUY/i);
const inputs = page.locator('input[type="number"]');
const premiumBuyInput = inputs.nth(0); // First input is premium_buy
await premiumBuyInput.clear();
await premiumBuyInput.fill("150"); // Invalid: > 100
@ -122,9 +124,10 @@ test.describe("Admin Pricing Page - Admin Access", () => {
// Should show validation error
await expect(page.getByText(/must be between.*-100.*100/i)).toBeVisible({ timeout: 2000 });
// Test min < max validation
const minBuyInput = page.getByLabel(/Minimum Amount.*BUY/i);
const maxBuyInput = page.getByLabel(/Maximum Amount.*BUY/i);
// Test min < max validation (inputs 4 and 5 are min/max buy)
const inputs = page.locator('input[type="number"]');
const minBuyInput = inputs.nth(4); // Min buy is 5th input (after 4 premium/threshold inputs)
const maxBuyInput = inputs.nth(5); // Max buy is 6th input
const currentMin = await minBuyInput.inputValue();
const currentMax = await maxBuyInput.inputValue();
@ -150,7 +153,9 @@ test.describe("Admin Pricing Page - Admin Access", () => {
await page.goto("/admin/pricing");
await page.waitForLoadState("networkidle");
const smallTradeThresholdInput = page.getByLabel(/Small Trade Threshold/i);
// Small trade threshold is the 3rd input (after premium_buy and premium_sell)
const inputs = page.locator('input[type="number"]');
const smallTradeThresholdInput = inputs.nth(2);
const currentThreshold = await smallTradeThresholdInput.inputValue();
// Update threshold
@ -278,7 +283,7 @@ test.describe("Admin Pricing API", () => {
eur_max_sell: 300000,
},
});
expect(invalidResponse.status()).toBe(422);
expect(invalidResponse.status()).toBe(400); // BadRequestError returns 400
// Restore original values
await request.put(`${getBackendUrl()}/api/admin/pricing`, {