Bundles the prior autonomous-session output that was sitting unstaged: - Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances) - country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk after the per-subpath dynamic-import approach silently failed in webpack) - Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index, redirects (ocr to ai, reports to dashboard, invitations to users), docs/admin-ia-proposal.md - Per-template email tester (registry + endpoint + UI on Email admin page) - Cancel-document mode picker (delete-from-Documenso vs keep-for-audit) - Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers - Customize-widgets per-region sortables at xl+ (charts/rails/feed); single flat sortable below xl when the layout stacks; per-viewport saved orders - Audit doc updates capturing each shipped item - Lint fixes: react-compiler immutability in DonutChart (reduce instead of let-reassign), set-state-in-effect disables in CountryFlag and UploadForSigning preview-bytes effect, unused 'confirm' destructures in interest contract + reservation tabs, unescaped apostrophe in test-template card copy
259 lines
8.9 KiB
TypeScript
259 lines
8.9 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
||
import { login, navigateTo, PORT_SLUG } from './helpers';
|
||
|
||
test.describe('Error Recovery', () => {
|
||
test('form validation shows inline errors on empty client submit', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
await navigateTo(page, '/clients');
|
||
|
||
const newBtn = page.getByRole('button', { name: /new client/i }).first();
|
||
await expect(newBtn).toBeVisible({ timeout: 10_000 });
|
||
await newBtn.click();
|
||
|
||
// Wait for the sheet/dialog to open
|
||
await page.waitForSelector('[role="dialog"]', { state: 'visible', timeout: 5_000 });
|
||
const sheet = page.locator('[role="dialog"]');
|
||
|
||
// Submit the form without filling any required fields
|
||
const submitBtn = sheet.getByRole('button', { name: /create client/i });
|
||
if (await submitBtn.isVisible({ timeout: 5_000 }).catch(() => false)) {
|
||
await submitBtn.click();
|
||
await page.waitForTimeout(1_000);
|
||
|
||
// Validation errors should appear inline (red text / .text-destructive)
|
||
const errorMsg = page
|
||
.locator('.text-destructive')
|
||
.first()
|
||
.or(page.locator('[aria-invalid="true"]').first())
|
||
.or(page.locator('[class*="error"]').first());
|
||
|
||
const hasError = await errorMsg.isVisible({ timeout: 5_000 }).catch(() => false);
|
||
|
||
if (!hasError) {
|
||
// Some forms use aria-describedby for error messages
|
||
const ariaError = page.locator('[role="alert"]').first();
|
||
const hasAriaError = await ariaError.isVisible({ timeout: 3_000 }).catch(() => false);
|
||
expect(hasAriaError).toBeTruthy();
|
||
} else {
|
||
expect(hasError).toBeTruthy();
|
||
}
|
||
}
|
||
|
||
// Dismiss the sheet
|
||
await page.keyboard.press('Escape');
|
||
await page.waitForTimeout(500);
|
||
});
|
||
|
||
test('filling required fields clears errors and allows submit', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
await navigateTo(page, '/clients');
|
||
|
||
const newBtn = page.getByRole('button', { name: /new client/i }).first();
|
||
await expect(newBtn).toBeVisible({ timeout: 10_000 });
|
||
await newBtn.click();
|
||
|
||
await page.waitForSelector('[role="dialog"]', { state: 'visible', timeout: 5_000 });
|
||
const sheet = page.locator('[role="dialog"]');
|
||
|
||
// Trigger validation first
|
||
const submitBtn = sheet.getByRole('button', { name: /create client/i });
|
||
if (await submitBtn.isVisible({ timeout: 5_000 }).catch(() => false)) {
|
||
await submitBtn.click();
|
||
await page.waitForTimeout(500);
|
||
}
|
||
|
||
// Now fill the required fields
|
||
const nameInput = sheet.locator('input[name="fullName"]');
|
||
if (await nameInput.isVisible({ timeout: 3_000 }).catch(() => false)) {
|
||
await nameInput.fill(`Recovery Test Client ${Date.now()}`);
|
||
}
|
||
|
||
const emailInput = sheet.locator('input[name="contacts.0.value"]');
|
||
if (await emailInput.isVisible({ timeout: 3_000 }).catch(() => false)) {
|
||
await emailInput.fill('recovery@test.com');
|
||
}
|
||
|
||
// Re-submit - should succeed or at minimum no longer show fullName error
|
||
if (await submitBtn.isVisible({ timeout: 3_000 }).catch(() => false)) {
|
||
await submitBtn.click();
|
||
await page.waitForTimeout(2_000);
|
||
|
||
// Either the sheet closes (success) or errors remain for other fields
|
||
const sheetStillOpen = await sheet.isVisible({ timeout: 2_000 }).catch(() => false);
|
||
if (!sheetStillOpen) {
|
||
console.log(' ✓ Form submitted successfully after filling required fields');
|
||
}
|
||
}
|
||
|
||
expect(true).toBeTruthy();
|
||
});
|
||
|
||
test('invalid search input handled gracefully', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
await navigateTo(page, '/clients');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2_000);
|
||
|
||
// Find the search input - try multiple selectors
|
||
const searchInput = page
|
||
.locator('input[type="search"]')
|
||
.first()
|
||
.or(page.locator('input[placeholder*="search" i]').first())
|
||
.or(page.locator('[data-testid*="search"] input').first())
|
||
.or(page.getByRole('searchbox').first());
|
||
|
||
const searchVisible = await searchInput.isVisible({ timeout: 5_000 }).catch(() => false);
|
||
|
||
if (!searchVisible) {
|
||
console.log(' ℹ Search input not found - checking global search');
|
||
|
||
// Try the global search bar (usually a keyboard shortcut or top-bar icon)
|
||
const globalSearch = page
|
||
.locator('[class*="global-search"], [data-testid*="global"]')
|
||
.first()
|
||
.or(page.getByRole('button', { name: /search/i }).first());
|
||
|
||
if (await globalSearch.isVisible({ timeout: 3_000 }).catch(() => false)) {
|
||
await globalSearch.click();
|
||
await page.waitForTimeout(500);
|
||
}
|
||
}
|
||
|
||
const activeSearch = page
|
||
.locator('input[type="search"], input[placeholder*="search" i], [role="searchbox"]')
|
||
.first();
|
||
const isActive = await activeSearch.isVisible({ timeout: 3_000 }).catch(() => false);
|
||
|
||
if (!isActive) {
|
||
console.log(' ℹ No accessible search input found - skipping search validation');
|
||
expect(true).toBeTruthy();
|
||
return;
|
||
}
|
||
|
||
// Single character - should not crash
|
||
await activeSearch.fill('a');
|
||
await page.waitForTimeout(1_500);
|
||
|
||
const noError1 = await page
|
||
.getByText(/uncaught error|cannot read|undefined/i)
|
||
.isVisible({ timeout: 1_000 })
|
||
.catch(() => false);
|
||
expect(noError1).toBeFalsy();
|
||
|
||
// SQL injection payload - should not crash or expose DB errors
|
||
await activeSearch.fill("'; DROP TABLE clients; --");
|
||
await page.waitForTimeout(1_500);
|
||
|
||
const noSqlError = await page
|
||
.getByText(/sql|syntax error|pg error|database/i)
|
||
.isVisible({ timeout: 1_000 })
|
||
.catch(() => false);
|
||
expect(noSqlError).toBeFalsy();
|
||
|
||
// XSS payload - should be escaped, not executed
|
||
await activeSearch.fill('<script>alert("xss")</script>');
|
||
await page.waitForTimeout(1_000);
|
||
|
||
// The payload text itself (escaped) may appear, but no alert dialog
|
||
const hasAlertDialog = await page
|
||
.locator('[role="alertdialog"]')
|
||
.filter({ hasText: 'xss' })
|
||
.isVisible({ timeout: 1_000 })
|
||
.catch(() => false);
|
||
expect(hasAlertDialog).toBeFalsy();
|
||
|
||
// Clear the search
|
||
await activeSearch.clear();
|
||
await page.waitForTimeout(500);
|
||
|
||
// Page should still be functional
|
||
const body = await page
|
||
.locator('body')
|
||
.textContent()
|
||
.catch(() => '');
|
||
expect(body && body.length > 10).toBeTruthy();
|
||
});
|
||
|
||
test('404 page for invalid routes within port', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
|
||
await page.goto(`/${PORT_SLUG}/nonexistent-page`);
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2_000);
|
||
|
||
const is404 = await page
|
||
.getByText('404')
|
||
.isVisible({ timeout: 3_000 })
|
||
.catch(() => false);
|
||
const isNotFound = await page
|
||
.getByText(/not found/i)
|
||
.isVisible({ timeout: 3_000 })
|
||
.catch(() => false);
|
||
const isError = await page
|
||
.getByText(/error/i)
|
||
.isVisible({ timeout: 3_000 })
|
||
.catch(() => false);
|
||
|
||
// Page should not be a blank crash - must render something meaningful
|
||
const body = await page
|
||
.locator('body')
|
||
.textContent()
|
||
.catch(() => '');
|
||
const hasContent = body !== null && body.length > 20;
|
||
|
||
expect(is404 || isNotFound || isError || hasContent).toBeTruthy();
|
||
});
|
||
|
||
test('404 page for entirely unknown top-level route', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
|
||
await page.goto('/this-route-absolutely-does-not-exist-xyz123');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2_000);
|
||
|
||
const body = await page
|
||
.locator('body')
|
||
.textContent()
|
||
.catch(() => '');
|
||
|
||
// Should render something - not crash with empty body
|
||
expect(body && body.length > 10).toBeTruthy();
|
||
|
||
// Should not show a raw Next.js error page with stack traces
|
||
const hasStackTrace = await page
|
||
.getByText(/at Object|at Module|stack trace/i)
|
||
.isVisible({ timeout: 1_000 })
|
||
.catch(() => false);
|
||
expect(hasStackTrace).toBeFalsy();
|
||
});
|
||
|
||
test('navigating back from an error page works', async ({ page }) => {
|
||
await login(page, 'super_admin');
|
||
|
||
// Record the starting URL (dashboard)
|
||
const startUrl = page.url();
|
||
|
||
// Navigate to a bad route
|
||
await page.goto(`/${PORT_SLUG}/this-does-not-exist`);
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(1_000);
|
||
|
||
// Go back
|
||
await page.goBack();
|
||
await page.waitForTimeout(2_000);
|
||
|
||
// Should be back on a functional page
|
||
const returnUrl = page.url();
|
||
const body = await page
|
||
.locator('body')
|
||
.textContent()
|
||
.catch(() => '');
|
||
expect(body && body.length > 10).toBeTruthy();
|
||
// URL should differ from the 404 page (we went back)
|
||
expect(
|
||
returnUrl !==
|
||
`${page.url().split('//')[0]}//${page.url().split('//')[1]?.split('/')[0]}/${PORT_SLUG}/this-does-not-exist`,
|
||
).toBeTruthy();
|
||
});
|
||
});
|