|
| 1 | +/*! |
| 2 | + * New BSD License (3-clause) |
| 3 | + * Copyright (c) 2026, Digital Bazaar, Inc. |
| 4 | + * All rights reserved. |
| 5 | + */ |
| 6 | +import {expect, test} from '@playwright/test'; |
| 7 | +import {fileURLToPath} from 'node:url'; |
| 8 | +import fs from 'node:fs/promises'; |
| 9 | +import path from 'node:path'; |
| 10 | + |
| 11 | +/* Generates a labelled, human-viewable gallery of the first party wallet |
| 12 | +chooser dialog across wallet counts, the cross-device QR section, themes, and |
| 13 | +viewports — the screenshots we otherwise capture by hand for review. Output |
| 14 | +goes to `test/e2e/gallery/<engine>/<theme>/<state>.png` plus an `index.html` |
| 15 | +contact sheet. This is NOT a regression gate (see `wallet-chooser.spec.js` for |
| 16 | +that); run it with `npm run gallery`. */ |
| 17 | + |
| 18 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 19 | +const GALLERY_DIR = path.join(__dirname, 'gallery'); |
| 20 | + |
| 21 | +const STATES = [ |
| 22 | + {name: 'hints-0-qr', query: 'hints=0&qr=1', label: '0 wallets + QR'}, |
| 23 | + {name: 'hints-1-qr', query: 'hints=1&qr=1', label: '1 wallet + QR'}, |
| 24 | + {name: 'hints-5-qr', query: 'hints=5&qr=1', label: '5 wallets + QR'}, |
| 25 | + {name: 'hints-5-noqr', query: 'hints=5&qr=0', label: '5 wallets, no QR'}, |
| 26 | + {name: 'hints-15-qr', query: 'hints=15&qr=1', label: '15 wallets + QR'} |
| 27 | +]; |
| 28 | +const THEMES = ['light', 'dark']; |
| 29 | + |
| 30 | +test.describe('gallery', () => { |
| 31 | + for(const theme of THEMES) { |
| 32 | + test.describe(theme, () => { |
| 33 | + test.use({colorScheme: theme}); |
| 34 | + |
| 35 | + for(const state of STATES) { |
| 36 | + test(`${state.label}`, async ({page}, testInfo) => { |
| 37 | + const engine = testInfo.project.name; |
| 38 | + await page.goto(`/test/wallet-chooser?${state.query}`); |
| 39 | + await page.locator('.wrm-modal-1p .wrm-modal-content').waitFor(); |
| 40 | + |
| 41 | + const dir = path.join(GALLERY_DIR, engine, theme); |
| 42 | + await fs.mkdir(dir, {recursive: true}); |
| 43 | + |
| 44 | + // collapsed (default) shot |
| 45 | + await page.screenshot({path: path.join(dir, `${state.name}.png`)}); |
| 46 | + |
| 47 | + // for states with the expander, also capture it expanded |
| 48 | + const toggle = page.locator('.cross-device-toggle'); |
| 49 | + if(await toggle.count() > 0) { |
| 50 | + await toggle.click(); |
| 51 | + await expect(page.locator('img[alt*="QR"]')).toBeVisible(); |
| 52 | + await page.screenshot( |
| 53 | + {path: path.join(dir, `${state.name}-expanded.png`)}); |
| 54 | + } |
| 55 | + }); |
| 56 | + } |
| 57 | + }); |
| 58 | + } |
| 59 | +}); |
0 commit comments