fix(m4): plans page - correct API fields (speedDownMbps/speedUpMbps/monthlyPrice)

This commit is contained in:
root
2026-03-26 10:11:16 +00:00
parent eebdf21505
commit b0c68ae562
2 changed files with 98 additions and 79 deletions

View File

@@ -5,75 +5,90 @@ test.describe('Plans', () => {
test.beforeEach(async ({ page }) => {
await login(page);
await page.goto('/plans');
await page.waitForURL(/\/plans/);
await page.waitForLoadState('networkidle');
});
test('plans page renders with header and table', async ({ page }) => {
await expect(page.locator('h1:has-text("Plans")')).toBeVisible();
await expect(page.locator('table')).toBeVisible();
await expect(page.locator('th:has-text("Name")')).toBeVisible();
await expect(page.locator('th:has-text("Type")')).toBeVisible();
await expect(page.locator('[data-testid="btn-add-plan"]')).toBeVisible();
});
test('plans list loads rows from API', async ({ page }) => {
// Wait for at least one row (demo data has 5 plans)
await expect(page.locator('[data-testid="plan-row"]').first()).toBeVisible({ timeout: 10000 });
const count = await page.locator('[data-testid="plan-row"]').count();
// Wait for data to load
await page.waitForTimeout(3000);
const rows = page.locator('[data-testid="plan-row"]');
const count = await rows.count();
// Demo tenant has seeded plans
expect(count).toBeGreaterThan(0);
});
test('add plan modal opens and submits', async ({ page }) => {
// Open create modal
await page.click('[data-testid="btn-add-plan"]');
await expect(page.locator('[data-testid="input-plan-name"]')).toBeVisible();
// Fill form with correct numeric fields
// Modal should appear
await expect(page.locator('[data-testid="modal-create-plan"]')).toBeVisible({ timeout: 5000 });
// Fill form with real API fields
const planName = `E2E Plan ${Date.now()}`;
await page.fill('[data-testid="input-plan-name"]', planName);
await page.selectOption('[data-testid="select-plan-type"]', 'PREPAID');
await page.fill('[data-testid="input-plan-speed-down"]', '25');
await page.fill('[data-testid="input-plan-speed-up"]', '10');
await page.fill('[data-testid="input-plan-price"]', '999');
await page.fill('[data-testid="input-plan-speed-down"]', '50');
await page.fill('[data-testid="input-plan-speed-up"]', '20');
await page.fill('[data-testid="input-plan-price"]', '1499');
await page.fill('[data-testid="input-plan-description"]', 'E2E test plan');
// Submit
await page.click('[data-testid="btn-submit-create"]');
// Modal should close after successful API call
await expect(page.locator('[data-testid="input-plan-name"]')).not.toBeVisible({ timeout: 10000 });
// Wait for modal to close (API call + state update)
await expect(page.locator('[data-testid="modal-create-plan"]')).not.toBeVisible({ timeout: 10000 });
// New plan should appear in table
await expect(page.locator(`text=${planName}`)).toBeVisible({ timeout: 10000 });
// New plan should appear in the table
await page.waitForTimeout(1000);
await expect(page.locator(`text=${planName}`)).toBeVisible({ timeout: 5000 });
});
test('edit plan modal opens and submits', async ({ page }) => {
// Wait for rows
await expect(page.locator('[data-testid="plan-row"]').first()).toBeVisible({ timeout: 10000 });
await page.waitForTimeout(2000);
const editBtns = page.locator('[data-testid="btn-edit-plan"]');
const count = await editBtns.count();
expect(count).toBeGreaterThan(0);
// Click first edit button
await page.locator('[data-testid="btn-edit-plan"]').first().click();
await editBtns.first().click();
// Edit modal should open
await expect(page.locator('[data-testid="modal-edit-plan"]')).toBeVisible({ timeout: 5000 });
await expect(page.locator('[data-testid="input-edit-name"]')).toBeVisible();
// Edit the name
await page.fill('[data-testid="input-edit-name"]', 'Updated Plan Name');
// Change download speed
await page.fill('[data-testid="input-edit-speed-down"]', '100');
// Submit
await page.click('[data-testid="btn-submit-edit"]');
// Modal should close
await expect(page.locator('[data-testid="input-edit-name"]')).not.toBeVisible({ timeout: 10000 });
await expect(page.locator('[data-testid="modal-edit-plan"]')).not.toBeVisible({ timeout: 10000 });
});
test('delete plan shows confirmation dialog', async ({ page }) => {
// Wait for rows
await expect(page.locator('[data-testid="plan-row"]').first()).toBeVisible({ timeout: 10000 });
test('delete plan shows confirmation and cancels', async ({ page }) => {
await page.waitForTimeout(2000);
const deleteBtns = page.locator('[data-testid="btn-delete-plan"]');
const count = await deleteBtns.count();
expect(count).toBeGreaterThan(0);
// Click first delete button
await page.locator('[data-testid="btn-delete-plan"]').first().click();
// Click last delete button (to avoid deleting seeded data, target the E2E-created plan)
await deleteBtns.last().click();
// Confirmation modal should appear
await expect(page.locator('[data-testid="modal-delete-plan"]')).toBeVisible({ timeout: 5000 });
await expect(page.locator('[data-testid="btn-confirm-delete"]')).toBeVisible();
await expect(page.locator('[data-testid="btn-cancel-delete"]')).toBeVisible();
// Cancel — don't actually delete
// Cancel the delete
await page.click('[data-testid="btn-cancel-delete"]');
await expect(page.locator('[data-testid="btn-confirm-delete"]')).not.toBeVisible();
// Modal should close
await expect(page.locator('[data-testid="modal-delete-plan"]')).not.toBeVisible({ timeout: 5000 });
});
});