diff --git a/pages.json b/pages.json index 1b40f1d8089159d076e26ab693cd356fc5553d34..c37f40576254b7340ff94df5a54b373bcb10f89e 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 0000000000000000000000000000000000000000..d5464d8bad67e1aa22527b90bf6194d5804b9731 --- /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 0000000000000000000000000000000000000000..d1ab7900fed9a83a45cf13cbc50fdb1103446b60 --- /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 0000000000000000000000000000000000000000..f902d49da88def2e4d4218b23c13eb429f6b1998 --- /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 0000000000000000000000000000000000000000..b16ea81153b29863c86f29c13ec65423ad632d7f --- /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 0000000000000000000000000000000000000000..fcdbfb7f709d4fa6160131591a9cecf9e24903f5 --- /dev/null +++ b/pages/API/dialog-page/next-page.uvue @@ -0,0 +1,110 @@ + + +