Skip to content

Commit d0b55b5

Browse files
committed
load chromatic e2e to new project
add storybookBaseDir to Playwright workflow configuration add tests for find-wallets page test: delete chromatic config file add env variable for e2e token
1 parent 16abb57 commit d0b55b5

File tree

5 files changed

+154
-24
lines changed

5 files changed

+154
-24
lines changed

.github/workflows/playwright.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ jobs:
7777
- name: Run Chromatic
7878
uses: chromaui/action@latest
7979
with:
80-
projectToken: fee8e66c9916
80+
projectToken: ${{ secrets.CHROMATIC_E2E_TOKEN }}
8181
playwright: true
8282
exitZeroOnChanges: true
8383
forceRebuild: true
84+
storybookBaseDir: .
8485
env:
8586
CHROMATIC_ARCHIVE_LOCATION: ./tests/e2e/__results__

chromatic.config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"storybook": "storybook dev -p 6006",
1717
"build-storybook": "storybook build",
1818
"build-storybook:chromatic": "storybook build --test",
19-
"chromatic": "CHROMATIC_ARCHIVE_LOCATION=tests/e2e/__results__ chromatic --project-token fee8e66c9916",
19+
"chromatic": "chromatic --project-token fee8e66c9916",
2020
"crowdin-clean": "rm -rf .crowdin && mkdir .crowdin",
2121
"crowdin-import": "ts-node src/scripts/crowdin-import.ts",
2222
"markdown-checker": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/markdownChecker.ts",

tests/e2e/find-wallet.spec.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { expect, takeSnapshot, test } from "@chromatic-com/playwright"
2+
3+
import { breakpointAsNumber } from "@/lib/utils/screen"
4+
5+
const PAGE_URL = "/wallets/find-wallet"
6+
7+
test.beforeEach(async ({ page }) => {
8+
await page.goto(PAGE_URL)
9+
})
10+
11+
test.describe("Find Wallet Page", () => {
12+
test("loads successfully", async ({ page }, testInfo) => {
13+
await expect(
14+
page.getByRole("heading", { name: "Choose your wallet" })
15+
).toBeVisible()
16+
await takeSnapshot(page, "find-wallet-initial-load", testInfo)
17+
})
18+
19+
test("personas filter updates counter and list", async ({ page }) => {
20+
// Click the first persona (e.g., New to crypto)
21+
const personaButton = page.getByRole("button", { name: /New to crypto/i })
22+
await personaButton.click()
23+
// Extract the counter from the persona button
24+
const counterText = await personaButton.textContent()
25+
const match = counterText && counterText.match(/\((\d+)\)/)
26+
const personaCount = match ? parseInt(match[1], 10) : null
27+
// Count the number of visible rows in the table (excluding header)
28+
const rows = await page
29+
.locator("table tbody tr")
30+
.filter({ has: page.locator("td") })
31+
.count()
32+
expect(personaCount).not.toBeNull()
33+
expect(rows).toBe(personaCount)
34+
})
35+
36+
test("wallet list items expand correctly", async ({ page }) => {
37+
// Click the first wallet row to expand
38+
const firstRow = page.locator("table tbody tr").first()
39+
await firstRow.click()
40+
// Check that the expanded content is visible (look for 'Links' heading)
41+
await expect(page.getByRole("heading", { name: /Links/i })).toBeVisible()
42+
})
43+
44+
test("sidebar filters - desktop", async ({ page }) => {
45+
// Device filter accordion should be expanded by default
46+
const deviceAccordion = page.getByRole("button", { name: /Device/i })
47+
await expect(deviceAccordion).toHaveAttribute("aria-expanded", "true")
48+
49+
// Click the Desktop filter (custom selector: button next to 'Desktop' text)
50+
const deviceRegion = page
51+
.getByRole("heading", { name: /device/i })
52+
.locator("..")
53+
const desktopLabel = deviceRegion.getByText("Desktop")
54+
const desktopLabelParent = desktopLabel.locator("../..")
55+
const desktopCheckbox = desktopLabelParent.locator("button")
56+
await desktopCheckbox.click()
57+
58+
// Grab all OS options from the Device filter section
59+
const osOptionLabels = await desktopLabelParent
60+
.locator("..")
61+
.locator("label span.select-none")
62+
.allTextContents()
63+
64+
// Check that at least one row is visible
65+
const rows = page
66+
.locator("table tbody tr")
67+
.filter({ has: page.locator("td") })
68+
await expect(rows.first()).toBeVisible()
69+
70+
// Check that every visible row contains at least one of the OS options
71+
const rowCount = await rows.count()
72+
for (let i = 0; i < rowCount; i++) {
73+
const row = rows.nth(i)
74+
const text = await row.textContent()
75+
expect(
76+
text && osOptionLabels.some((os) => text.includes(os))
77+
).toBeTruthy()
78+
}
79+
80+
// Check that the row counter matches the number of rows in the table
81+
const rowCounter = await page
82+
.getByText(/Showing all wallets \(\d+\)/i)
83+
.textContent()
84+
expect(rowCounter).toBe(`Showing all wallets (${rowCount})`)
85+
})
86+
87+
test("sidebar filters - mobile", async ({ page }) => {
88+
// Set viewport to mobile size
89+
await page.setViewportSize({ width: breakpointAsNumber.sm, height: 800 })
90+
91+
// Open mobile filters drawer
92+
const filterButton = page.getByRole("button", { name: /filters/i })
93+
await filterButton.click()
94+
// Click the Device filter accordion
95+
const deviceAccordion = page.getByRole("button", { name: /Device/i })
96+
await expect(deviceAccordion).toHaveAttribute("aria-expanded", "true")
97+
98+
// Click the Mobile filter
99+
const deviceRegion = page
100+
.getByRole("heading", { name: /device/i })
101+
.locator("..")
102+
const mobileLabel = deviceRegion.getByText(/mobile/i)
103+
const mobileLabelParent = mobileLabel.locator("../..")
104+
const mobileCheckbox = mobileLabelParent.locator("button")
105+
await mobileCheckbox.click()
106+
107+
// Grab all OS options from the Device filter section
108+
const osOptionLabels = await mobileLabelParent
109+
.locator("..")
110+
.locator("label span.select-none")
111+
.allTextContents()
112+
113+
// Close the filters drawer
114+
const closeButton = page.getByRole("button", { name: /see wallets/i })
115+
await closeButton.click()
116+
117+
// Check that at least one row is visible
118+
const rows = page
119+
.locator("table tbody tr")
120+
.filter({ has: page.locator("td") })
121+
await expect(rows.first()).toBeVisible()
122+
123+
// Check that every visible row contains at least one of the OS options
124+
const rowCount = await rows.count()
125+
for (let i = 0; i < rowCount; i++) {
126+
const row = rows.nth(i)
127+
const text = await row.textContent()
128+
expect(
129+
text && osOptionLabels.some((os) => text.includes(os))
130+
).toBeTruthy()
131+
}
132+
133+
// Check that the row counter matches the number of rows in the table
134+
const rowCounter = await page
135+
.getByText(/Showing all wallets \(\d+\)/i)
136+
.textContent()
137+
expect(rowCounter).toBe(`Showing all wallets (${rowCount})`)
138+
})
139+
})

