Skip to content

Commit 1f729f1

Browse files
author
Jarvis
committed
fix(tests): use testid instead of hasText for connect button
- Add testid prop to WalletConnectButton, pass through to SMUI Button - Update loginOnCurrentPage helper to use getByTestId('wallet-connect-btn') - Remove fragile hasText matching, scope stays in top navbar
1 parent ea55f71 commit 1f729f1

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/routes/WalletConnectButton.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@
128128
129129
export let anchor: HTMLDivElement;
130130
export let connectButtonVariant: 'raised' | 'unelevated' | 'outlined' = 'raised';
131+
export let testid: string = '';
131132
</script>
132133

133-
<Button variant={connectButtonVariant} on:click={toggleMenu}>
134+
<Button variant={connectButtonVariant} on:click={toggleMenu} {testid}>
134135
<slot name="buttonLabel">Connect</slot>
135136
</Button>
136137
<Menu

src/routes/WalletConnectStatus.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
export let anchor: HTMLDivElement;
2020
</script>
2121

22-
<WalletConnectButton connectButtonVariant="unelevated" {anchor}>
22+
<WalletConnectButton connectButtonVariant="unelevated" {anchor} testid="wallet-connect-btn">
2323
<div class="wallet-connect" slot="buttonLabel">
2424
<Icon icon="wallet" align="left" />
2525
<Label>{buttonLabel}</Label>

tests/e2e/helpers.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ export const TEST_PRIVATE_KEY = 'df4642ef258f9aef2adb6c148590208b20387fb067f2c09
1212
* for the dev-key-input to become visible.
1313
*/
1414
export async function loginOnCurrentPage(page: Page) {
15-
// The top-bar wallet button is inside a header element.
16-
// On pages with ConnectionRequired (e.g. /register), there may be a second
17-
// Connect button in the page body. We target the header's button.
18-
const topBar = page.locator('header').first();
19-
const connectBtn = topBar.locator('button', { hasText: /Connect/ }).first();
15+
// Use testid on the button in the top navbar — reliable, no text matching needed.
16+
const connectBtn = page.getByTestId('wallet-connect-btn');
2017
await expect(connectBtn).toBeVisible({ timeout: 15000 });
2118

2219
// Allow SvelteKit hydration to complete.
2320
await page.waitForTimeout(3000);
2421

2522
// Click the Connect button.
26-
await connectBtn.click({ force: true });
23+
await connectBtn.click();
2724

2825
// Wait for the dev-key-input to appear and be visible.
2926
// Use expect with toBeVisible which polls internally — more reliable than manual count checks.
@@ -38,7 +35,7 @@ export async function loginOnCurrentPage(page: Page) {
3835
await devConnectBtn.click();
3936

4037
// Verify wallet is connected — the button text changes to a short address containing "..."
41-
await expect(topBar.locator('button', { hasText: '...' }).first()).toBeVisible({ timeout: 10000 });
38+
await expect(page.getByTestId('wallet-connect-btn').locator('text=/\\.{3}/')).toBeVisible({ timeout: 10000 });
4239
}
4340

4441
/**

0 commit comments

Comments
 (0)