Merge pull request 'fix: getByRole('button', { name: 'Buy' }).last() fragility is duplicated across e2e/01 and this scenario (#398)' (#414) from fix/issue-398 into master

This commit is contained in:
johba 2026-03-03 01:11:00 +01:00
commit b8d0e07fd2
4 changed files with 11 additions and 11 deletions

View file

@ -80,13 +80,13 @@ export async function buyKrk(page: Page, ethAmount: string): Promise<void> {
await navigateSPA(page, '/app/get-krk'); await navigateSPA(page, '/app/get-krk');
await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 }); await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 });
const swapInput = page.getByLabel('ETH to spend'); const swapInput = page.getByTestId('swap-amount-input');
await expect(swapInput).toBeVisible({ timeout: 15_000 }); await expect(swapInput).toBeVisible({ timeout: 15_000 });
await swapInput.fill(ethAmount); await swapInput.fill(ethAmount);
await page.waitForTimeout(500); await page.waitForTimeout(500);
const buyButton = page.getByRole('button', { name: 'Buy KRK' }); const buyButton = page.getByTestId('swap-buy-button');
await expect(buyButton).toBeVisible({ timeout: 5_000 }); await expect(buyButton).toBeVisible({ timeout: 5_000 });
await page.screenshot({ path: 'test-results/holdout-before-buy.png' }); await page.screenshot({ path: 'test-results/holdout-before-buy.png' });
@ -97,7 +97,7 @@ export async function buyKrk(page: Page, ethAmount: string): Promise<void> {
try { try {
await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 });
console.log('[swap] Swap in progress...'); console.log('[swap] Swap in progress...');
await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 });
console.log('[swap] Swap completed'); console.log('[swap] Swap completed');
} catch { } catch {
// Swap completed before the Submitting state could be observed // Swap completed before the Submitting state could be observed

View file

@ -170,11 +170,11 @@ test.describe('Acquire & Stake', () => {
await page.screenshot({ path: 'test-results/before-swap.png' }); await page.screenshot({ path: 'test-results/before-swap.png' });
const ethToSpendInput = page.getByLabel('ETH to spend'); const ethToSpendInput = page.getByTestId('swap-amount-input');
await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 }); await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 });
await ethToSpendInput.fill('0.05'); await ethToSpendInput.fill('0.05');
const buyButton = page.getByRole('button', { name: 'Buy KRK' }); const buyButton = page.getByTestId('swap-buy-button');
await expect(buyButton).toBeVisible(); await expect(buyButton).toBeVisible();
console.log('[TEST] Clicking Buy KRK button...'); console.log('[TEST] Clicking Buy KRK button...');
await buyButton.click(); await buyButton.click();
@ -184,7 +184,7 @@ test.describe('Acquire & Stake', () => {
try { try {
await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 });
console.log('[TEST] Swap initiated, waiting for completion...'); console.log('[TEST] Swap initiated, waiting for completion...');
await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 });
console.log('[TEST] Swap completed!'); console.log('[TEST] Swap completed!');
} catch (e) { } catch (e) {
console.log('[TEST] No "Submitting" state detected, swap may have completed instantly'); console.log('[TEST] No "Submitting" state detected, swap may have completed instantly');

View file

@ -181,11 +181,11 @@ test.describe('Max Stake All Tax Rates', () => {
await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 }); await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 });
console.log('[TEST] Buying KRK tokens (swapping 5 ETH)...'); console.log('[TEST] Buying KRK tokens (swapping 5 ETH)...');
const ethToSpendInput = page.getByLabel('ETH to spend'); const ethToSpendInput = page.getByTestId('swap-amount-input');
await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 }); await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 });
await ethToSpendInput.fill('5'); await ethToSpendInput.fill('5');
const buyButton = page.getByRole('button', { name: 'Buy KRK' }); const buyButton = page.getByTestId('swap-buy-button');
await expect(buyButton).toBeVisible(); await expect(buyButton).toBeVisible();
await buyButton.click(); await buyButton.click();
@ -193,7 +193,7 @@ test.describe('Max Stake All Tax Rates', () => {
console.log('[TEST] Waiting for swap to process...'); console.log('[TEST] Waiting for swap to process...');
try { try {
await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 });
await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 });
console.log('[TEST] Swap completed!'); console.log('[TEST] Swap completed!');
} catch (e) { } catch (e) {
console.log('[TEST] Swap may have completed instantly'); console.log('[TEST] Swap may have completed instantly');

View file

@ -6,9 +6,9 @@
<template v-else> <template v-else>
<div class="swap-field"> <div class="swap-field">
<label for="local-swap-amount" class="swap-label">ETH to spend</label> <label for="local-swap-amount" class="swap-label">ETH to spend</label>
<input id="local-swap-amount" :value="swapAmount" @input="swapAmount = ($event.target as HTMLInputElement).value" type="number" min="0" step="0.01" class="swap-input" :disabled="swapping" /> <input id="local-swap-amount" data-testid="swap-amount-input" :value="swapAmount" @input="swapAmount = ($event.target as HTMLInputElement).value" type="number" min="0" step="0.01" class="swap-input" :disabled="swapping" />
</div> </div>
<button class="swap-button" :disabled="swapping" @click="buyKrk"> <button class="swap-button" data-testid="swap-buy-button" :disabled="swapping" @click="buyKrk">
{{ swapping ? 'Submitting…' : 'Buy KRK' }} {{ swapping ? 'Submitting…' : 'Buy KRK' }}
</button> </button>
<p class="swap-hint">Wraps ETH WETH, approves the swap router, then trades into $KRK.</p> <p class="swap-hint">Wraps ETH WETH, approves the swap router, then trades into $KRK.</p>