From 39686008ef8006c525d66b2c34623eed400895d9 Mon Sep 17 00:00:00 2001 From: jixinbao Date: Fri, 2 Aug 2024 17:44:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95=20uni.createSelector?= =?UTF-8?q?Query=20=E4=BC=A0=E9=80=92=20node/fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create-selector-query.test.js | 31 ++++++++++--- .../create-selector-query.uvue | 45 +++++++++++++++++-- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/pages/API/create-selector-query/create-selector-query.test.js b/pages/API/create-selector-query/create-selector-query.test.js index 36d0519b..f434ad6b 100644 --- a/pages/API/create-selector-query/create-selector-query.test.js +++ b/pages/API/create-selector-query/create-selector-query.test.js @@ -58,12 +58,12 @@ describe('nodes-info', () => { const child = await page.$('.node-child') const childData = await child.data() expect(childData.top > 100).toBe(true) - }) - - it('multi-child', async () => { - const pageData = await page.data() - expect(pageData.selectCount).toBe(1) - expect(pageData.selectAllCount).toBe(2) + }) + + it('multi-child', async () => { + const pageData = await page.data() + expect(pageData.selectCount).toBe(1) + expect(pageData.selectAllCount).toBe(2) }) // #ifdef APP @@ -74,6 +74,23 @@ describe('nodes-info', () => { }) */ // #endif + it('test filelds', async () => { + if (process.env.uniTestPlatformInfo.startsWith('web')) { + expect(true).toBe(true) + } else { + const pageData = await page.data() + expect(pageData.fieldsResultContainNode).toBe(true) + } + }) + + it('test node', async () => { + if (process.env.uniTestPlatformInfo.startsWith('web')) { + expect(true).toBe(true) + } else { + const pageData = await page.data() + expect(pageData.nodeResultContainNode).toBe(true) + } + }) }) async function getRootNode(selector) { @@ -89,4 +106,4 @@ async function getRootNode(selector) { const data = await page.data() expect(data.rootNodeInfo != null).toBe(true) -} +} diff --git a/pages/API/create-selector-query/create-selector-query.uvue b/pages/API/create-selector-query/create-selector-query.uvue index c3493d56..486dfdcd 100644 --- a/pages/API/create-selector-query/create-selector-query.uvue +++ b/pages/API/create-selector-query/create-selector-query.uvue @@ -42,7 +42,16 @@ 子组件多根节点 子组件多根节点(仅测试,用于验证查询是否超出范围) - + + + 测试.fields + {{fieldsResultContainNode}} + + + 测试.node + {{nodeResultContainNode}} + + @@ -77,13 +86,18 @@ // resizeRectValid: false // TODO selectCount: 0, - selectAllCount: 0, + selectAllCount: 0, + fieldsResultContainNode: false, + nodeResultContainNode: false } }, onReady() { const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance) this.selectCount = instance2.$data['selectCount'] as Number this.selectAllCount = instance2.$data['selectAllCount'] as Number + + this.testFields() + this.testNode() }, onResize() { //供自动化测试使用 @@ -142,7 +156,32 @@ } as NodeInfoType) }) }) - } + }, + // test .fields + testFields() { + uni.createSelectorQuery().select('.rect1').fields({ + node: true + } as NodeField, (ret) => { + const isElement = (ret as NodeInfo).node instanceof UniElement + if(isElement){ + this.fieldsResultContainNode = true + } else { + this.fieldsResultContainNode = false + } + }).exec() + }, + // test .node + testNode() { + uni.createSelectorQuery().select('#canvas1').node((ret) => { + const isElement = (ret as NodeInfo).node instanceof UniElement + const isCanvasElement = ((ret as NodeInfo).node as UniCanvasElement).tagName == 'CANVAS' + if(isElement && isCanvasElement){ + this.nodeResultContainNode = true + } else { + this.nodeResultContainNode = false + } + }).exec() + }, } } -- GitLab