Fix e2e tests to wait for API calls and form rendering
- Wait for GET /api/admin/pricing response before checking elements - Wait for heading to be visible before interacting with form - Wait for inputs to be visible before reading values - This ensures the page has finished loading before tests run
This commit is contained in:
parent
c9efcf79ff
commit
1874c3a057
1 changed files with 47 additions and 10 deletions
|
|
@ -26,7 +26,14 @@ test.describe("Admin Pricing Page - Admin Access", () => {
|
||||||
// Test page access and structure
|
// Test page access and structure
|
||||||
await page.goto("/admin/pricing");
|
await page.goto("/admin/pricing");
|
||||||
await expect(page).toHaveURL("/admin/pricing");
|
await expect(page).toHaveURL("/admin/pricing");
|
||||||
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible();
|
|
||||||
|
// Wait for API call to complete and form to render
|
||||||
|
await page.waitForResponse(
|
||||||
|
(resp) => resp.url().includes("/api/admin/pricing") && resp.request().method() === "GET"
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
await expect(page.getByText("Configure premium pricing and trade amount limits")).toBeVisible();
|
await expect(page.getByText("Configure premium pricing and trade amount limits")).toBeVisible();
|
||||||
|
|
||||||
// Check all form fields are present (using text + input selector since labels aren't associated)
|
// Check all form fields are present (using text + input selector since labels aren't associated)
|
||||||
|
|
@ -47,11 +54,17 @@ test.describe("Admin Pricing Page - Admin Access", () => {
|
||||||
test("can view current pricing configuration", async ({ page }) => {
|
test("can view current pricing configuration", async ({ page }) => {
|
||||||
await page.goto("/admin/pricing");
|
await page.goto("/admin/pricing");
|
||||||
|
|
||||||
// Wait for data to load
|
// Wait for API call to complete and form to render
|
||||||
await page.waitForLoadState("networkidle");
|
await page.waitForResponse(
|
||||||
|
(resp) => resp.url().includes("/api/admin/pricing") && resp.request().method() === "GET"
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
// All input fields should have values (not empty)
|
// Wait for inputs to be visible
|
||||||
const inputs = page.locator('input[type="number"]');
|
const inputs = page.locator('input[type="number"]');
|
||||||
|
await expect(inputs.first()).toBeVisible({ timeout: 5000 });
|
||||||
const count = await inputs.count();
|
const count = await inputs.count();
|
||||||
expect(count).toBeGreaterThan(0);
|
expect(count).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
|
@ -65,10 +78,18 @@ test.describe("Admin Pricing Page - Admin Access", () => {
|
||||||
|
|
||||||
test("can update pricing configuration", async ({ page }) => {
|
test("can update pricing configuration", async ({ page }) => {
|
||||||
await page.goto("/admin/pricing");
|
await page.goto("/admin/pricing");
|
||||||
await page.waitForLoadState("networkidle");
|
|
||||||
|
|
||||||
// Get current values (first input is premium_buy)
|
// Wait for API call to complete and form to render
|
||||||
|
await page.waitForResponse(
|
||||||
|
(resp) => resp.url().includes("/api/admin/pricing") && resp.request().method() === "GET"
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for inputs to be visible
|
||||||
const inputs = page.locator('input[type="number"]');
|
const inputs = page.locator('input[type="number"]');
|
||||||
|
await expect(inputs.first()).toBeVisible({ timeout: 5000 });
|
||||||
const premiumBuyInput = inputs.nth(0);
|
const premiumBuyInput = inputs.nth(0);
|
||||||
const currentBuyValue = await premiumBuyInput.inputValue();
|
const currentBuyValue = await premiumBuyInput.inputValue();
|
||||||
const newBuyValue = currentBuyValue === "5" ? "6" : "5";
|
const newBuyValue = currentBuyValue === "5" ? "6" : "5";
|
||||||
|
|
@ -107,10 +128,18 @@ test.describe("Admin Pricing Page - Admin Access", () => {
|
||||||
|
|
||||||
test("validation prevents invalid values", async ({ page }) => {
|
test("validation prevents invalid values", async ({ page }) => {
|
||||||
await page.goto("/admin/pricing");
|
await page.goto("/admin/pricing");
|
||||||
await page.waitForLoadState("networkidle");
|
|
||||||
|
|
||||||
// Test premium range validation (should be -100 to 100)
|
// Wait for API call to complete and form to render
|
||||||
|
await page.waitForResponse(
|
||||||
|
(resp) => resp.url().includes("/api/admin/pricing") && resp.request().method() === "GET"
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for inputs to be visible
|
||||||
const inputs = page.locator('input[type="number"]');
|
const inputs = page.locator('input[type="number"]');
|
||||||
|
await expect(inputs.first()).toBeVisible({ timeout: 5000 });
|
||||||
const premiumBuyInput = inputs.nth(0); // First input is premium_buy
|
const premiumBuyInput = inputs.nth(0); // First input is premium_buy
|
||||||
await premiumBuyInput.clear();
|
await premiumBuyInput.clear();
|
||||||
await premiumBuyInput.fill("150"); // Invalid: > 100
|
await premiumBuyInput.fill("150"); // Invalid: > 100
|
||||||
|
|
@ -149,10 +178,18 @@ test.describe("Admin Pricing Page - Admin Access", () => {
|
||||||
|
|
||||||
test("form fields update correctly when values change", async ({ page }) => {
|
test("form fields update correctly when values change", async ({ page }) => {
|
||||||
await page.goto("/admin/pricing");
|
await page.goto("/admin/pricing");
|
||||||
await page.waitForLoadState("networkidle");
|
|
||||||
|
|
||||||
// Small trade threshold is the 3rd input (after premium_buy and premium_sell)
|
// Wait for API call to complete and form to render
|
||||||
|
await page.waitForResponse(
|
||||||
|
(resp) => resp.url().includes("/api/admin/pricing") && resp.request().method() === "GET"
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("heading", { name: "Pricing Configuration" })).toBeVisible({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for inputs to be visible
|
||||||
const inputs = page.locator('input[type="number"]');
|
const inputs = page.locator('input[type="number"]');
|
||||||
|
await expect(inputs.first()).toBeVisible({ timeout: 5000 });
|
||||||
const smallTradeThresholdInput = inputs.nth(2);
|
const smallTradeThresholdInput = inputs.nth(2);
|
||||||
const currentThreshold = await smallTradeThresholdInput.inputValue();
|
const currentThreshold = await smallTradeThresholdInput.inputValue();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue