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

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

上级 4c533db4
...@@ -58,6 +58,12 @@ describe('nodes-info', () => { ...@@ -58,6 +58,12 @@ describe('nodes-info', () => {
const child = await page.$('.node-child') const child = await page.$('.node-child')
const childData = await child.data() const childData = await child.data()
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
......
<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>
...@@ -35,12 +38,20 @@ ...@@ -35,12 +38,20 @@
</view> </view>
</view> </view>
</view> </view>
<node-child class="node-child"></node-child> <node-child class="node-child"></node-child>
</view> <text>子组件多根节点</text>
<multi-child ref="multi-child" id="multi-child"></multi-child>
<text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text>
<multi-child id="multi-child-2"></multi-child>
</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 {
...@@ -62,8 +74,17 @@ ...@@ -62,8 +74,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() {
//供自动化测试使用 //供自动化测试使用
...@@ -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.
先完成此消息的编辑!
想要评论请 注册