|
| 1 | +import { type Page, expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +const customTimeout = { timeout: 30000 } |
| 4 | + |
| 5 | +const defaultImageURL: string = |
| 6 | + '/wei/socialify/image?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark' |
| 7 | +const svgImageURL: string = |
| 8 | + '/wei/socialify/svg?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark' |
| 9 | +const pngImageURL: string = |
| 10 | + '/wei/socialify/png?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark' |
| 11 | +// Backward compatibility route. |
| 12 | +const jpgImageURL: string = |
| 13 | + '/wei/socialify/jpg?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark' |
| 14 | + |
| 15 | +test.describe('Socialify image api', () => { |
| 16 | + test('respond consistently for default endpoint', async ({ |
| 17 | + page, |
| 18 | + }: { page: Page }): Promise<void> => { |
| 19 | + await page.goto(defaultImageURL, customTimeout) |
| 20 | + |
| 21 | + // Wait for the page to load/hydrate completely. |
| 22 | + await page.waitForLoadState('networkidle', customTimeout) |
| 23 | + |
| 24 | + const image = await page.screenshot() |
| 25 | + expect(image).toMatchSnapshot() |
| 26 | + }) |
| 27 | + |
| 28 | + test('respond consistently for svg endpoint', async ({ |
| 29 | + page, |
| 30 | + }: { page: Page }): Promise<void> => { |
| 31 | + await page.goto(svgImageURL, customTimeout) |
| 32 | + |
| 33 | + // Wait for the page to load/hydrate completely. |
| 34 | + await page.waitForLoadState('networkidle', customTimeout) |
| 35 | + |
| 36 | + const image = await page.screenshot() |
| 37 | + expect(image).toMatchSnapshot() |
| 38 | + }) |
| 39 | + |
| 40 | + test('respond consistently for png endpoint', async ({ |
| 41 | + page, |
| 42 | + }: { page: Page }): Promise<void> => { |
| 43 | + await page.goto(pngImageURL, customTimeout) |
| 44 | + |
| 45 | + // Wait for the page to load/hydrate completely. |
| 46 | + await page.waitForLoadState('networkidle', customTimeout) |
| 47 | + |
| 48 | + const image = await page.screenshot() |
| 49 | + expect(image).toMatchSnapshot() |
| 50 | + }) |
| 51 | + |
| 52 | + test('respond consistently for backwards-compatible jpg endpoint', async ({ |
| 53 | + page, |
| 54 | + }: { page: Page }): Promise<void> => { |
| 55 | + await page.goto(jpgImageURL, customTimeout) |
| 56 | + |
| 57 | + // Wait for the page to load/hydrate completely. |
| 58 | + await page.waitForLoadState('networkidle', customTimeout) |
| 59 | + |
| 60 | + const image = await page.screenshot() |
| 61 | + expect(image).toMatchSnapshot() |
| 62 | + }) |
| 63 | +}) |
0 commit comments