| 
 | 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 | +})  | 
0 commit comments