|
| 1 | +/** |
| 2 | + * Full-page screenshots for public routes (committed under cypress/baseline/). |
| 3 | + * |
| 4 | + * Prerequisites: frontend (and usually API) running; regenerate after UI changes: |
| 5 | + * cd apps/e2e && bun run cy:baseline |
| 6 | + * |
| 7 | + * Dynamic routes (/song/:id, /blog/:id, …) use CYPRESS_* env vars when set; otherwise skipped. |
| 8 | + */ |
| 9 | +import { SEED_E2E_BROWSER_CLOCK_MS } from '@nbw/config'; |
| 10 | + |
| 11 | +const VIEWPORT = { width: 1280, height: 720 } as const; |
| 12 | + |
| 13 | +type PageTarget = { path: string; file: string }; |
| 14 | + |
| 15 | +const STATIC_PAGES: PageTarget[] = [ |
| 16 | + { path: '/', file: 'page-home' }, |
| 17 | + { path: '/about', file: 'page-about' }, |
| 18 | + { path: '/contact', file: 'page-contact' }, |
| 19 | + { path: '/search', file: 'page-search' }, |
| 20 | + { path: '/upload', file: 'page-upload' }, |
| 21 | + { path: '/my-songs', file: 'page-my-songs' }, |
| 22 | + { path: '/help', file: 'page-help' }, |
| 23 | + { path: '/blog', file: 'page-blog' }, |
| 24 | + { path: '/login', file: 'page-login' }, |
| 25 | + { path: '/login/email', file: 'page-login-email' }, |
| 26 | + { path: '/logout', file: 'page-logout' }, |
| 27 | + { path: '/privacy', file: 'page-privacy' }, |
| 28 | + { path: '/terms', file: 'page-terms' }, |
| 29 | + { path: '/guidelines', file: 'page-guidelines' }, |
| 30 | + { |
| 31 | + path: '/__cypress_unknown_route__/nbw', |
| 32 | + file: 'page-not-found', |
| 33 | + }, |
| 34 | +]; |
| 35 | + |
| 36 | +function optionalPage( |
| 37 | + envName: string, |
| 38 | + pathSuffix: string, |
| 39 | + file: string, |
| 40 | +): PageTarget | null { |
| 41 | + const id = Cypress.env(envName) as string | undefined; |
| 42 | + if (!id || typeof id !== 'string') { |
| 43 | + return null; |
| 44 | + } |
| 45 | + return { path: `${pathSuffix}/${id}`, file }; |
| 46 | +} |
| 47 | + |
| 48 | +describe('Page baseline snapshots', () => { |
| 49 | + beforeEach(() => { |
| 50 | + cy.viewport(VIEWPORT.width, VIEWPORT.height); |
| 51 | + cy.clock(SEED_E2E_BROWSER_CLOCK_MS, ['Date']); |
| 52 | + }); |
| 53 | + |
| 54 | + for (const { path, file } of STATIC_PAGES) { |
| 55 | + it(file, () => { |
| 56 | + cy.visit(path, { failOnStatusCode: false }); |
| 57 | + cy.get('body', { timeout: 45_000 }).should('be.visible'); |
| 58 | + cy.wait(800); |
| 59 | + cy.screenshot(file, { capture: 'fullPage', overwrite: true }); |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + const dynamicPages: PageTarget[] = [ |
| 64 | + optionalPage('SNAPSHOT_SONG_ID', '/song', 'page-song-detail'), |
| 65 | + optionalPage('SNAPSHOT_BLOG_ID', '/blog', 'page-blog-detail'), |
| 66 | + optionalPage('SNAPSHOT_HELP_ID', '/help', 'page-help-detail'), |
| 67 | + ].filter((p): p is PageTarget => p !== null); |
| 68 | + |
| 69 | + for (const { path, file } of dynamicPages) { |
| 70 | + it(file, () => { |
| 71 | + cy.visit(path, { failOnStatusCode: false }); |
| 72 | + cy.get('body', { timeout: 45_000 }).should('be.visible'); |
| 73 | + cy.wait(800); |
| 74 | + cy.screenshot(file, { capture: 'fullPage', overwrite: true }); |
| 75 | + }); |
| 76 | + } |
| 77 | +}); |
0 commit comments