fix: use waitFor instead of isVisible for wallet connect in deep link test

The deep link test's wallet connection was silently failing because
isVisible() returns immediately without waiting for the element to
appear. wagmi needs time to settle into 'disconnected' state after
provider injection. Now uses waitFor() which properly auto-retries,
plus adds a 2s delay matching the pattern used in test 01.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
johba 2026-03-25 11:41:35 +00:00
parent 01c81abdd3
commit e562a51d47

View file

@ -298,15 +298,27 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
if (hasLocalSwap) { if (hasLocalSwap) {
console.log('[DEEPLINK] Local swap mode — connecting wallet first'); console.log('[DEEPLINK] Local swap mode — connecting wallet first');
// The wallet must be explicitly connected for the swap input to render. // The wallet must be explicitly connected for the swap input to render.
// Navigate to main page to access the connect button, then return.
const navbarTitle = page.locator('.navbar-title').first(); const navbarTitle = page.locator('.navbar-title').first();
await navbarTitle.waitFor({ state: 'visible', timeout: 30_000 }); await navbarTitle.waitFor({ state: 'visible', timeout: 30_000 });
await page.evaluate(() => window.dispatchEvent(new Event('resize'))); await page.evaluate(() => window.dispatchEvent(new Event('resize')));
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: wagmi needs time to settle into disconnected/connected state after provider injection; no observable DOM event signals readiness. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(2_000);
// Check if wallet already connected (wagmi may auto-reconnect from storage)
const alreadyConnected = page.locator('.connect-button--connected').first();
if (await alreadyConnected.isVisible({ timeout: 1_000 }).catch(() => false)) {
console.log('[DEEPLINK] Wallet already connected (auto-reconnect)');
} else {
// Wait for wagmi to settle into disconnected state and render the connect button
const connectBtn = page.locator('.connect-button--disconnected').first(); const connectBtn = page.locator('.connect-button--disconnected').first();
if (await connectBtn.isVisible({ timeout: 10_000 }).catch(() => false)) { await connectBtn.waitFor({ state: 'visible', timeout: 15_000 });
console.log('[DEEPLINK] Found desktop Connect button, clicking...');
await connectBtn.click(); await connectBtn.click();
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: connector panel animation has no completion event. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(1_000);
const connector = page.locator('.connectors-element').first(); const connector = page.locator('.connectors-element').first();
await connector.waitFor({ state: 'visible', timeout: 10_000 }); await connector.waitFor({ state: 'visible', timeout: 10_000 });
console.log('[DEEPLINK] Clicking wallet connector...');
await connector.click(); await connector.click();
// Wait for wallet to connect // Wait for wallet to connect
await page.getByText(/0x[a-fA-F0-9]{4}/i).first().waitFor({ state: 'visible', timeout: 15_000 }); await page.getByText(/0x[a-fA-F0-9]{4}/i).first().waitFor({ state: 'visible', timeout: 15_000 });