|
| 1 | +import { type Page, expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +const customPageLoadTimeout = { timeout: 30000 } |
| 4 | + |
| 5 | +// As a known CI issue, allow max 1% deviation in pixel diff. |
| 6 | +const customDiffPixelRatio = { maxDiffPixelRatio: 0.01 } |
| 7 | + |
| 8 | +// Testing constants. |
| 9 | +const repoPreviewURL: string = |
| 10 | + '/wei/socialify?language=1&owner=1&name=1&stargazers=1&theme=Light' |
| 11 | + |
| 12 | +test.describe('Socialify UI:', () => { |
| 13 | + test('is consistent for landing page', async ({ |
| 14 | + page, |
| 15 | + }: { page: Page }): Promise<void> => { |
| 16 | + await page.goto('/', customPageLoadTimeout) |
| 17 | + |
| 18 | + // Wait for the page to load/hydrate completely. |
| 19 | + await page.waitForLoadState('networkidle', customPageLoadTimeout) |
| 20 | + await page.waitForTimeout(5000) |
| 21 | + |
| 22 | + const image = await page.screenshot() |
| 23 | + expect(image).toMatchSnapshot(customDiffPixelRatio) |
| 24 | + }) |
| 25 | + |
| 26 | + test('is consistent for error (404) page', async ({ |
| 27 | + page, |
| 28 | + }: { page: Page }): Promise<void> => { |
| 29 | + await page.goto('/404', customPageLoadTimeout) |
| 30 | + |
| 31 | + // Wait for the page to load/hydrate completely. |
| 32 | + await page.waitForLoadState('networkidle', customPageLoadTimeout) |
| 33 | + |
| 34 | + const image = await page.screenshot() |
| 35 | + expect(image).toMatchSnapshot(customDiffPixelRatio) |
| 36 | + }) |
| 37 | + |
| 38 | + test('is consistent for preview config page', async ({ |
| 39 | + page, |
| 40 | + }: { page: Page }): Promise<void> => { |
| 41 | + await page.goto(repoPreviewURL, customPageLoadTimeout) |
| 42 | + |
| 43 | + // Wait for the page to load/hydrate completely. |
| 44 | + await page.waitForLoadState('networkidle', customPageLoadTimeout) |
| 45 | + |
| 46 | + // To maintain consistency, de-select the 'Stars' checkbox, |
| 47 | + // and selects the 'Description' checkbox. |
| 48 | + await page.click('input[name="stargazers"]') |
| 49 | + await page.click('input[name="description"]') |
| 50 | + |
| 51 | + // Wait for the component transition/animation to finish completely. |
| 52 | + await page.waitForTimeout(1000) |
| 53 | + |
| 54 | + const image = await page.screenshot() |
| 55 | + expect(image).toMatchSnapshot(customDiffPixelRatio) |
| 56 | + |
| 57 | + // Also check the toaster UI consistency. |
| 58 | + await page.click('button:has-text("URL")') |
| 59 | + await page.waitForSelector('[role="alert"]', customPageLoadTimeout) |
| 60 | + |
| 61 | + // Wait for the component transition/animation to finish completely. |
| 62 | + await page.waitForTimeout(1000) |
| 63 | + |
| 64 | + const toastImage = await page.screenshot() |
| 65 | + expect(toastImage).toMatchSnapshot(customDiffPixelRatio) |
| 66 | + }) |
| 67 | +}) |
0 commit comments