From 4d8dab59c88bee47903c561ec83877f29f7050c3 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 8 Aug 2024 17:49:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20dialogPage=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=8F=8A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 29 +++ pages/API/dialog-page/dialog-1.uvue | 165 +++++++++++++ pages/API/dialog-page/dialog-2.uvue | 141 +++++++++++ pages/API/dialog-page/dialog-page.test.js | 271 ++++++++++++++++++++++ pages/API/dialog-page/dialog-page.uvue | 176 ++++++++++++++ pages/API/dialog-page/next-page.uvue | 110 +++++++++ 6 files changed, 892 insertions(+) create mode 100644 pages/API/dialog-page/dialog-1.uvue create mode 100644 pages/API/dialog-page/dialog-2.uvue create mode 100644 pages/API/dialog-page/dialog-page.test.js create mode 100644 pages/API/dialog-page/dialog-page.uvue create mode 100644 pages/API/dialog-page/next-page.uvue diff --git a/pages.json b/pages.json index 1b40f1d8..c37f4057 100644 --- a/pages.json +++ b/pages.json @@ -1143,6 +1143,31 @@ } }, // #endif + { + "path": "pages/API/dialog-page/dialog-page", + "group": "1,4,10", + "style": { + "navigationBarTitleText": "dialogPage | 弹框页面" + } + }, + { + "path": "pages/API/dialog-page/next-page", + "style": { + "navigationBarTitleText": "dialogNextPage" + } + }, + { + "path": "pages/API/dialog-page/dialog-1", + "style": { + "navigationBarTitleText": "dialogPage1" + } + }, + { + "path": "pages/API/dialog-page/dialog-2", + "style": { + "navigationBarTitleText": "dialogPage1" + } + }, { "path": "pages/tabBar/CSS", "style": { @@ -2156,6 +2181,10 @@ { "id": "api.base.animationFrame", "name": "animationFrame" + }, + { + "id": "api.ui.dialogPage", + "name": "dialogPage" } ] }, diff --git a/pages/API/dialog-page/dialog-1.uvue b/pages/API/dialog-page/dialog-1.uvue new file mode 100644 index 00000000..d5464d8b --- /dev/null +++ b/pages/API/dialog-page/dialog-1.uvue @@ -0,0 +1,165 @@ + + + + + diff --git a/pages/API/dialog-page/dialog-2.uvue b/pages/API/dialog-page/dialog-2.uvue new file mode 100644 index 00000000..d1ab7900 --- /dev/null +++ b/pages/API/dialog-page/dialog-2.uvue @@ -0,0 +1,141 @@ + + + + + diff --git a/pages/API/dialog-page/dialog-page.test.js b/pages/API/dialog-page/dialog-page.test.js new file mode 100644 index 00000000..f902d49d --- /dev/null +++ b/pages/API/dialog-page/dialog-page.test.js @@ -0,0 +1,271 @@ +jest.setTimeout(20000) + +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isWeb = platformInfo.startsWith('web') +const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page' +const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page' + +describe('dialog page', () => { + let page; + let initLifeCycleNum; + let lifecycleNum; + beforeAll(async () => { + page = await program.reLaunch(FIRST_PAGE_PATH) + await page.waitFor('view'); + initLifeCycleNum = await page.callMethod('getLifeCycleNum'); + await page.callMethod('setLifeCycleNum', 0) + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(0) + }); + + it('open dialog1', async () => { + await page.callMethod('openDialog1'); + // 无法通过获取 dom 元素来判断是否打开了 dialogPage + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 不应触发父页面的生命周期,应该触发: + // 1. openDialogPage sucess & complete callback + // 2. dialog page 生命周期 + expect(lifecycleNum).toBe(7) + }); + + it('closeDialogPage', async () => { + await page.callMethod('closeDialog'); + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + // closeDialogPage success & complete callback 应被触发 + // dialogPage onUnload 应被触发 + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(4) + }) + + it('openDialog with wrong path', async () => { + await page.callMethod('openDialog1WrongPath') + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(1) + }) + + it('navigateTo nextPage & open Dialog', async () => { + await page.callMethod('goNextPageOpenDialog1') + await page.waitFor(2000) + if (isWeb) { + await page.waitFor(2000) + } + page = await program.currentPage() + expect(page.path).toBe(NEXT_PAGE_PATH.substring(1)) + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(-3) + }) + + it('dialog1 navigateBack', async () => { + await program.navigateBack() + page = await program.currentPage() + // dialogPage onBackPress 返回 true, 应可以拦截 navigateBack + expect(page.path).toBe(NEXT_PAGE_PATH.substring(1)) + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // onBackPress 生命周期应该被触发 + expect(lifecycleNum).toBe(-2) + }) + + it('open dialog2', async () => { + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 应触发前一个 dialogPage 的 onHide + expect(lifecycleNum).toBe(2) + }) + + it('closeDialogPage', async () => { + await page.callMethod('closeDialog') + lifecycleNum = await page.callMethod('getLifeCycleNum') + // 应触发 success & complete 回调 + // 应触发 dialogPage 的 unload,下层的 dialogPage 会先 show 再 unload + expect(lifecycleNum).toBe(-5) + + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + }) + + it('open multiple dialog page', async () => { + await page.callMethod('openDialog1') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image1 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image1).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(-1) + + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image2 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image2).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(3) + }) + + it('openDialogPage to home page', async () => { + await page.callMethod('openDialogPage1ToHomePage') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(7) + }) + + it('dialog2 navigateBack', async () => { + await program.navigateBack() + page = await program.currentPage() + // dialogPage onBackPress 返回 true, 应可以拦截 navigateBack + expect(page.path).toBe(FIRST_PAGE_PATH.substring(1)) + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + // onBackPress 生命周期应该被触发 + expect(lifecycleNum).toBe(9) + }) + + it('close specified dialogPage', async () => { + await page.callMethod('openDialog2') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image1 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image1).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(13) + + await page.callMethod('openDialog1') + await page.waitFor(1000) + if (isWeb) { + await page.waitFor(2000) + } + const image2 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image2).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(19) + + await page.callMethod('closeSpecifiedDialog', 0) + const image3 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image3).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(16) + + await page.callMethod('closeSpecifiedDialog', 1) + const image4 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image4).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(14) + + await page.callMethod('closeSpecifiedDialog', 0) + const image5 = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }); + expect(image5).toSaveImageSnapshot(); + lifecycleNum = await page.callMethod('getLifeCycleNum') + expect(lifecycleNum).toBe(11) + }) + + + afterAll(async () => { + await page.callMethod('setLifeCycleNum', initLifeCycleNum) + }); +}); diff --git a/pages/API/dialog-page/dialog-page.uvue b/pages/API/dialog-page/dialog-page.uvue new file mode 100644 index 00000000..b16ea811 --- /dev/null +++ b/pages/API/dialog-page/dialog-page.uvue @@ -0,0 +1,176 @@ + + + diff --git a/pages/API/dialog-page/next-page.uvue b/pages/API/dialog-page/next-page.uvue new file mode 100644 index 00000000..fcdbfb7f --- /dev/null +++ b/pages/API/dialog-page/next-page.uvue @@ -0,0 +1,110 @@ + + + -- GitLab