Skip to content

Commit bbe4452

Browse files
committed
wip: add more tests
1 parent ecef92b commit bbe4452

File tree

5 files changed

+106
-14
lines changed

5 files changed

+106
-14
lines changed

packages-private/vapor-e2e-test/__tests__/transition.spec.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,60 @@ describe('vapor transition', () => {
845845
E2E_TIMEOUT,
846846
)
847847

848-
test.todo(
848+
test(
849849
'transition + fallthrough attrs (in-out mode)',
850-
async () => {},
850+
async () => {
851+
const btnSelector = '.if-fallthrough-attr-in-out > button'
852+
const containerSelector = '.if-fallthrough-attr-in-out > div'
853+
854+
expect(await html(containerSelector)).toBe('<div foo="1">one</div>')
855+
856+
// toggle
857+
await click(btnSelector)
858+
await nextTick()
859+
await transitionFinish(duration * 3)
860+
let calls = await page().evaluate(() => {
861+
return (window as any).getCalls('ifInOut')
862+
})
863+
expect(calls).toStrictEqual([
864+
'beforeEnter',
865+
'onEnter',
866+
'afterEnter',
867+
'beforeLeave',
868+
'onLeave',
869+
'afterLeave',
870+
])
871+
872+
expect(await html(containerSelector)).toBe(
873+
'<div foo="1" class="">two</div>',
874+
)
875+
876+
// clear calls
877+
await page().evaluate(() => {
878+
;(window as any).resetCalls('ifInOut')
879+
})
880+
881+
// toggle back
882+
await click(btnSelector)
883+
await nextTick()
884+
await transitionFinish(duration * 3)
885+
886+
calls = await page().evaluate(() => {
887+
return (window as any).getCalls('ifInOut')
888+
})
889+
expect(calls).toStrictEqual([
890+
'beforeEnter',
891+
'onEnter',
892+
'afterEnter',
893+
'beforeLeave',
894+
'onLeave',
895+
'afterLeave',
896+
])
897+
898+
expect(await html(containerSelector)).toBe(
899+
'<div foo="1" class="">one</div>',
900+
)
901+
},
851902
E2E_TIMEOUT,
852903
)
853904
})

packages-private/vapor-e2e-test/transition/App.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let calls = {
2121
enterCancel: [],
2222
withAppear: [],
2323
cssFalse: [],
24+
ifInOut: [],
2425
}
2526
window.getCalls = key => calls[key]
2627
window.resetCalls = key => (calls[key] = [])
@@ -73,6 +74,16 @@ const view = shallowRef(One)
7374
function changeView() {
7475
view.value = view.value === One ? Two : One
7576
}
77+
78+
const SimpleOne = defineVaporComponent({
79+
setup() {
80+
return template('<div>one</div>', true)()
81+
},
82+
})
83+
const viewInOut = shallowRef(SimpleOne)
84+
function changeViewInOut() {
85+
viewInOut.value = viewInOut.value === SimpleOne ? Two : SimpleOne
86+
}
7687
</script>
7788

