From ed5db3b000d11271ec495e86e71f9c3d23e7bd9e Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 2 Mar 2026 23:47:53 +0000 Subject: [PATCH] fix: use toHaveText to correctly await swap completion after testId migration getByTestId('swap-buy-button').waitFor({ state: 'visible' }) resolved immediately because the button is always rendered; only its text changes. Replace with expect(...).toHaveText('Buy KRK', { timeout: 60_000 }) to correctly gate on the button returning to its idle state. Co-Authored-By: Claude Sonnet 4.6 --- scripts/harb-evaluator/helpers/swap.ts | 2 +- tests/e2e/01-acquire-and-stake.spec.ts | 2 +- tests/e2e/02-max-stake-all-tax-rates.spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/harb-evaluator/helpers/swap.ts b/scripts/harb-evaluator/helpers/swap.ts index 83b93e1..86e27a8 100644 --- a/scripts/harb-evaluator/helpers/swap.ts +++ b/scripts/harb-evaluator/helpers/swap.ts @@ -97,7 +97,7 @@ export async function buyKrk(page: Page, ethAmount: string): Promise { try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); console.log('[swap] Swap in progress...'); - await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); + await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 }); console.log('[swap] Swap completed'); } catch { // Swap completed before the Submitting state could be observed diff --git a/tests/e2e/01-acquire-and-stake.spec.ts b/tests/e2e/01-acquire-and-stake.spec.ts index 7e5d10c..9ed1643 100644 --- a/tests/e2e/01-acquire-and-stake.spec.ts +++ b/tests/e2e/01-acquire-and-stake.spec.ts @@ -184,7 +184,7 @@ test.describe('Acquire & Stake', () => { try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); console.log('[TEST] Swap initiated, waiting for completion...'); - await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); + await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 }); console.log('[TEST] Swap completed!'); } catch (e) { console.log('[TEST] No "Submitting" state detected, swap may have completed instantly'); diff --git a/tests/e2e/02-max-stake-all-tax-rates.spec.ts b/tests/e2e/02-max-stake-all-tax-rates.spec.ts index 6c58d3c..9848b31 100644 --- a/tests/e2e/02-max-stake-all-tax-rates.spec.ts +++ b/tests/e2e/02-max-stake-all-tax-rates.spec.ts @@ -193,7 +193,7 @@ test.describe('Max Stake All Tax Rates', () => { console.log('[TEST] Waiting for swap to process...'); try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); - await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); + await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 }); console.log('[TEST] Swap completed!'); } catch (e) { console.log('[TEST] Swap may have completed instantly');