提交 1d9232f8 编写于 作者: H hdx

test(createSelectorQuery): 新增组件多根节点测试

上级 4c533db4
...@@ -60,6 +60,12 @@ describe('nodes-info', () => { ...@@ -60,6 +60,12 @@ describe('nodes-info', () => {
expect(childData.top > 100).toBe(true) 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)
})
// #ifdef APP // #ifdef APP
//检测onResize获取BoundingClientRect信息是否有效 //检测onResize获取BoundingClientRect信息是否有效
/* it('check_resizeRectValid', async () => { /* it('check_resizeRectValid', async () => {
......
<template> <template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view class="page" id="page"> <view class="page" id="page">
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button> <button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button>
...@@ -36,11 +39,19 @@ ...@@ -36,11 +39,19 @@
</view> </view>
</view> </view>
<node-child class="node-child"></node-child> <node-child class="node-child"></node-child>
<text>子组件多根节点</text>
<multi-child ref="multi-child" id="multi-child"></multi-child>
<text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text>
<multi-child id="multi-child-2"></multi-child>
</view> </view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template> </template>
<script> <script>
import nodeChild from './nodes-info-child.uvue' import nodeChild from './nodes-info-child.uvue'
import multiChild from './selector-query-child-multi.uvue'
type NodeInfoType = { type NodeInfoType = {
left : number | null, left : number | null,
...@@ -53,7 +64,8 @@ ...@@ -53,7 +64,8 @@
export default { export default {
components: { components: {
nodeChild nodeChild,
multiChild
}, },
data() { data() {
return { return {
...@@ -63,8 +75,17 @@ ...@@ -63,8 +75,17 @@
rootNodeInfo: null as NodeInfoType | null, rootNodeInfo: null as NodeInfoType | null,
//供自动化测试使用 //供自动化测试使用
// resizeRectValid: false // resizeRectValid: false
// TODO
selectCount: 0,
selectAllCount: 0,
} }
}, },
onReady() {
const instance = (this.$refs['multi-child'] as ComponentPublicInstance)
this.selectCount = instance.$data['selectCount'] as Number
this.selectAllCount = instance.$data['selectAllCount'] as Number
console.log('selectCount', selectCount, selectAllCount)
},
onResize() { onResize() {
//供自动化测试使用 //供自动化测试使用
/* var rect12Element = uni.getElementById("rect-1-2") /* var rect12Element = uni.getElementById("rect-1-2")
...@@ -130,7 +151,6 @@ ...@@ -130,7 +151,6 @@
<style> <style>
.page { .page {
padding: 15px; padding: 15px;
flex: 1;
} }
.btn { .btn {
......
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
}, },
mounted() { mounted() {
uni.createSelectorQuery().in(this).select('.selector-query-view').boundingClientRect().exec((ret) => { uni.createSelectorQuery().in(this).select('.selector-query-view').boundingClientRect().exec((ret) => {
this.text1 = JSON.stringify(ret) this.text1 = JSON.stringify(ret, null, 2)
if (ret.length == 1) { if (ret.length == 1) {
this.selectCount = ret.length this.selectCount = ret.length
} }
}) })
uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => {
this.text2 = JSON.stringify(ret) this.text2 = JSON.stringify(ret, null, 2)
if (ret.length == 1) { if (ret.length == 1) {
this.selectAllCount = (ret[0] as NodeInfo[]).length this.selectAllCount = (ret[0] as NodeInfo[]).length
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册