Skip to content

Commit

Permalink
βœ… Added Playwright behavior tests to image api endpoints
Browse files Browse the repository at this point in the history
Screenshot all 4 GET image api endpoints with complex config per viewport type (Chrome and Mobile Chrome) in preparation for migration. Also updated TailwindCSS config from .js to .ts.
  • Loading branch information
KemingHe committed Dec 15, 2024
1 parent 6c96812 commit 74809d6
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 5 deletions.
63 changes: 63 additions & 0 deletions .playwright/imageAPIEndpoints.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { type Page, expect, test } from '@playwright/test'

const customTimeout = { timeout: 30000 }

const defaultImageURL: string =
'/wei/socialify/image?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark'
const svgImageURL: string =
'/wei/socialify/svg?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark'
const pngImageURL: string =
'/wei/socialify/png?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark'
// Backward compatibility route.
const jpgImageURL: string =
'/wei/socialify/jpg?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Diagonal%20Stripes&theme=Dark'

test.describe('Socialify image api', () => {
test('respond consistently for default endpoint', async ({
page,
}: { page: Page }): Promise<void> => {
await page.goto(defaultImageURL, customTimeout)

// Wait for the page to load/hydrate completely.
await page.waitForLoadState('networkidle', customTimeout)

const image = await page.screenshot()
expect(image).toMatchSnapshot()
})

test('respond consistently for svg endpoint', async ({
page,
}: { page: Page }): Promise<void> => {
await page.goto(svgImageURL, customTimeout)

// Wait for the page to load/hydrate completely.
await page.waitForLoadState('networkidle', customTimeout)

const image = await page.screenshot()
expect(image).toMatchSnapshot()
})

test('respond consistently for png endpoint', async ({
page,
}: { page: Page }): Promise<void> => {
await page.goto(pngImageURL, customTimeout)

// Wait for the page to load/hydrate completely.
await page.waitForLoadState('networkidle', customTimeout)

const image = await page.screenshot()
expect(image).toMatchSnapshot()
})

test('respond consistently for backwards-compatible jpg endpoint', async ({
page,
}: { page: Page }): Promise<void> => {
await page.goto(jpgImageURL, customTimeout)

// Wait for the page to load/hydrate completely.
await page.waitForLoadState('networkidle', customTimeout)

const image = await page.screenshot()
expect(image).toMatchSnapshot()
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions tailwind.config.js β†’ tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./pages/**/*.{js,ts,jsx,tsx}', './src/**/*.{js,ts,jsx,tsx}'],
import daisyui from 'daisyui'
import type { Config } from 'tailwindcss'

export default {
content: [
'./app/**/*.{js,ts,jsx,tsx}',
'./pages/**/*.{js,ts,jsx,tsx}',
'./src/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
plugins: [daisyui],
daisyui: {
themes: [
{
Expand All @@ -16,5 +23,4 @@ module.exports = {
},
],
},
plugins: [require('daisyui')],
}
} satisfies Config

0 comments on commit 74809d6

Please sign in to comment.