mirror of https://github.com/vuejs/core.git
wip: port tests and fix bugs
This commit is contained in:
parent
055ca98701
commit
b1b11c7de2
|
@ -349,8 +349,55 @@ describe('vapor transition', () => {
|
||||||
E2E_TIMEOUT,
|
E2E_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
test.todo('onEnterCancelled', async () => {}, E2E_TIMEOUT)
|
test(
|
||||||
test.todo('transition on appear', async () => {}, E2E_TIMEOUT)
|
'onEnterCancelled',
|
||||||
|
async () => {
|
||||||
|
const btnSelector = '.if-enter-cancelled > button'
|
||||||
|
const containerSelector = '.if-enter-cancelled > div'
|
||||||
|
const childSelector = `${containerSelector} > div`
|
||||||
|
|
||||||
|
expect(await html(containerSelector)).toBe('')
|
||||||
|
|
||||||
|
// enter
|
||||||
|
expect(
|
||||||
|
(await transitionStart(btnSelector, childSelector)).classNames,
|
||||||
|
).toStrictEqual(['test', 'test-enter-from', 'test-enter-active'])
|
||||||
|
await nextFrame()
|
||||||
|
expect(await classList(childSelector)).toStrictEqual([
|
||||||
|
'test',
|
||||||
|
'test-enter-active',
|
||||||
|
'test-enter-to',
|
||||||
|
])
|
||||||
|
|
||||||
|
// cancel (leave)
|
||||||
|
expect(
|
||||||
|
(await transitionStart(btnSelector, childSelector)).classNames,
|
||||||
|
).toStrictEqual(['test', 'test-leave-from', 'test-leave-active'])
|
||||||
|
let calls = await page().evaluate(() => {
|
||||||
|
return (window as any).getCalls('enterCancel')
|
||||||
|
})
|
||||||
|
expect(calls).toStrictEqual(['enterCancelled'])
|
||||||
|
await nextFrame()
|
||||||
|
expect(await classList(childSelector)).toStrictEqual([
|
||||||
|
'test',
|
||||||
|
'test-leave-active',
|
||||||
|
'test-leave-to',
|
||||||
|
])
|
||||||
|
await transitionFinish()
|
||||||
|
expect(await html(containerSelector)).toBe('')
|
||||||
|
},
|
||||||
|
E2E_TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
|
test.todo(
|
||||||
|
'transition on appear',
|
||||||
|
async () => {
|
||||||
|
const btnSelector = '.if-appear > button'
|
||||||
|
const containerSelector = '.if-appear > div'
|
||||||
|
const childSelector = `${containerSelector} > div`
|
||||||
|
},
|
||||||
|
E2E_TIMEOUT,
|
||||||
|
)
|
||||||
test.todo('transition events with appear', async () => {}, E2E_TIMEOUT)
|
test.todo('transition events with appear', async () => {}, E2E_TIMEOUT)
|
||||||
test.todo('no transition detected', async () => {}, E2E_TIMEOUT)
|
test.todo('no transition detected', async () => {}, E2E_TIMEOUT)
|
||||||
test.todo('animations', async () => {}, E2E_TIMEOUT)
|
test.todo('animations', async () => {}, E2E_TIMEOUT)
|
||||||
|
|
|
@ -4,13 +4,16 @@ const show = ref(true)
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const count = ref(0)
|
const count = ref(0)
|
||||||
|
|
||||||
|
const timeout = (fn, time) => setTimeout(fn, time)
|
||||||
|
|
||||||
let calls = {
|
let calls = {
|
||||||
basic: [],
|
basic: [],
|
||||||
withOutAppear: [],
|
withOutAppear: [],
|
||||||
withArgs: []
|
withArgs: [],
|
||||||
|
enterCancel: [],
|
||||||
}
|
}
|
||||||
window.getCalls = (key) => calls[key]
|
window.getCalls = key => calls[key]
|
||||||
window.resetCalls = (key) => calls[key] = []
|
window.resetCalls = key => (calls[key] = [])
|
||||||
|
|
||||||
import VaporCompA from './components/VaporCompA.vue'
|
import VaporCompA from './components/VaporCompA.vue'
|
||||||
import VaporCompB from './components/VaporCompB.vue'
|
import VaporCompB from './components/VaporCompB.vue'
|
||||||
|
@ -52,8 +55,14 @@ const name = ref('test')
|
||||||
</div>
|
</div>
|
||||||
<div class="if-custom-classes">
|
<div class="if-custom-classes">
|
||||||
<div>
|
<div>
|
||||||
<transition enter-from-class="hello-from" enter-active-class="hello-active" enter-to-class="hello-to"
|
<transition
|
||||||
leave-from-class="bye-from" leave-active-class="bye-active" leave-to-class="bye-to">
|
enter-from-class="hello-from"
|
||||||
|
enter-active-class="hello-active"
|
||||||
|
enter-to-class="hello-to"
|
||||||
|
leave-from-class="bye-from"
|
||||||
|
leave-active-class="bye-active"
|
||||||
|
leave-to-class="bye-to"
|
||||||
|
>
|
||||||
<div v-if="toggle" class="test">content</div>
|
<div v-if="toggle" class="test">content</div>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,10 +79,15 @@ const name = ref('test')
|
||||||
</div>
|
</div>
|
||||||
<div class="if-events-without-appear">
|
<div class="if-events-without-appear">
|
||||||
<div>
|
<div>
|
||||||
<transition name="test" @before-enter="() => calls.withOutAppear.push('beforeEnter')"
|
<transition
|
||||||
@enter="() => calls.withOutAppear.push('onEnter')" @after-enter="() => calls.withOutAppear.push('afterEnter')"
|
name="test"
|
||||||
|
@before-enter="() => calls.withOutAppear.push('beforeEnter')"
|
||||||
|
@enter="() => calls.withOutAppear.push('onEnter')"
|
||||||
|
@after-enter="() => calls.withOutAppear.push('afterEnter')"
|
||||||
@beforeLeave="() => calls.withOutAppear.push('beforeLeave')"
|
@beforeLeave="() => calls.withOutAppear.push('beforeLeave')"
|
||||||
@leave="() => calls.withOutAppear.push('onLeave')" @afterLeave="() => calls.withOutAppear.push('afterLeave')">
|
@leave="() => calls.withOutAppear.push('onLeave')"
|
||||||
|
@afterLeave="() => calls.withOutAppear.push('afterLeave')"
|
||||||
|
>
|
||||||
<div v-if="toggle" class="test">content</div>
|
<div v-if="toggle" class="test">content</div>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,31 +95,81 @@ const name = ref('test')
|
||||||
</div>
|
</div>
|
||||||
<div class="if-events-with-args">
|
<div class="if-events-with-args">
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<transition :css="false" name="test" @before-enter="(el) => {
|
<transition
|
||||||
calls.withArgs.push('beforeEnter');
|
:css="false"
|
||||||
|
name="test"
|
||||||
|
@before-enter="
|
||||||
|
el => {
|
||||||
|
calls.withArgs.push('beforeEnter')
|
||||||
el.classList.add('before-enter')
|
el.classList.add('before-enter')
|
||||||
}" @enter="(el, done) => {
|
}
|
||||||
calls.withArgs.push('onEnter');
|
"
|
||||||
|
@enter="
|
||||||
|
(el, done) => {
|
||||||
|
calls.withArgs.push('onEnter')
|
||||||
el.classList.add('enter')
|
el.classList.add('enter')
|
||||||
setTimeout(done, 200)
|
timeout(done, 200)
|
||||||
}" @after-enter="(el) => {
|
}
|
||||||
calls.withArgs.push('afterEnter');
|
"
|
||||||
|
@after-enter="
|
||||||
|
el => {
|
||||||
|
calls.withArgs.push('afterEnter')
|
||||||
el.classList.add('after-enter')
|
el.classList.add('after-enter')
|
||||||
}" @before-leave="(el) => {
|
}
|
||||||
calls.withArgs.push('beforeLeave');
|
"
|
||||||
|
@before-leave="
|
||||||
|
el => {
|
||||||
|
calls.withArgs.push('beforeLeave')
|
||||||
el.classList.add('before-leave')
|
el.classList.add('before-leave')
|
||||||
}" @leave="(el, done) => {
|
}
|
||||||
calls.withArgs.push('onLeave');
|
"
|
||||||
|
@leave="
|
||||||
|
(el, done) => {
|
||||||
|
calls.withArgs.push('onLeave')
|
||||||
el.classList.add('leave')
|
el.classList.add('leave')
|
||||||
setTimeout(done, 200)
|
timeout(done, 200)
|
||||||
}" @after-leave="() => {
|
}
|
||||||
calls.withArgs.push('afterLeave');
|
"
|
||||||
}">
|
@after-leave="
|
||||||
|
() => {
|
||||||
|
calls.withArgs.push('afterLeave')
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
<div v-if="toggle" class="test">content</div>
|
<div v-if="toggle" class="test">content</div>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
<button id="toggleBtn" @click="toggle = !toggle">button</button>
|
<button id="toggleBtn" @click="toggle = !toggle">button</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="if-enter-cancelled">
|
||||||
|
<div>
|
||||||
|
<transition
|
||||||
|
name="test"
|
||||||
|
@enter-cancelled="
|
||||||
|
() => {
|
||||||
|
calls.enterCancel.push('enterCancelled')
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div v-if="!toggle" class="test">content</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
<button @click="toggle = !toggle">cancelled</button>
|
||||||
|
</div>
|
||||||
|
<div class="if-appear">
|
||||||
|
<div>
|
||||||
|
<transition
|
||||||
|
name="test"
|
||||||
|
appear
|
||||||
|
appear-from-class="test-appear-from"
|
||||||
|
appear-to-class="test-appear-to"
|
||||||
|
appear-active-class="test-appear-active"
|
||||||
|
>
|
||||||
|
<div v-if="toggle" class="test">content</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
<button @click="toggle = !toggle">button</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="vshow">
|
<div class="vshow">
|
||||||
<button @click="show = !show">Show</button>
|
<button @click="show = !show">Show</button>
|
||||||
|
@ -115,11 +179,18 @@ const name = ref('test')
|
||||||
</div>
|
</div>
|
||||||
<div class="vif">
|
<div class="vif">
|
||||||
<button @click="toggle = !toggle">Toggle</button>
|
<button @click="toggle = !toggle">Toggle</button>
|
||||||
<Transition appear @beforeEnter="() => calls.basic.push('beforeEnter')" @enter="() => calls.basic.push('onEnter')"
|
<Transition
|
||||||
@afterEnter="() => calls.basic.push('afterEnter')" @beforeLeave="() => calls.basic.push('beforeLeave')"
|
appear
|
||||||
@leave="() => calls.basic.push('onLeave')" @afterLeave="() => calls.basic.push('afterLeave')"
|
@beforeEnter="() => calls.basic.push('beforeEnter')"
|
||||||
@beforeAppear="() => calls.basic.push('beforeAppear')" @appear="() => calls.basic.push('onAppear')"
|
@enter="() => calls.basic.push('onEnter')"
|
||||||
@afterAppear="() => calls.basic.push('afterAppear')">
|
@afterEnter="() => calls.basic.push('afterEnter')"
|
||||||
|
@beforeLeave="() => calls.basic.push('beforeLeave')"
|
||||||
|
@leave="() => calls.basic.push('onLeave')"
|
||||||
|
@afterLeave="() => calls.basic.push('afterLeave')"
|
||||||
|
@beforeAppear="() => calls.basic.push('beforeAppear')"
|
||||||
|
@appear="() => calls.basic.push('onAppear')"
|
||||||
|
@afterAppear="() => calls.basic.push('afterAppear')"
|
||||||
|
>
|
||||||
<h1 v-if="toggle">vIf</h1>
|
<h1 v-if="toggle">vIf</h1>
|
||||||
</Transition>
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -41,11 +41,13 @@ export const VaporTransition: FunctionalComponent<TransitionProps> =
|
||||||
checkTransitionMode(mode)
|
checkTransitionMode(mode)
|
||||||
|
|
||||||
let resolvedProps
|
let resolvedProps
|
||||||
|
let isMounted = false
|
||||||
renderEffect(() => {
|
renderEffect(() => {
|
||||||
resolvedProps = resolveTransitionProps(props)
|
resolvedProps = resolveTransitionProps(props)
|
||||||
|
if (isMounted) {
|
||||||
// only update props for Fragment block, for later reusing
|
// only update props for Fragment block, for later reusing
|
||||||
if (isFragment(children) && children.$transition) {
|
if (isFragment(children)) {
|
||||||
children.$transition.props = resolvedProps
|
if (children.$transition) children.$transition.props = resolvedProps
|
||||||
} else {
|
} else {
|
||||||
// replace existing transition hooks
|
// replace existing transition hooks
|
||||||
const child = findTransitionBlock(children)
|
const child = findTransitionBlock(children)
|
||||||
|
@ -54,6 +56,9 @@ export const VaporTransition: FunctionalComponent<TransitionProps> =
|
||||||
applyTransitionHooks(child, child.$transition)
|
applyTransitionHooks(child, child.$transition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
isMounted = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
applyTransitionHooks(children, {
|
applyTransitionHooks(children, {
|
||||||
|
@ -133,8 +138,13 @@ export function applyTransitionHooks(
|
||||||
block: Block,
|
block: Block,
|
||||||
hooks: VaporTransitionHooks,
|
hooks: VaporTransitionHooks,
|
||||||
): VaporTransitionHooks {
|
): VaporTransitionHooks {
|
||||||
const child = findTransitionBlock(block)
|
const inFragment = isFragment(block)
|
||||||
if (!child) return hooks
|
const child = findTransitionBlock(block, inFragment)
|
||||||
|
if (!child) {
|
||||||
|
// set transition hooks on fragment for reusing during it's updating
|
||||||
|
if (inFragment) setTransitionHooksToFragment(block, hooks)
|
||||||
|
return hooks
|
||||||
|
}
|
||||||
|
|
||||||
const { props, state, delayedLeave } = hooks
|
const { props, state, delayedLeave } = hooks
|
||||||
let resolvedHooks = resolveTransitionHooks(
|
let resolvedHooks = resolveTransitionHooks(
|
||||||
|
@ -146,10 +156,7 @@ export function applyTransitionHooks(
|
||||||
)
|
)
|
||||||
resolvedHooks.delayedLeave = delayedLeave
|
resolvedHooks.delayedLeave = delayedLeave
|
||||||
setTransitionHooks(child, resolvedHooks)
|
setTransitionHooks(child, resolvedHooks)
|
||||||
if (isFragment(block)) {
|
if (inFragment) setTransitionHooksToFragment(block, resolvedHooks)
|
||||||
// also set transition hooks on fragment for reusing during it's updating
|
|
||||||
setTransitionHooksToFragment(block, resolvedHooks)
|
|
||||||
}
|
|
||||||
return resolvedHooks
|
return resolvedHooks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +210,10 @@ export function applyTransitionLeaveHooks(
|
||||||
}
|
}
|
||||||
|
|
||||||
const transitionBlockCache = new WeakMap<Block, TransitionBlock>()
|
const transitionBlockCache = new WeakMap<Block, TransitionBlock>()
|
||||||
export function findTransitionBlock(block: Block): TransitionBlock | undefined {
|
export function findTransitionBlock(
|
||||||
|
block: Block,
|
||||||
|
inFragment: boolean = false,
|
||||||
|
): TransitionBlock | undefined {
|
||||||
if (transitionBlockCache.has(block)) {
|
if (transitionBlockCache.has(block)) {
|
||||||
return transitionBlockCache.get(block)
|
return transitionBlockCache.get(block)
|
||||||
}
|
}
|
||||||
|
@ -238,11 +248,11 @@ export function findTransitionBlock(block: Block): TransitionBlock | undefined {
|
||||||
if (block.insert) {
|
if (block.insert) {
|
||||||
child = block
|
child = block
|
||||||
} else {
|
} else {
|
||||||
child = findTransitionBlock(block.nodes)
|
child = findTransitionBlock(block.nodes, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__ && !child) {
|
if (__DEV__ && !child && !inFragment) {
|
||||||
warn('Transition component has no valid child element')
|
warn('Transition component has no valid child element')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue