From 6e761430e2d5e5ff861194ffe1c019d2c10a9c1d Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Fri, 10 May 2024 19:37:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(render):=20=E8=A1=A5=E5=85=85=E7=BB=84?= =?UTF-8?q?=E5=90=88=E5=BC=8F=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 10 +++- pages/index/index.uvue | 13 ++++- .../render/render-composition.uvue | 36 ++++++++++++++ .../{render.uvue => render-options.uvue} | 0 pages/render-function/render/render.test.js | 47 ++++++++++++------- 5 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 pages/render-function/render/render-composition.uvue rename pages/render-function/render/{render.uvue => render-options.uvue} (100%) diff --git a/pages.json b/pages.json index 03bbfa2..3f76e94 100644 --- a/pages.json +++ b/pages.json @@ -711,9 +711,15 @@ } }, { - "path": "pages/render-function/render/render", + "path": "pages/render-function/render/render-options", "style": { - "navigationBarTitleText": "render function" + "navigationBarTitleText": "render 选项式 API" + } + }, + { + "path": "pages/render-function/render/render-composition", + "style": { + "navigationBarTitleText": "render 组合式 API" } }, { diff --git a/pages/index/index.uvue b/pages/index/index.uvue index c42363c..b8d675e 100644 --- a/pages/index/index.uvue +++ b/pages/index/index.uvue @@ -976,7 +976,18 @@ export default { { id: 'render', name: 'render & h()', - url: 'render/render' + children: [ + { + id: 'render-options', + name: 'render 选项式 API', + url: 'render-options' + }, + { + id: 'render-composition', + name: 'render 组合式 API', + url: 'render-composition' + }, + ] }, { id: 'mergeProps', diff --git a/pages/render-function/render/render-composition.uvue b/pages/render-function/render/render-composition.uvue new file mode 100644 index 0000000..5080576 --- /dev/null +++ b/pages/render-function/render/render-composition.uvue @@ -0,0 +1,36 @@ + + + \ No newline at end of file diff --git a/pages/render-function/render/render.uvue b/pages/render-function/render/render-options.uvue similarity index 100% rename from pages/render-function/render/render.uvue rename to pages/render-function/render/render-options.uvue diff --git a/pages/render-function/render/render.test.js b/pages/render-function/render/render.test.js index 31263ea..26ba059 100644 --- a/pages/render-function/render/render.test.js +++ b/pages/render-function/render/render.test.js @@ -1,35 +1,48 @@ -const PAGE_PATH = '/pages/render-function/render/render' +const OPTIONS_PAGE_PATH = '/pages/render-function/render/render-options' +const COMPOSITION_PAGE_PATH = '/pages/render-function/render/render-composition' -describe('/pages/render-function/render/render', () => { - if (process.env.uniTestPlatformInfo.startsWith('web')) { - // TODO: web 端测试未获取到元素 - it('web', async () => { - expect(1).toBe(1) - }) +describe('render-function render', () => { + const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() + const isWeb = platformInfo.startsWith('web') + const isIos = platformInfo.startsWith('ios') + if (isWeb) { + it("web platform test cannot get render dom", async () => { + expect(1).toBe(1); + }); return } let page - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) + const test = async (pagePath) => { + page = await program.reLaunch(pagePath) await page.waitFor('view') - }) - it('component', async () => { + const ComForRenderFunction = await page.$('.component-for-h-function') expect(await ComForRenderFunction.text()).toEqual( 'component for h()' ) const compSlot = await page.$('.comp-slot') expect(await compSlot.text()).toEqual('component slot') - }) - it('text', async () => { - const msgEl = await page.$('.msg') + + let msgEl = await page.$('.msg') expect(await msgEl.text()).toEqual('default msg') - }) - it('button', async () => { + const btnEl = await page.$('.btn') expect(await btnEl.property('type')).toBe('primary') await btnEl.tap() - const msgEl = await page.$('.msg') + msgEl = await page.$('.msg') expect(await msgEl.text()).toEqual('new msg') + } + + it('render options API', async () => { + await test(OPTIONS_PAGE_PATH) + }) + + it('render composition API', async () => { + if (!isIos) { + await test(COMPOSITION_PAGE_PATH) + } else { + // TODO: ios 端 defineOptions + render 页面空白 + expect(1).toBe(1); + } }) }) \ No newline at end of file -- GitLab