tests/e2e/home.spec.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import { expect, takeSnapshot, test } from "@chromatic-com/playwright"
22

33
import { breakpointAsNumber } from "@/lib/utils/screen"
44

5-
test.describe("Homepage", () => {
6-
test("loads successfully", async ({ page }, testInfo) => {
7-
await page.goto("/")
5+
const PAGE_URL = "/"
6+
7+
test.beforeEach(async ({ page }) => {
8+
await page.goto(PAGE_URL)
9+
})
810

11+
test.describe("Home Page", () => {
12+
test("loads successfully", async ({ page }, testInfo) => {
913
await expect(page).toHaveTitle(/Ethereum.org/)
1014

11-
await takeSnapshot(page, "Page loaded", testInfo)
15+
await takeSnapshot(page, "initial-load", testInfo)
1216
})
1317

1418
test("search functionality", async ({ page }) => {
15-
await page.goto("/")
16-
1719
await page.getByRole("button", { name: "Search" }).click()
1820
await page.getByPlaceholder("Search").fill("smart contract")
1921

@@ -26,8 +28,6 @@ test.describe("Homepage", () => {
2628
const isMobile = viewport && viewport.width <= breakpointAsNumber.md
2729
test.skip(!!isMobile, "This test is for desktop viewports only")
2830

29-
await page.goto("/")
30-
3131
const nav = page.getByRole("navigation", { name: "Primary" })
3232
await expect(nav.getByRole("button", { name: "Learn" })).toBeVisible()
3333
await expect(nav.getByRole("button", { name: "Use" })).toBeVisible()
@@ -41,14 +41,10 @@ test.describe("Homepage", () => {
4141
})
4242

4343
test("navigation menu - mobile", async ({ page }, testInfo) => {
44-
// Only run this test for mobile projects
45-
const viewport = page.viewportSize()
46-
const isMobile = viewport && viewport.width <= breakpointAsNumber.md
47-
test.skip(!isMobile, "This test is for mobile viewports only")
48-
49-
await page.goto("/")
44+
// Set viewport to mobile size
45+
await page.setViewportSize({ width: breakpointAsNumber.sm, height: 800 })
5046

51-
await takeSnapshot(page, "Mobile page loaded", testInfo)
47+
await takeSnapshot(page, "mobile-initial-load", testInfo)
5248

5349
const nav = page.getByRole("navigation", { name: "Primary" })
5450
const menuButton = nav.getByRole("button", {
@@ -59,7 +55,7 @@ test.describe("Homepage", () => {
5955
// Open the mobile menu
6056
await menuButton.click()
6157

62-
await takeSnapshot(page, "Mobile menu opened", testInfo)
58+
await takeSnapshot(page, "mobile-menu-opened", testInfo)
6359

6460
// Check that navigation links are visible in the mobile menu
6561
const sidebar = page.getByRole("dialog", { name: /ethereum.org/i })

0 commit comments

Comments
 (0)