From: daiwei Date: Thu, 13 Mar 2025 03:55:31 +0000 (+0800) Subject: test: add more tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=055ca98701fae2b19c533000a72ab62f2ef0aca1;p=thirdparty%2Fvuejs%2Fcore.git test: add more tests --- diff --git a/packages-private/vapor-e2e-test/__tests__/transition.spec.ts b/packages-private/vapor-e2e-test/__tests__/transition.spec.ts index 509751fad8..e7590ef4cd 100644 --- a/packages-private/vapor-e2e-test/__tests__/transition.spec.ts +++ b/packages-private/vapor-e2e-test/__tests__/transition.spec.ts @@ -214,8 +214,141 @@ describe('vapor transition', () => { }, E2E_TIMEOUT, ) - test.todo('transition events without appear', async () => {}, E2E_TIMEOUT) - test.todo('events with arguments', async () => {}, E2E_TIMEOUT) + + test( + 'transition events without appear', + async () => { + const btnSelector = '.if-events-without-appear > button' + const containerSelector = '.if-events-without-appear > div' + const childSelector = `${containerSelector} > div` + + expect(await html(containerSelector)).toBe( + '
content
', + ) + // 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('withOutAppear') + }) + expect(calls).toStrictEqual(['beforeLeave', 'onLeave']) + await nextFrame() + expect(await classList(childSelector)).toStrictEqual([ + 'test', + 'test-leave-active', + 'test-leave-to', + ]) + + expect( + await page().evaluate(() => { + return (window as any).getCalls('withOutAppear') + }), + ).not.contain('afterLeave') + await transitionFinish() + expect(await html(containerSelector)).toBe('') + expect( + await page().evaluate(() => { + return (window as any).getCalls('withOutAppear') + }), + ).toStrictEqual(['beforeLeave', 'onLeave', 'afterLeave']) + + await page().evaluate(() => { + ;(window as any).resetCalls('withOutAppear') + }) + + // enter + expect( + (await transitionStart(btnSelector, childSelector)).classNames, + ).toStrictEqual(['test', 'test-enter-from', 'test-enter-active']) + + calls = await page().evaluate(() => { + return (window as any).getCalls('withOutAppear') + }) + expect(calls).toStrictEqual(['beforeEnter', 'onEnter']) + await nextFrame() + expect(await classList(childSelector)).toStrictEqual([ + 'test', + 'test-enter-active', + 'test-enter-to', + ]) + expect( + await page().evaluate(() => { + return (window as any).getCalls('withOutAppear') + }), + ).not.contain('afterEnter') + await transitionFinish() + expect(await html(containerSelector)).toBe( + '
content
', + ) + expect( + await page().evaluate(() => { + return (window as any).getCalls('withOutAppear') + }), + ).toStrictEqual(['beforeEnter', 'onEnter', 'afterEnter']) + }, + E2E_TIMEOUT, + ) + + test( + 'events with arguments', + async () => { + const btnSelector = '.if-events-with-args > button' + const containerSelector = '.if-events-with-args > div' + const childSelector = `${containerSelector} > div` + + expect(await html(containerSelector)).toBe( + '
content
', + ) + + // leave + await click(btnSelector) + let calls = await page().evaluate(() => { + return (window as any).getCalls('withArgs') + }) + expect(calls).toStrictEqual(['beforeLeave', 'onLeave']) + expect(await classList(childSelector)).toStrictEqual([ + 'test', + 'before-leave', + 'leave', + ]) + + await timeout(200 + buffer) + calls = await page().evaluate(() => { + return (window as any).getCalls('withArgs') + }) + expect(calls).toStrictEqual(['beforeLeave', 'onLeave', 'afterLeave']) + expect(await html(containerSelector)).toBe('') + + await page().evaluate(() => { + ;(window as any).resetCalls('withArgs') + }) + + // enter + await click(btnSelector) + calls = await page().evaluate(() => { + return (window as any).getCalls('withArgs') + }) + expect(calls).toStrictEqual(['beforeEnter', 'onEnter']) + expect(await classList(childSelector)).toStrictEqual([ + 'test', + 'before-enter', + 'enter', + ]) + + await timeout(200 + buffer) + calls = await page().evaluate(() => { + return (window as any).getCalls('withArgs') + }) + expect(calls).toStrictEqual(['beforeEnter', 'onEnter', 'afterEnter']) + expect(await html(containerSelector)).toBe( + '
content
', + ) + }, + E2E_TIMEOUT, + ) + test.todo('onEnterCancelled', async () => {}, E2E_TIMEOUT) test.todo('transition on appear', async () => {}, E2E_TIMEOUT) test.todo('transition events with appear', async () => {}, E2E_TIMEOUT) @@ -353,11 +486,11 @@ describe('vapor transition', () => { await nextFrame() expect(await isVisible(containerSelector)).toBe(true) - const calls = await page().evaluate(() => { - return (window as any).calls - }) - - expect(calls).toStrictEqual([ + expect( + await page().evaluate(() => { + return (window as any).getCalls('basic') + }), + ).toStrictEqual([ 'beforeAppear', 'onAppear', 'afterAppear', diff --git a/packages-private/vapor-e2e-test/transition/App.vue b/packages-private/vapor-e2e-test/transition/App.vue index b5f2e77ab3..19b2c97a21 100644 --- a/packages-private/vapor-e2e-test/transition/App.vue +++ b/packages-private/vapor-e2e-test/transition/App.vue @@ -4,8 +4,13 @@ const show = ref(true) const toggle = ref(true) const count = ref(0) -const calls = [] -window.calls = calls +let calls = { + basic: [], + withOutAppear: [], + withArgs: [] +} +window.getCalls = (key) => calls[key] +window.resetCalls = (key) => calls[key] = [] import VaporCompA from './components/VaporCompA.vue' import VaporCompB from './components/VaporCompB.vue' @@ -47,14 +52,8 @@ const name = ref('test')
- +
content
@@ -69,6 +68,44 @@ const name = ref('test')
+
+
+ +
content
+
+
+ +
+
+
+ +
content
+
+
+ +
@@ -78,18 +115,11 @@ const name = ref('test')
- +

vIf

@@ -152,7 +182,7 @@ const name = ref('test') }