From 4b21f5756e05561eec68450bee03b17f368c1c6b Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Fri, 12 Jul 2024 16:45:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=20onBackPress=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 | 24 +++++++++++++ .../on-back-press-child-composition.uvue | 12 +++++++ .../on-back-press-child-options.uvue | 14 ++++++++ .../on-back-press-composition.uvue | 28 +++++++++++++++ .../onBackPress/on-back-press-options.uvue | 30 ++++++++++++++++ .../page/onBackPress/on-back-press.test.js | 34 +++++++++++++++++++ pages/lifecycle/page/page-composition.uvue | 15 +++++--- pages/lifecycle/page/page-options.uvue | 6 ++++ 8 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue create mode 100644 pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue create mode 100644 pages/lifecycle/page/onBackPress/on-back-press-composition.uvue create mode 100644 pages/lifecycle/page/onBackPress/on-back-press-options.uvue create mode 100644 pages/lifecycle/page/onBackPress/on-back-press.test.js diff --git a/pages.json b/pages.json index f028d2f..08d184b 100644 --- a/pages.json +++ b/pages.json @@ -624,6 +624,30 @@ "enablePullDownRefresh": true } }, + { + "path": "pages/lifecycle/page/onBackPress/on-back-press-options", + "style": { + "navigationBarTitleText": "onBackPress 选项式 API" + } + }, + { + "path": "pages/lifecycle/page/onBackPress/on-back-press-child-options", + "style": { + "navigationBarTitleText": "onBackPress 选项式 API" + } + }, + { + "path": "pages/lifecycle/page/onBackPress/on-back-press-composition", + "style": { + "navigationBarTitleText": "onBackPress 组合式 API" + } + }, + { + "path": "pages/lifecycle/page/onBackPress/on-back-press-child-composition", + "style": { + "navigationBarTitleText": "onBackPress 组合式 API" + } + }, { "path": "pages/lifecycle/component/component-options", "style": { diff --git a/pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue b/pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue new file mode 100644 index 0000000..c6fe93c --- /dev/null +++ b/pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue b/pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue new file mode 100644 index 0000000..d0a3599 --- /dev/null +++ b/pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/pages/lifecycle/page/onBackPress/on-back-press-composition.uvue b/pages/lifecycle/page/onBackPress/on-back-press-composition.uvue new file mode 100644 index 0000000..c32c5ee --- /dev/null +++ b/pages/lifecycle/page/onBackPress/on-back-press-composition.uvue @@ -0,0 +1,28 @@ + + + \ No newline at end of file diff --git a/pages/lifecycle/page/onBackPress/on-back-press-options.uvue b/pages/lifecycle/page/onBackPress/on-back-press-options.uvue new file mode 100644 index 0000000..5887ae6 --- /dev/null +++ b/pages/lifecycle/page/onBackPress/on-back-press-options.uvue @@ -0,0 +1,30 @@ + + + \ No newline at end of file diff --git a/pages/lifecycle/page/onBackPress/on-back-press.test.js b/pages/lifecycle/page/onBackPress/on-back-press.test.js new file mode 100644 index 0000000..49e9c95 --- /dev/null +++ b/pages/lifecycle/page/onBackPress/on-back-press.test.js @@ -0,0 +1,34 @@ +jest.setTimeout(30000) +const OPTIONS_PAGE_PATH = '/pages/lifecycle/page/onBackPress/on-back-press-options' +const OPTIONS_CHILD_PAGE_PATH = '/pages/lifecycle/page/onBackPress/on-back-press-child-options' +const COMPOSITION_PAGE_PATH = '/pages/lifecycle/page/onBackPress/on-back-press-composition' +const COMPOSITION_CHILD_PAGE_PATH = '/pages/lifecycle/page/onBackPress/on-back-press-child-composition' + +describe('onBackPress 返回值', () => { + const test = async (pagePath, childPagePath) => { + const page = await program.navigateTo(pagePath) + await page.waitFor('view') + expect(page.path).toBe(pagePath.substring(1)) + await page.callMethod('goChildPage') + await page.waitFor(800) + const childPage = await program.currentPage() + await childPage.waitFor('view') + expect(childPage.path).toBe(childPagePath.substring(1)) + await program.navigateBack() + let currentPage = await program.currentPage() + expect(currentPage.path).toBe(pagePath.substring(1)) + await program.navigateBack() + currentPage = await program.currentPage() + expect(currentPage.path).toBe(pagePath.substring(1)) + const currentPageData = await currentPage.data('backPressOptions') + expect(currentPageData.from).toBe('navigateBack') + + } + it('onBackPress options API', async () => { + await test(OPTIONS_PAGE_PATH, OPTIONS_CHILD_PAGE_PATH) + }) + + it('onBackPress composition API', async () => { + await test(COMPOSITION_PAGE_PATH, COMPOSITION_CHILD_PAGE_PATH) + }) +}); \ No newline at end of file diff --git a/pages/lifecycle/page/page-composition.uvue b/pages/lifecycle/page/page-composition.uvue index 7193dac..3455ef9 100644 --- a/pages/lifecycle/page/page-composition.uvue +++ b/pages/lifecycle/page/page-composition.uvue @@ -35,14 +35,17 @@ onResize 触发: {{ isOnResizeTriggered }} - - - + + + + @@ -50,7 +53,7 @@ -- GitLab