Skip to content

Commit 7b94e13

Browse files
committed
feat: add playwright test for start page [fixes #15896]
1 parent b069f7c commit 7b94e13

File tree

6 files changed

+138
-13
lines changed

6 files changed

+138
-13
lines changed

src/config/mockWallet.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Address } from "viem"
2+
import { CreateConnectorFn, mock } from "wagmi"
3+
import type { Wallet } from "@rainbow-me/rainbowkit"
4+
import { WalletDetailsParams } from "@rainbow-me/rainbowkit"
5+
6+
const defaultAnvilAccount: Address =
7+
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
8+
9+
export const mockWallet = (): Wallet => {
10+
return {
11+
id: "mock",
12+
name: "Mock Wallet",
13+
shortName: "Mock",
14+
installed: true,
15+
iconBackground: "rgba(0, 255, 0, 0.5)",
16+
iconUrl: "/images/assets/svgs/eth-glyph-colored.svg",
17+
downloadUrls: {},
18+
createConnector: createMockConnector,
19+
}
20+
}
21+
22+
function createMockConnector(
23+
walletDetails: WalletDetailsParams
24+
): CreateConnectorFn {
25+
const mockConnector: CreateConnectorFn = (config) => {
26+
return {
27+
...mock({
28+
accounts: [defaultAnvilAccount],
29+
})(config),
30+
rkDetails: walletDetails.rkDetails,
31+
}
32+
}
33+
34+
return mockConnector
35+
}

src/config/rainbow-kit.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,37 @@ import {
99
zerionWallet,
1010
} from "@rainbow-me/rainbowkit/wallets"
1111

12+
import { mockWallet } from "@/config/mockWallet"
13+
14+
const walletGroups = [
15+
{
16+
groupName: "New to crypto",
17+
wallets: [
18+
coinbaseWallet,
19+
rainbowWallet,
20+
metaMaskWallet,
21+
zerionWallet,
22+
oneKeyWallet,
23+
walletConnectWallet,
24+
],
25+
},
26+
]
27+
28+
const isLocalhost =
29+
typeof window !== "undefined" && window.location.hostname === "localhost"
30+
31+
// Add mock wallet only when running on localhost
32+
if (isLocalhost) {
33+
walletGroups.push({
34+
groupName: "Test",
35+
wallets: [mockWallet],
36+
})
37+
}
38+
1239
export const rainbowkitConfig = getDefaultConfig({
1340
appName: "ethereum.org",
1441
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!,
1542
chains: [mainnet],
16-
wallets: [
17-
{
18-
groupName: "New to crypto",
19-
wallets: [
20-
coinbaseWallet,
21-
rainbowWallet,
22-
metaMaskWallet,
23-
zerionWallet,
24-
oneKeyWallet,
25-
walletConnectWallet,
26-
],
27-
},
28-
],
43+
wallets: walletGroups,
44+
ssr: isLocalhost,
2945
})

tests/e2e/fixtures/testData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import en from "@/intl/en/common.json"
2+
import enStart from "@/intl/en/page-start.json"
23
import es from "@/intl/es/common.json"
34

45
/**
@@ -36,6 +37,7 @@ export const testData = {
3637
content: {
3738
headings: {
3839
homepage: en["site-title"],
40+
startPage: enStart["page-start-meta-title"],
3941
findWallet: en["nav-find-wallet-label"],
4042
notFoundEn: en["we-couldnt-find-that-page"],
4143
notFoundEs: es["we-couldnt-find-that-page"],

tests/e2e/pages/StartPage.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { expect, Page } from "@playwright/test"
2+
3+
import { testData } from "../fixtures/testData"
4+
5+
import { BasePage } from "./BasePage"
6+
7+
/**
8+
* Page Object Model for the Start page
9+
*/
10+
export class StartPage extends BasePage {
11+
private readonly url = "/en/start"
12+
13+
constructor(page: Page) {
14+
super(page)
15+
}
16+
17+
/**
18+
* Navigate to the start page
19+
*/
20+
async goto() {
21+
await this.navigateTo(this.url)
22+
}
23+
24+
/**
25+
* Verify the start page has loaded successfully
26+
*/
27+
async verifyPageLoaded() {
28+
await this.assertTitleContains(testData.content.headings.startPage)
29+
}
30+
31+
async connectWithExistingWallet() {
32+
await this.page
33+
.getByRole("paragraph")
34+
.filter({ hasText: "I have a wallet." })
35+
.click()
36+
await this.page.getByRole("button", { name: "Continue" }).click()
37+
await this.page
38+
.getByRole("button", { name: "Sign in with Ethereum" })
39+
.click()
40+
// Choose mock wallet option in RainbowKit modal
41+
await this.page.getByTestId("rk-wallet-option-mock").click()
42+
// Verify wallet connected
43+
await expect(
44+
this.page
45+
.getByRole("paragraph")
46+
.filter({ hasText: "This is your account" })
47+
).toBeVisible()
48+
}
49+
50+
async continueToUseAppsStep() {
51+
await this.page.getByRole("button", { name: "Lets continue" }).click()
52+
await expect(
53+
this.page.getByRole("heading", { name: "Let Use Some Apps" })
54+
).toBeVisible()
55+
}
56+
}

tests/e2e/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
export { BasePage } from "./BasePage"
66
export { FindWalletPage } from "./FindWalletPage"
77
export { HomePage } from "./HomePage"
8+
export { StartPage } from "./StartPage"

tests/e2e/start.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test } from "@playwright/test"
2+
3+
import { StartPage } from "./pages"
4+
5+
test.describe("Start Page", () => {
6+
test("Connect wallet", async ({ page }) => {
7+
const startPage = new StartPage(page)
8+
await startPage.goto()
9+
await startPage.verifyPageLoaded()
10+
11+
await startPage.connectWithExistingWallet()
12+
13+
await startPage.continueToUseAppsStep()
14+
})
15+
})

0 commit comments

Comments
 (0)