| 1 |
import { test, expect } from '@playwright/test'; |
| 2 |
|
| 3 |
import { navigateWithSwup, waitForSwup } from '../support/swup.js'; |
| 4 |
|
| 5 |
test.describe('markup', () => { |
| 6 |
test.beforeEach(async ({ page }) => { |
| 7 |
await page.goto('/page-1.html'); |
| 8 |
await waitForSwup(page); |
| 9 |
}); |
| 10 |
|
| 11 |
test('adds swup class to html element', async ({ page }) => { |
| 12 |
await page.waitForSelector('html.swup-enabled'); |
| 13 |
}); |
| 14 |
|
| 15 |
test('removes swup class from html element', async ({ page }) => { |
| 16 |
const el = page.waitForSelector('html:not(.swup-enabled)'); |
| 17 |
page.evaluate(() => window._swup.destroy()); |
| 18 |
await el; |
| 19 |
}); |
| 20 |
|
| 21 |
test('sets animation classes on html element', async ({ page }) => { |
| 22 |
await page.waitForSelector('html.swup-enabled'); |
| 23 |
|
| 24 |
await page.evaluate(() => { |
| 25 |
const el = document.documentElement; |
| 26 |
window.data = {}; |
| 27 |
window._swup.hooks.on('visit:start', () => window.data.before = el.className); |
| 28 |
window._swup.hooks.on('visit:end', () => window.data.after = el.className); |
| 29 |
window._swup.hooks.on('animation:out:start', () => window.data.leave = el.className); |
| 30 |
window._swup.hooks.on('animation:in:start', () => window.data.enter = el.className); |
| 31 |
}); |
| 32 |
|
| 33 |
await navigateWithSwup(page, '/page-2.html'); |
| 34 |
|
| 35 |
await page.waitForFunction(() => window.data.after !== undefined); |
| 36 |
expect(await page.evaluate(() => window.data)).toMatchObject({ |
| 37 |
before: 'swup-enabled', |
| 38 |
leave: 'swup-enabled is-changing is-animating is-leaving', |
| 39 |
enter: 'swup-enabled is-changing is-rendering', |
| 40 |
after: 'swup-enabled' |
| 41 |
}); |
| 42 |
}); |
| 43 |
|
| 44 |
test('sets animation classes on container element', async ({ page }) => { |
| 45 |
await page.waitForSelector('html.swup-enabled'); |
| 46 |
|
| 47 |
await page.evaluate(() => window._swup.options.animationScope = 'containers'); |
| 48 |
await page.evaluate(() => { |
| 49 |
const el = () => document.querySelector('[data-testid="container"]'); |
| 50 |
window.data = {}; |
| 51 |
window._swup.hooks.on('visit:start', () => window.data.before = el()?.className); |
| 52 |
window._swup.hooks.on('visit:end', () => window.data.after = el()?.className); |
| 53 |
window._swup.hooks.on('animation:out:start', () => window.data.leave = el()?.className); |
| 54 |
window._swup.hooks.on('animation:in:start', () => window.data.enter = el()?.className); |
| 55 |
}); |
| 56 |
|
| 57 |
await navigateWithSwup(page, '/page-2.html'); |
| 58 |
await page.waitForFunction(() => window.data.after !== undefined); |
| 59 |
|
| 60 |
expect(await page.evaluate(() => window.data)).toMatchObject({ |
| 61 |
before: 'wrapper transition-default', |
| 62 |
leave: 'wrapper transition-default is-changing is-animating is-leaving', |
| 63 |
enter: 'wrapper transition-default is-changing is-rendering', |
| 64 |
after: 'wrapper transition-default' |
| 65 |
}); |
| 66 |
}); |
| 67 |
}); |