From 088fc47d2de95b42a8e1be6cc380b10fbab62c5e Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 28 Sep 2023 17:06:02 +0800 Subject: [PATCH] =?UTF-8?q?test(lifecycle):=20onLoad=20=E7=94=9F=E5=91=BD?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=E8=B0=83=E7=94=A8=E8=B7=AF=E7=94=B1=E5=8F=8A?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 10 +- pages/API/navigator/new-page/new-page-1.uvue | 5 + pages/API/navigator/new-page/onLoad.test.js | 98 ++++++++++++++++ pages/API/navigator/new-page/onLoad.uvue | 111 +++++++++++++++++++ 4 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 pages/API/navigator/new-page/onLoad.test.js create mode 100644 pages/API/navigator/new-page/onLoad.uvue diff --git a/pages.json b/pages.json index 4a17638b..12a7091a 100644 --- a/pages.json +++ b/pages.json @@ -263,6 +263,12 @@ "enablePullDownRefresh": true } }, + { + "path": "pages/API/navigator/new-page/onLoad", + "style": { + "navigationBarTitleText": "onLoad 生命周期测试" + } + }, { "path": "pages/API/pull-down-refresh/pull-down-refresh", "style": { @@ -939,13 +945,13 @@ "style": { "navigationBarTitleText": "自定义TabBar" } - }, { + }, + { "path": "pages/API/facial-recognition-verify/facial-recognition-verify", "style": { "navigationBarTitleText": "", "enablePullDownRefresh": false } - } ], "globalStyle": { diff --git a/pages/API/navigator/new-page/new-page-1.uvue b/pages/API/navigator/new-page/new-page-1.uvue index 3895c285..c339940b 100644 --- a/pages/API/navigator/new-page/new-page-1.uvue +++ b/pages/API/navigator/new-page/new-page-1.uvue @@ -39,6 +39,11 @@ export default { }, }) }, + navigateToOnLoadWithType(type: string) { + uni.navigateTo({ + url: `/pages/API/navigator/new-page/onLoad?type=${type}`, + }) + } }, } diff --git a/pages/API/navigator/new-page/onLoad.test.js b/pages/API/navigator/new-page/onLoad.test.js new file mode 100644 index 00000000..8edf7b24 --- /dev/null +++ b/pages/API/navigator/new-page/onLoad.test.js @@ -0,0 +1,98 @@ +jest.setTimeout(20000); +const PAGE_PATH = "/pages/API/navigator/new-page/onLoad"; +const INTERMEDIATE_PAGE_PATH = "/pages/API/navigator/new-page/new-page-1"; +const TARGET_PAGE_PATH = "/pages/API/navigator/new-page/new-page-2"; +let page; + +describe("onLoad", () => { + it("adjustData", async () => { + page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + await page.waitFor(500); + await page.callMethod("navigateToOnLoadWithType", "adjustData"); + await page.waitFor(1000); + const image = await program.screenshot(); + expect(image).toMatchImageSnapshot(); + }); + // 先出现 TARGET_PAGE_PATH 页面,再出现 onLoad 页面, 顺序异常 + // it("navigateTo", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "navigateTo"); + // await page.waitFor(1000); + // page = await program.currentPage(); + // expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); + // }); + // 页面白屏 + // it("navigateBack", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "navigateBack"); + // await page.waitFor(1000); + // page = await program.currentPage(); + // expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); + // }); + // 直接出现 TARGET_PAGE_PATH 页面,又动画了 TARGET_PAGE_PATH 页面 + // it("redirectTo", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "redirectTo"); + // await page.waitFor(1000); + // page = await program.currentPage(); + // expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); + // }); + // 直接出现 TARGET_PAGE_PATH 页面,又动画了 TARGET_PAGE_PATH 页面 + // it("reLaunch", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "reLaunch"); + // await page.waitFor(1000); + // page = await program.currentPage(); + // expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); + // }); + // 页面白屏 + // it("switchTab", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "switchTab"); + // await page.waitFor(1000); + // page = await program.currentPage(); + // expect(page.path).toBe("pages/tabBar/component"); + // }); + // toast 出现在 INTERMEDIATE_PAGE_PATH 页面(非 onLoad 生命周期所在页面) + // 当 navigateTo 到 onLoad 页面时,toast 会被关闭 + // it("showToast", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "showToast"); + // await page.waitFor(1000); + // const image = await program.screenshot(); + // expect(image).toMatchImageSnapshot(); + // }); + // 同 toast + // it("showLoading", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "showLoading"); + // await page.waitFor(1000); + // const image = await program.screenshot(); + // expect(image).toMatchImageSnapshot(); + // }); + // 同 toast + // it("showModal", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "showModal"); + // await page.waitFor(1000); + // const image = await program.screenshot(); + // expect(image).toMatchImageSnapshot(); + // }); + // 同 toast + // it("showActionSheet", async () => { + // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); + // await page.waitFor(500); + // await page.callMethod("navigateToOnLoadWithType", "showActionSheet"); + // await page.waitFor(1000); + // const image = await program.screenshot(); + // expect(image).toMatchImageSnapshot(); + // }); +}); diff --git a/pages/API/navigator/new-page/onLoad.uvue b/pages/API/navigator/new-page/onLoad.uvue new file mode 100644 index 00000000..bab65d35 --- /dev/null +++ b/pages/API/navigator/new-page/onLoad.uvue @@ -0,0 +1,111 @@ + + + -- GitLab