fix(tests): improve response handling and session management in import tests

This commit is contained in:
GitHub Actions
2026-03-01 05:11:18 +00:00
parent 94356e7d4e
commit 404aa92ea0
4 changed files with 9 additions and 27 deletions

View File

@@ -213,9 +213,10 @@ test.describe('Caddy Import - Firefox-Specific @firefox-only', () => {
await textarea.fill('cors-test.example.com { reverse_proxy localhost:3000 }');
const parseButton = page.getByRole('button', { name: /parse|review/i });
const responsePromise = page.waitForResponse((r) => r.url().includes('/api/v1/import/upload'), { timeout: 5000 });
await parseButton.click();
await responsePromise;
// Wait for response
await page.waitForResponse((r) => r.url().includes('/api/v1/import/upload'), { timeout: 5000 });
// Verify no CORS issues
expect(corsIssues).toHaveLength(0);

View File

@@ -231,10 +231,6 @@ async function loginWithSetupCredentials(page: Page): Promise<void> {
}
export async function resetImportSession(page: Page): Promise<void> {
// Unconditional cancel covers sessions in any state (reviewing, pending, etc.)
await page.request.delete('/api/v1/import/cancel').catch(() => null);
await page.request.post('/api/v1/import/cancel').catch(() => null);
try {
if (!page.url().includes(IMPORT_PAGE_PATH)) {
await page.goto(IMPORT_PAGE_PATH, { waitUntil: 'domcontentloaded' });
@@ -333,11 +329,8 @@ export async function ensureImportFormReady(page: Page): Promise<void> {
let textareaVisible = await textarea.isVisible().catch(() => false);
if (!textareaVisible) {
const pendingSessionVisible = await page.getByText(/pending import session/i).first().isVisible().catch(() => false);
const reviewTableVisible = await page.getByTestId('import-review-table').isVisible().catch(() => false);
if (pendingSessionVisible || reviewTableVisible) {
diagnosticLog(`[Diag:import-ready] stale session detected (pending=${pendingSessionVisible}, review=${reviewTableVisible}), canceling to restore textarea`);
await page.request.delete('/api/v1/import/cancel').catch(() => null);
await page.request.post('/api/v1/import/cancel').catch(() => null);
if (pendingSessionVisible) {
diagnosticLog('[Diag:import-ready] pending import session detected, canceling to restore textarea');
await clearPendingImportSession(page);
await page.goto(IMPORT_PAGE_PATH, { waitUntil: 'domcontentloaded' });
await assertNoAuthRedirect(page, 'ensureImportFormReady after pending-session reset');

View File

@@ -521,7 +521,7 @@ test.describe('Dashboard', () => {
* Test: Dashboard loads within acceptable time
*/
test('should load dashboard within 5 seconds', async ({ page }) => {
const maxDashboardLoadMs = 8000;
const maxDashboardLoadMs = 5000;
const startTime = Date.now();
const deadline = startTime + maxDashboardLoadMs;
const remainingTime = () => Math.max(0, deadline - Date.now());

View File

@@ -17,22 +17,14 @@ import { waitForLoadingComplete } from '../utils/wait-helpers';
test.describe('Navigation', () => {
test.beforeEach(async ({ page, adminUser }) => {
try {
await loginUser(page, adminUser);
} catch {
// Transient 401 under full-suite load — stored auth state is still valid
}
await loginUser(page, adminUser);
await waitForLoadingComplete(page);
await page.goto('/');
await waitForLoadingComplete(page);
if (page.url().includes('/login')) {
try {
await loginUser(page, adminUser);
} catch {
// Fall through — page retains setup auth state from storageState fixture
}
await loginUser(page, adminUser);
await waitForLoadingComplete(page);
await page.goto('/');
await waitForLoadingComplete(page);
@@ -50,11 +42,7 @@ test.describe('Navigation', () => {
await test.step('Verify navigation menu exists', async () => {
const nav = page.getByRole('navigation');
if (!await nav.first().isVisible().catch(() => false)) {
try {
await loginUser(page, adminUser);
} catch {
// Stored auth state fallback
}
await loginUser(page, adminUser);
await waitForLoadingComplete(page);
await page.goto('/');
await waitForLoadingComplete(page);