Skip to content

AI-native design editor. Open-source Figma alternative.

test: seed motion preferences through Playwright storage state

Danila Poyarkova4a916c97a06
diff --git a/tests/e2e/settings/motion.spec.ts b/tests/e2e/settings/motion.spec.ts
index b689a0673..828cf53b3 100644
--- a/tests/e2e/settings/motion.spec.ts
+++ b/tests/e2e/settings/motion.spec.ts
@@ -3,16 +3,32 @@ import { expect, test } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
for (const appearance of [undefined, null, { animations: 'invalid' }]) {
- test(`normalizes legacy animation preferences ${JSON.stringify(appearance)}`, async ({
- page
- }) => {
- await page.emulateMedia({ reducedMotion: 'no-preference' })
- await page.addInitScript((appearance) => {
- localStorage.setItem('open-pencil:preferences:v1', JSON.stringify({ version: 1, appearance }))
- }, appearance)
- await page.goto('/?test')
- await new CanvasHelper(page).waitForInit()
- await expect(page.locator('html')).toHaveAttribute('data-motion', 'full')
+ test.describe(`legacy animation preferences ${JSON.stringify(appearance)}`, () => {
+ test.use({
+ storageState: async ({ baseURL }, use) => {
+ if (!baseURL) throw new Error('Browser test baseURL is required')
+ await use({
+ cookies: [],
+ origins: [
+ {
+ origin: new URL(baseURL).origin,
+ localStorage: [
+ {
+ name: 'open-pencil:preferences:v1',
+ value: JSON.stringify({ version: 1, appearance })
+ }
+ ]
+ }
+ ]
+ })
+ }
+ })
+ test('normalizes the preference', async ({ page }) => {
+ await page.emulateMedia({ reducedMotion: 'no-preference' })
+ await page.goto('/?test')
+ await new CanvasHelper(page).waitForInit()
+ await expect(page.locator('html')).toHaveAttribute('data-motion', 'full')
+ })
})
}
diff --git a/tests/e2e/toolbar/mobile.spec.ts b/tests/e2e/toolbar/mobile.spec.ts
index 8b9cb6900..cc675138f 100644
--- a/tests/e2e/toolbar/mobile.spec.ts
+++ b/tests/e2e/toolbar/mobile.spec.ts
@@ -3,36 +3,49 @@ import { expect, test } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
for (const animations of ['system', 'off'] as const) {
- test(`mobile toolbar retains keyboard navigation with animations ${animations}`, async ({
- page
- }) => {
- await page.addInitScript((animations) => {
- localStorage.setItem(
- 'open-pencil:preferences:v1',
- JSON.stringify({ version: 1, appearance: { animations } })
- )
- }, animations)
- await page.setViewportSize({ width: 390, height: 844 })
- await page.goto('/?test')
- const canvas = new CanvasHelper(page)
- await canvas.waitForInit()
- const toolbar = page.getByTestId('mobile-toolbar-container')
- await expect(toolbar).toHaveAttribute('role', 'toolbar')
- const tools = page.getByTestId('mobile-toolbar-tools')
- await expect(tools).toBeVisible()
- await page.getByTestId('mobile-toolbar-next').click()
- const edit = page.getByTestId('mobile-toolbar-edit')
- await expect(edit).toBeVisible()
- await expect(tools).toHaveCount(0)
- const first = edit.getByRole('button').first()
- await expect(first).toHaveAttribute('aria-label', /.+/)
- await first.focus()
- await first.press('ArrowRight')
- await expect(edit.getByRole('button').nth(1)).toBeFocused()
- await page.getByTestId('mobile-toolbar-prev').click()
- await expect(tools).toBeVisible()
- await expect(edit).toHaveCount(0)
- await expect(tools.getByRole('button').first()).toHaveAttribute('aria-label', /.+/)
- canvas.assertNoErrors()
+ test.describe(`mobile toolbar with animations ${animations}`, () => {
+ test.use({
+ storageState: async ({ baseURL }, use) => {
+ if (!baseURL) throw new Error('Browser test baseURL is required')
+ await use({
+ cookies: [],
+ origins: [
+ {
+ origin: new URL(baseURL).origin,
+ localStorage: [
+ {
+ name: 'open-pencil:preferences:v1',
+ value: JSON.stringify({ version: 1, appearance: { animations } })
+ }
+ ]
+ }
+ ]
+ })
+ }
+ })
+ test('retains keyboard navigation', async ({ page }) => {
+ await page.setViewportSize({ width: 390, height: 844 })
+ await page.goto('/?test')
+ const canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+ const toolbar = page.getByTestId('mobile-toolbar-container')
+ await expect(toolbar).toHaveAttribute('role', 'toolbar')
+ const tools = page.getByTestId('mobile-toolbar-tools')
+ await expect(tools).toBeVisible()
+ await page.getByTestId('mobile-toolbar-next').click()
+ const edit = page.getByTestId('mobile-toolbar-edit')
+ await expect(edit).toBeVisible()
+ await expect(tools).toHaveCount(0)
+ const first = edit.getByRole('button').first()
+ await expect(first).toHaveAttribute('aria-label', /.+/)
+ await first.focus()
+ await first.press('ArrowRight')
+ await expect(edit.getByRole('button').nth(1)).toBeFocused()
+ await page.getByTestId('mobile-toolbar-prev').click()
+ await expect(tools).toBeVisible()
+ await expect(edit).toHaveCount(0)
+ await expect(tools.getByRole('button').first()).toHaveAttribute('aria-label', /.+/)
+ canvas.assertNoErrors()
+ })
})
}