7889
<template>
@@ -308,6 +319,24 @@ function changeView() {
308319
</div>
309320
<button @click="toggle = !toggle">button fallthrough</button>
310321
</div>
322+
<div class="if-fallthrough-attr-in-out">
323+
<div>
324+
<transition
325+
foo="1"
326+
name="test"
327+
mode="in-out"
328+
@beforeEnter="() => calls.ifInOut.push('beforeEnter')"
329+
@enter="() => calls.ifInOut.push('onEnter')"
330+
@afterEnter="() => calls.ifInOut.push('afterEnter')"
331+
@beforeLeave="() => calls.ifInOut.push('beforeLeave')"
332+
@leave="() => calls.ifInOut.push('onLeave')"
333+
@afterLeave="() => calls.ifInOut.push('afterLeave')"
334+
>
335+
<component :is="viewInOut"></component>
336+
</transition>
337+
</div>
338+
<button @click="changeViewInOut">button</button>
339+
</div>
311340

312341
<div class="vshow">
313342
<button @click="show = !show">Show</button>

packages/runtime-vapor/src/component.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,9 @@ export function createComponent(
236236
instance.block instanceof Element &&
237237
Object.keys(instance.attrs).length
238238
) {
239-
renderEffect(() => {
240-
isApplyingFallthroughProps = true
241-
setDynamicProps(instance.block as Element, [instance.attrs])
242-
isApplyingFallthroughProps = false
243-
})
239+
renderEffect(() =>
240+
applyFallthroughProps(instance.block as Element, instance.attrs),
241+
)
244242
}
245243

246244
resetTracking()
@@ -258,6 +256,15 @@ export function createComponent(
258256

259257
export let isApplyingFallthroughProps = false
260258

259+
export function applyFallthroughProps(
260+
block: Block,
261+
attrs: Record<string, any>,
262+
): void {
263+
isApplyingFallthroughProps = true
264+
setDynamicProps(block as Element, [attrs])
265+
isApplyingFallthroughProps = false
266+
}
267+
261268
/**
262269
* dev only
263270
*/

packages/runtime-vapor/src/components/Transition.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import {
2121
type VaporTransitionHooks,
2222
isFragment,
2323
} from '../block'
24-
import { type VaporComponentInstance, isVaporComponent } from '../component'
24+
import {
25+
type VaporComponentInstance,
26+
applyFallthroughProps,
27+
isVaporComponent,
28+
} from '../component'
2529
import { extend, isArray } from '@vue/shared'
2630
import { renderEffect } from '../renderEffect'
27-
import { setDynamicProps } from '../dom/prop'
2831

2932
const decorate = (t: typeof VaporTransition) => {
3033
t.displayName = 'VaporTransition'
@@ -71,7 +74,7 @@ export const VaporTransition: FunctionalComponent<TransitionProps> =
7174
const resolvedAttrs = extend({}, attrs)
7275
const child = findTransitionBlock(children)
7376
if (child) {
74-
setDynamicProps(child, [resolvedAttrs])
77+
applyFallthroughProps(child, resolvedAttrs)
7578
// ensure fallthrough attrs are not happened again in
7679
// applyTransitionHooks
7780
fallthroughAttrs = false
@@ -185,7 +188,7 @@ export function applyTransitionHooks(
185188

186189
// fallthrough attrs
187190
if (fallthroughAttrs && instance.hasFallthrough) {
188-
setDynamicProps(child, [instance.attrs])
191+
applyFallthroughProps(child, instance.attrs)
189192
}
190193

191194
return resolvedHooks
@@ -256,7 +259,8 @@ export function findTransitionBlock(
256259
if (block instanceof Element) child = block
257260
} else if (isVaporComponent(block)) {
258261
child = findTransitionBlock(block.block)
259-
if (child && child.$key === undefined) child.$key = block.type.__name
262+
// use component id as key
263+
if (child && child.$key === undefined) child.$key = block.uid
260264
} else if (isArray(block)) {
261265
child = block[0] as TransitionBlock
262266
let hasFound = false

packages/runtime-vapor/src/components/TransitionGroup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import {
3131
import {
3232
type ObjectVaporComponent,
3333
type VaporComponentInstance,
34+
applyFallthroughProps,
3435
isVaporComponent,
3536
} from '../component'
3637
import { isForBlock } from '../apiCreateFor'
37-
import { renderEffect, setDynamicProps } from '@vue/runtime-vapor'
38+
import { renderEffect } from '../renderEffect'
3839

3940
const positionMap = new WeakMap<TransitionBlock, DOMRect>()
4041
const newPositionMap = new WeakMap<TransitionBlock, DOMRect>()
@@ -149,7 +150,7 @@ export const VaporTransitionGroup: ObjectVaporComponent = decorate({
149150
insert(slottedBlock, container)
150151
// fallthrough attrs
151152
if (instance!.hasFallthrough) {
152-
renderEffect(() => setDynamicProps(container, [instance!.attrs]))
153+
renderEffect(() => applyFallthroughProps(container, instance!.attrs))
153154
}
154155
return container
155156
} else {

0 commit comments

Comments
 (0)