Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
19ce0d48
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6045
Star
91
Fork
165
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
19ce0d48
编写于
12月 05, 2024
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 新增 element-get-bounding-client-rect-async
上级
f063c53a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
0 deletion
+164
-0
pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async.test.js
...rect-async/element-get-bounding-client-rect-async.test.js
+35
-0
pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async.uvue
...nt-rect-async/element-get-bounding-client-rect-async.uvue
+129
-0
未找到文件。
pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async.test.js
0 → 100644
浏览文件 @
19ce0d48
const
PAGE_PATH
=
'
/pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async
'
const
RECT_X
=
15
;
const
RECT_HEIGHT
=
100
;
const
RECT_LEFT
=
15
;
describe
(
'
element-get-bounding-client-rect-async
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
getBoundingClientRectSync
'
,
async
()
=>
{
await
invokeGetBoundingClientRect
(
'
getBoundingClientRectAsync
'
,
'
rectInfo
'
);
})
})
async
function
invokeGetBoundingClientRect
(
methodName
,
dataName
)
{
await
page
.
callMethod
(
methodName
);
await
page
.
waitFor
(
50
)
const
data
=
await
page
.
data
()
const
width
=
uni
.
getWindowInfo
().
windowWidth
const
rectInfo
=
data
[
dataName
]
expect
(
Math
.
round
(
rectInfo
.
x
)).
toBe
(
RECT_X
)
expect
(
Math
.
round
(
rectInfo
.
y
)
>
90
).
toBe
(
true
)
expect
(
Math
.
round
(
rectInfo
.
width
)).
toBe
(
width
-
15
*
2
)
expect
(
Math
.
round
(
rectInfo
.
height
)).
toBe
(
RECT_HEIGHT
)
expect
(
Math
.
round
(
rectInfo
.
left
)).
toBe
(
RECT_LEFT
)
expect
(
Math
.
round
(
rectInfo
.
top
)
>
90
).
toBe
(
true
)
expect
(
Math
.
round
(
rectInfo
.
right
)).
toBe
(
width
-
15
)
expect
(
Math
.
round
(
rectInfo
.
bottom
)
>
200
).
toBe
(
true
)
}
pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async.uvue
0 → 100644
浏览文件 @
19ce0d48
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view class="page" id="page">
<!-- <page-head :title="title"></page-head> -->
<button class="btn btn-get-all-node-info" @click="getBoundingClientRectAsync">getBoundingClientRectAsync</button>
<view id="rect-test" ref="rect-test" class="rect-test"></view>
<view class="rect-info" v-if="rectInfo">
<view class="node-info-item">
<text class="node-info-item-k">x: </text>
<text class="node-info-item-v">{{rectInfo.x}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">y: </text>
<text class="node-info-item-v">{{rectInfo.y}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">width: </text>
<text class="node-info-item-v">{{rectInfo.width}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">height: </text>
<text class="node-info-item-v">{{rectInfo.height}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">left: </text>
<text class="node-info-item-v">{{rectInfo.left}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">top: </text>
<text class="node-info-item-v">{{rectInfo.top}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">right: </text>
<text class="node-info-item-v">{{rectInfo.right}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">bottom: </text>
<text class="node-info-item-v">{{rectInfo.bottom}}</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
type DomRectType = {
x : number,
y : number,
left : number,
top : number,
right : number,
bottom : number,
width : number,
height : number,
}
export default {
data() {
return {
title: 'getBoundingClientRectAsync',
rectInfo: {
x: 0,
y: 0,
width: 0,
height: 0,
left: 0,
top: 0,
right: 0,
bottom: 0,
} as DomRectType,
}
},
methods: {
getBoundingClientRectAsync() {
(this.$refs["rect-test"] as UniElement).getBoundingClientRectAsync()!.then((rect : DOMRect) => {
this.rectInfo = {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
} as DomRectType;;
})
}
}
}
</script>
<style>
.page {
padding: 15px;
}
.btn {
margin-top: 15px;
}
.rect-test {
margin-top: 15px;
height: 100px;
background-color: dodgerblue;
}
.rect-info {
margin-top: 15px;
flex-direction: column;
}
.node-info-item {
flex-direction: row;
}
.node-info-item-k {
width: 72px;
line-height: 2;
}
.node-info-item-v {
font-weight: bold;
line-height: 2;
}
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录