From ed8e1549274f3c2c2bc2d2d09f9307dacdb1f492 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 24 Sep 2024 13:19:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(dialogPage):=20=E7=A7=BB=E9=99=A4=20ev?= =?UTF-8?q?entBus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/dialog-page/dialog-1.uvue | 8 --- pages/API/dialog-page/dialog-page.test.js | 12 ++--- pages/API/dialog-page/dialog-page.uvue | 66 +++++++---------------- 3 files changed, 26 insertions(+), 60 deletions(-) diff --git a/pages/API/dialog-page/dialog-1.uvue b/pages/API/dialog-page/dialog-1.uvue index 12d9d747..328088e3 100644 --- a/pages/API/dialog-page/dialog-1.uvue +++ b/pages/API/dialog-page/dialog-1.uvue @@ -55,14 +55,6 @@ // 自动化测试 setLifeCycleNum(state.lifeCycleNum + 1) } - dialogPage.emit('fn1', { from: 'dialog1' }) - dialogPage.emit('fn2', null) - dialogPage.off('fn2', null) - dialogPage.emit('fn1', { from: 'dialog1' }) - dialogPage.emit('fn2', null) - dialogPage.emit('fnOnce', null) - dialogPage.emit('fnOnce', null) - }, onHide() { console.log('dialog 1 onHide') diff --git a/pages/API/dialog-page/dialog-page.test.js b/pages/API/dialog-page/dialog-page.test.js index a8b4c88c..f569b65f 100644 --- a/pages/API/dialog-page/dialog-page.test.js +++ b/pages/API/dialog-page/dialog-page.test.js @@ -37,7 +37,7 @@ describe('dialog page', () => { // 不应触发父页面的生命周期,应该触发: // 1. openDialogPage success & complete callback // 2. dialog page 生命周期 - expect(lifecycleNum).toBe(13) + expect(lifecycleNum).toBe(7) await page.callMethod('setLifeCycleNum', 0) }); @@ -69,7 +69,7 @@ describe('dialog page', () => { await page.callMethod('goNextPageOpenDialog1') await page.waitFor(2000) if (isWeb) { - await page.waitFor(2000) + await page.waitFor(3000) } page = await program.currentPage() expect(page.path).toBe(NEXT_PAGE_PATH.substring(1)) @@ -235,7 +235,7 @@ describe('dialog page', () => { }); expect(image2).toSaveImageSnapshot(); lifecycleNum = await page.callMethod('getLifeCycleNum') - expect(lifecycleNum).toBe(16) + expect(lifecycleNum).toBe(10) await page.callMethod('closeSpecifiedDialog', 0) const image3 = await program.screenshot({ @@ -247,7 +247,7 @@ describe('dialog page', () => { }); expect(image3).toSaveImageSnapshot(); lifecycleNum = await page.callMethod('getLifeCycleNum') - expect(lifecycleNum).toBe(13) + expect(lifecycleNum).toBe(7) await page.callMethod('closeSpecifiedDialog', 1) const image4 = await program.screenshot({ @@ -259,7 +259,7 @@ describe('dialog page', () => { }); expect(image4).toSaveImageSnapshot(); lifecycleNum = await page.callMethod('getLifeCycleNum') - expect(lifecycleNum).toBe(11) + expect(lifecycleNum).toBe(5) await page.callMethod('closeSpecifiedDialog', 0) const image5 = await program.screenshot({ @@ -271,7 +271,7 @@ describe('dialog page', () => { }); expect(image5).toSaveImageSnapshot(); lifecycleNum = await page.callMethod('getLifeCycleNum') - expect(lifecycleNum).toBe(8) + expect(lifecycleNum).toBe(2) }) diff --git a/pages/API/dialog-page/dialog-page.uvue b/pages/API/dialog-page/dialog-page.uvue index 09339034..5b9d2b0d 100644 --- a/pages/API/dialog-page/dialog-page.uvue +++ b/pages/API/dialog-page/dialog-page.uvue @@ -5,11 +5,10 @@ - - - - + dialog1 + + + @@ -44,43 +43,23 @@ }) }, openDialog1() { - const dialogPage = uni.openDialogPage({ - url: '/pages/API/dialog-page/dialog-1?name=dialog1', - success(res) { - console.log('openDialogPage1 success', res) - // 自动化测试 - setLifeCycleNum(state.lifeCycleNum + 1) - }, - fail(err) { - console.log('openDialogPage1 fail', err) - setLifeCycleNum(state.lifeCycleNum - 4) - }, - complete(res) { - console.log('openDialogPage1 complete', res) - // 自动化测试 - setLifeCycleNum(state.lifeCycleNum + 1) - } - }) ! - const fn1 = (options: any | null) => { - console.log('dialogPage1 be triggered fn1', options) + uni.openDialogPage({ + url: '/pages/API/dialog-page/dialog-1?name=dialog1', + success(res) { + console.log('openDialogPage1 success', res) + // 自动化测试 + setLifeCycleNum(state.lifeCycleNum + 1) + }, + fail(err) { + console.log('openDialogPage1 fail', err) + setLifeCycleNum(state.lifeCycleNum - 4) + }, + complete(res) { + console.log('openDialogPage1 complete', res) + // 自动化测试 setLifeCycleNum(state.lifeCycleNum + 1) } - const fn11 = (options: any | null) => { - console.log('dialogPage1 be triggered fn11', options) - setLifeCycleNum(state.lifeCycleNum + 1) - } - const fn2 = (options: any | null) => { - console.log('dialogPage1 be triggered fn2', options) - setLifeCycleNum(state.lifeCycleNum + 1) - } - const fnOnce = (options: any | null) => { - console.log('dialogPage1 be triggered fnOnce', options) - setLifeCycleNum(state.lifeCycleNum + 1) - } - dialogPage.on('fn1', fn1) - dialogPage.on('fn1', fn11) - dialogPage.on('fn2', fn2) - dialogPage.once('fnOnce', fnOnce) + }) }, openDialog2() { uni.openDialogPage({ @@ -194,12 +173,7 @@ }, getLifeCycleNum(): number { return state.lifeCycleNum - }, - privacy() { - uni.openDialogPage({ - url: '/pages/API/dialog-page/dialog-privacytest', - }) - }, + } } } -- GitLab