2020-05-07 23:10:28 +08:00
|
|
|
import { E2E_TIMEOUT, setupPuppeteer } from '../e2eUtils'
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
describe('e2e: Transition', () => {
|
2020-05-11 23:52:08 +08:00
|
|
|
const { page, html, classList } = setupPuppeteer()
|
2020-05-07 23:10:28 +08:00
|
|
|
const baseUrl = `file://${path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../transition/index.html'
|
|
|
|
)}`
|
2020-05-11 23:52:08 +08:00
|
|
|
|
2020-05-07 23:10:28 +08:00
|
|
|
const container = '#test'
|
|
|
|
|
2020-05-11 23:52:08 +08:00
|
|
|
const duration = 50
|
|
|
|
const buffer = 10
|
|
|
|
const transitionFinish = () =>
|
|
|
|
new Promise(r => {
|
|
|
|
setTimeout(r, duration + buffer)
|
|
|
|
})
|
|
|
|
|
|
|
|
const nextFrame = () => {
|
|
|
|
return page().evaluate(() => {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
requestAnimationFrame(resolve)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-07 23:10:28 +08:00
|
|
|
test(
|
|
|
|
'basic transition',
|
|
|
|
async () => {
|
|
|
|
await page().goto(baseUrl)
|
|
|
|
await page().waitFor('#app')
|
2020-05-11 23:52:08 +08:00
|
|
|
expect(await html(container)).toBe('<div class="test">content</div>')
|
2020-05-07 23:10:28 +08:00
|
|
|
|
2020-05-11 23:52:08 +08:00
|
|
|
const leaveStartClasses = await page().evaluate(() => {
|
|
|
|
document.querySelector('button')!.click()
|
|
|
|
return Promise.resolve().then(() => {
|
|
|
|
return document.querySelector('#test div')!.className.split(/\s+/g)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(leaveStartClasses).toStrictEqual([
|
2020-05-07 23:10:28 +08:00
|
|
|
'test',
|
|
|
|
'v-leave-active',
|
|
|
|
'v-leave-from'
|
|
|
|
])
|
2020-05-11 23:52:08 +08:00
|
|
|
|
|
|
|
await nextFrame()
|
|
|
|
expect(await classList('#test div')).toStrictEqual([
|
|
|
|
'test',
|
|
|
|
'v-leave-active',
|
|
|
|
'v-leave-to'
|
|
|
|
])
|
|
|
|
|
|
|
|
await transitionFinish()
|
|
|
|
expect(await html('#test')).toBe('<!--v-if-->')
|
|
|
|
|
|
|
|
const enterStartClasses = await page().evaluate(() => {
|
|
|
|
document.querySelector('button')!.click()
|
|
|
|
return Promise.resolve().then(() => {
|
|
|
|
return document.querySelector('#test div')!.className.split(/\s+/g)
|
2020-05-07 23:10:28 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-11 23:52:08 +08:00
|
|
|
expect(enterStartClasses).toStrictEqual([
|
2020-05-07 23:10:28 +08:00
|
|
|
'test',
|
|
|
|
'v-enter-active',
|
|
|
|
'v-enter-from'
|
|
|
|
])
|
2020-05-11 23:52:08 +08:00
|
|
|
|
|
|
|
await nextFrame()
|
|
|
|
expect(await classList('#test div')).toStrictEqual([
|
|
|
|
'test',
|
|
|
|
'v-enter-active',
|
|
|
|
'v-enter-to'
|
|
|
|
])
|
|
|
|
|
|
|
|
await transitionFinish()
|
|
|
|
expect(await html('#test')).toBe('<div class="test">content</div>')
|
2020-05-07 23:10:28 +08:00
|
|
|
},
|
|
|
|
E2E_TIMEOUT
|
|
|
|
)
|
|
|
|
})
|