Skip to content

Commit 70e2265

Browse files
chore: simplify chaos test payment dialog handling to prevent browser crashes
Replace waitForResponse/expect patterns with simpler isVisible checks to prevent cascading browser context failures during record payment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c73f5b2 commit 70e2265

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

e2e/tests/iteration/chaos-cycle.spec.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -314,35 +314,22 @@ async function opRecordPayment(page: Page, state: TestState) {
314314
const dateInput = dialog.getByLabel(/Payment Date/i);
315315
await dateInput.fill(isoDate(0)); // use today, not tomorrow
316316

317-
// Listen for the payment API response
318-
const paymentRespPromise = page.waitForResponse(
319-
(r) => r.url().includes("/payments") && r.request().method() === "POST",
320-
{ timeout: 15000 },
321-
).catch(() => null);
322-
323-
// Click record
317+
// Click record and wait for result
324318
await dialog.getByRole("button", { name: /Record Payment/i }).click();
325319

326-
const paymentResp = await paymentRespPromise;
327-
if (paymentResp && !paymentResp.ok()) {
328-
const body = await paymentResp.text().catch(() => "");
329-
state.operationLog.push(`RECORD_PAYMENT_API_ERROR: ${loan.description} status=${paymentResp.status()} body=${body.substring(0, 300)}`);
330-
}
320+
// Give the request time to complete
321+
await page.waitForTimeout(3000);
331322

332-
// Wait for dialog to close (success) or detect error
333-
try {
334-
await expect(dialog).toBeHidden({ timeout: 10000 });
323+
// Check if dialog closed (success) or is still open (error)
324+
const dialogStillVisible = await dialog.isVisible().catch(() => false);
325+
if (!dialogStillVisible) {
335326
state.operationLog.push(`RECORD_PAYMENT: ${loan.description} amount=${amount}`);
336-
} catch {
337-
// Check for toast errors
338-
const toastText = await page.locator("[data-testid='toast-error']").first().textContent().catch(() => "no toast");
339-
// Dialog didn't close — dismiss it
340-
const closeBtn = dialog.locator("[data-testid='modal-close']");
327+
} else {
328+
// Dialog still open — dismiss it
341329
const cancelBtn = dialog.getByRole("button", { name: "Cancel" });
342-
if (await closeBtn.isVisible()) await closeBtn.click();
343-
else if (await cancelBtn.isVisible()) await cancelBtn.click();
330+
if (await cancelBtn.isVisible().catch(() => false)) await cancelBtn.click();
344331
await page.waitForTimeout(500);
345-
state.operationLog.push(`RECORD_PAYMENT_FAILED: ${loan.description} amount=${amount} toast="${toastText}"`);
332+
state.operationLog.push(`RECORD_PAYMENT_FAILED: ${loan.description} amount=${amount}`);
346333
}
347334
}
348335

@@ -378,17 +365,16 @@ async function opRecordPartialPayment(page: Page, state: TestState) {
378365
await dateInput.fill(isoDate(1));
379366

380367
await dialog.getByRole("button", { name: /Record Payment/i }).click();
368+
await page.waitForTimeout(3000);
381369

382-
try {
383-
await expect(dialog).toBeHidden({ timeout: 10000 });
370+
const partialDialogVisible = await dialog.isVisible().catch(() => false);
371+
if (!partialDialogVisible) {
384372
state.operationLog.push(`PARTIAL_PAYMENT: ${loan.description} amount=${partialAmount} of ${payment.amount_due}`);
385-
} catch {
386-
const closeBtn = dialog.locator("[data-testid='modal-close']");
373+
} else {
387374
const cancelBtn = dialog.getByRole("button", { name: "Cancel" });
388-
if (await closeBtn.isVisible()) await closeBtn.click();
389-
else if (await cancelBtn.isVisible()) await cancelBtn.click();
375+
if (await cancelBtn.isVisible().catch(() => false)) await cancelBtn.click();
390376
await page.waitForTimeout(500);
391-
state.operationLog.push(`PARTIAL_PAYMENT_FAILED: ${loan.description} — dialog stayed open`);
377+
state.operationLog.push(`PARTIAL_PAYMENT_FAILED: ${loan.description}`);
392378
}
393379
}
394380

0 commit comments

Comments
 (0)