Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
9739c6b3
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9739c6b3
编写于
6月 12, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整测试例:因事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取
上级
3bb18cf9
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
206 addition
and
131 deletion
+206
-131
pages/component/scroll-view/scroll-view-refresher.test.js
pages/component/scroll-view/scroll-view-refresher.test.js
+16
-11
pages/component/scroll-view/scroll-view-refresher.uvue
pages/component/scroll-view/scroll-view-refresher.uvue
+62
-15
pages/component/scroll-view/scroll-view.test.js
pages/component/scroll-view/scroll-view.test.js
+46
-76
pages/component/scroll-view/scroll-view.uvue
pages/component/scroll-view/scroll-view.uvue
+61
-7
pages/component/swiper/swiper.test.js
pages/component/swiper/swiper.test.js
+3
-3
pages/component/swiper/swiper.uvue
pages/component/swiper/swiper.uvue
+18
-19
未找到文件。
pages/component/scroll-view/scroll-view-refresher.test.js
浏览文件 @
9739c6b3
...
...
@@ -13,14 +13,6 @@ describe('component-native-scroll-view-refresher', () => {
await
page
.
waitFor
(
300
);
});
async
function
eventCheck
(
dataName
,
typeName
){
const
eventInfo
=
await
page
.
data
(
dataName
)
expect
(
eventInfo
.
type
).
toBe
(
typeName
)
expect
(
eventInfo
.
currentTarget
).
not
.
toBeFalsy
();
expect
(
eventInfo
.
target
).
not
.
toBeFalsy
();
expect
(
eventInfo
.
detail
.
dy
).
toBeGreaterThan
(
0
)
}
it
(
'
scroll-view-refresher-screenshot
'
,
async
()
=>
{
//禁止滚动条
await
page
.
setData
({
...
...
@@ -39,12 +31,25 @@ describe('component-native-scroll-view-refresher', () => {
expect
(
await
page
.
data
(
'
refresherrefreshTimes
'
)).
toBe
(
1
)
// 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)){
await
eventCheck
(
'
onRefresherpullingTest
'
,
'
refresherpulling
'
)
expect
(
await
page
.
data
(
'
onRefresherpullingTest
'
)).
toBe
(
'
refresherpulling:Success
'
)
}
await
eventCheck
(
'
refresherrefreshTest
'
,
'
refresherrefresh
'
)
expect
(
await
page
.
data
(
'
refresherrefreshTest
'
)).
toBe
(
'
refresherrefresh:Success
'
)
await
page
.
waitFor
(
1000
);
await
eventCheck
(
'
onRefresherrestoreTest
'
,
'
refresherrestore
'
)
expect
(
await
page
.
data
(
'
onRefresherrestoreTest
'
)).
toBe
(
'
refresherrestore:Success
'
)
});
// 仅App端支持手势下拉刷新
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
it
(
'
check_refresherabort
'
,
async
()
=>
{
await
program
.
swipe
({
startPoint
:
{
x
:
100
,
y
:
500
},
endPoint
:
{
x
:
100
,
y
:
630
},
duration
:
1000
})
await
page
.
waitFor
(
1500
)
expect
(
await
page
.
data
(
'
onRefresherabortTest
'
)).
toBe
(
'
refresherabort:Success
'
)
});
}
it
(
'
check_refresher_snapshot
'
,
async
()
=>
{
await
page
.
setData
({
...
...
pages/component/scroll-view/scroll-view-refresher.uvue
浏览文件 @
9739c6b3
...
...
@@ -13,6 +13,12 @@
</view>
</template>
<script>
type RefresherEventTest = {
type: string;
target: UniElement | null;
currentTarget: UniElement | null;
dy:number;
}
export default {
data() {
return {
...
...
@@ -21,11 +27,11 @@
refresherrefresh: false,
refresherrefreshTimes: 0,
showScrollbar: false,
// 自动化测试
refresherrefreshTest:
null as RefresherEvent|null
,
onRefresherabortTest:
null as RefresherEvent|null
,
onRefresherrestoreTest:
null as RefresherEvent|null
,
onRefresherpullingTest:
null as RefresherEvent|null
// 自动化测试
使用
refresherrefreshTest:
""
,
onRefresherabortTest:
""
,
onRefresherrestoreTest:
""
,
onRefresherpullingTest:
""
};
},
onLoad() {
...
...
@@ -37,31 +43,72 @@
},
methods: {
onRefresherrefresh(e :
RefresherEvent
) {
onRefresherrefresh(e :
UniRefresherEvent)
) {
this.refresherrefresh = true
console.log("onRefresherrefresh--------------下拉刷新触发")
this.refresherrefreshTest = e
console.log("onRefresherrefresh------下拉刷新触发")
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
dy:e.detail.dy,
} as RefresherEventTest,'refresherrefresh')
this.refresherTriggered = true
this.refresherrefreshTimes++
setTimeout(() => {
this.refresherTriggered = false
}, 1500)
},
onRefresherabort(e :
RefresherEvent
) {
onRefresherabort(e :
UniRefresherEvent)
) {
console.log("onRefresherabort------下拉刷新被中止")
this.onRefresherabortTest = e
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
dy:e.detail.dy,
} as RefresherEventTest,'refresherabort')
},
onRefresherrestore(e :
RefresherEvent
) {
onRefresherrestore(e :
UniRefresherEvent)
) {
this.refresherrefresh = false
console.log("onRefresherrestore------下拉刷新被复位")
this.onRefresherrestoreTest = e
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
dy:e.detail.dy,
} as RefresherEventTest,'refresherrestore')
},
onRefresherpulling(e :
RefresherEvent
) {
onRefresherpulling(e :
UniRefresherEvent)
) {
console.log("onRefresherpulling------拉刷新控件被下拉-dy=" + e.detail.dy)
this.onRefresherpullingTest = e
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
dy:e.detail.dy,
} as RefresherEventTest,'refresherpulling')
},
onScrolltolower(e : ScrollToLowerEvent) {
onScrolltolower(e :
Uni
ScrollToLowerEvent) {
console.log("onScrolltolower 滚动到底部-----" + e.detail.direction)
},
// 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
checkEventTest(e:RefresherEventTest, eventName:String){
const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement && e.dy>0;
const result = isPass ? `${eventName}:Success` : `${eventName}:Fail`;
switch (eventName){
case 'refresherrefresh':
this.refresherrefreshTest = result
break;
case 'refresherpulling':
this.onRefresherpullingTest = result
break;
case 'refresherrestore':
this.onRefresherrestoreTest = result
break;
case 'refresherabort':
this.onRefresherabortTest = result
break;
default:
break;
}
}
}
};
...
...
pages/component/scroll-view/scroll-view.test.js
浏览文件 @
9739c6b3
...
...
@@ -27,98 +27,68 @@ describe('component-native-scroll-view', () => {
it
(
'
Event scroll-vertical
'
,
async
()
=>
{
// 纵向滚动
await
page
.
setData
({
scrollTop
:
100
})
await
page
.
waitFor
(
600
)
//设置top 是否触发scroll 事件
const
topScrollInfo
=
await
page
.
data
(
'
scrollTest
'
)
// const topScrollResult = {
// "scrollLeft": 0,
// "scrollTop": 100,
// "scrollHeight": 450,
// "scrollWidth": 345,
// "deltaX": 0,
// "deltaY": -100
// }
const
{
scrollLeft
,
scrollTop
,
scrollHeight
,
scrollWidth
,
deltaX
,
deltaY
}
=
topScrollInfo
.
detail
expect
(
topScrollInfo
.
type
).
toBe
(
'
scroll
'
)
expect
(
scrollLeft
).
toBe
(
0
)
await
page
.
waitFor
(
1000
)
// bug:在web端scroll事件event参数中detail类型报错
if
(
!
process
.
env
.
UNI_UTS_PLATFORM
.
startsWith
(
'
web
'
)){
// 设置top 是否触发scroll 事件
const
topScrollDetail
=
await
page
.
data
(
'
scrollDetailTest
'
)
expect
(
topScrollDetail
.
scrollLeft
).
toBe
(
0
)
// Android 差异scrollTop:99.809525
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)){
expect
(
scrollTop
).
toBe
(
100
)
expect
(
topScrollDetail
.
scrollTop
).
toBe
(
100
)
}
expect
(
scrollHeight
).
toBeGreaterThan
(
0
)
expect
(
scrollWidth
).
toBeGreaterThan
(
0
)
expect
(
deltaX
).
toBe
(
0
)
expect
(
deltaY
).
toBe
(
-
100
)
expect
(
topScrollInfo
.
currentTarget
).
not
.
toBeFalsy
();
expect
(
topScrollInfo
.
target
).
not
.
toBeFalsy
();
// expect(topScrollInfo.detail).toEqual(topScrollResult);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
expect
(
topScrollInfo
.
timeStamp
).
toBeGreaterThan
(
0
)
expect
(
topScrollDetail
.
scrollHeight
).
toBeGreaterThan
(
0
)
expect
(
topScrollDetail
.
scrollWidth
).
toBeGreaterThan
(
0
)
expect
(
topScrollDetail
.
deltaX
).
toBe
(
0
)
expect
(
topScrollDetail
.
deltaY
).
toBe
(
-
100
)
}
expect
(
await
page
.
data
(
'
isScrollTest
'
)).
toBe
(
'
scroll:Success
'
)
})
it
(
'
Event scroll-horizontal
'
,
async
()
=>
{
// 横向滚动
console
.
log
(
'
scrollLeft
'
,
await
page
.
data
(
'
scrollLeft
'
))
await
page
.
setData
({
scrollLeft
:
220
})
await
page
.
waitFor
(
600
)
if
(
!
process
.
env
.
UNI_UTS_PLATFORM
.
startsWith
(
'
web
'
)){
//设置left 是否触发scroll 事件
const
leftScrollInfo
=
await
page
.
data
(
'
scrollTest
'
)
// const leftScrollResult = {
// "scrollLeft": 220,
// "scrollTop": 0,
// "scrollHeight": 150,
// "scrollWidth": 1036,
// "deltaX": -100,
// "deltaY": 0
// }
const
{
scrollLeft
,
scrollTop
,
scrollHeight
,
scrollWidth
,
deltaX
,
deltaY
}
=
leftScrollInfo
.
detail
console
.
log
(
'
deltaX
'
,
deltaX
)
expect
(
leftScrollInfo
.
type
).
toBe
(
'
scroll
'
)
const
leftScrollDetail
=
await
page
.
data
(
'
scrollDetailTest
'
)
// Android 差异scrollLeft:219.80952
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)){
expect
(
scrollLeft
).
toBe
(
220
)
expect
(
leftScrollDetail
.
scrollLeft
).
toBe
(
220
)
}
expect
(
scrollTop
).
toBe
(
0
)
expect
(
scrollHeight
).
toBeGreaterThan
(
0
)
expect
(
scrollWidth
).
toBeGreaterThan
(
0
)
expect
(
deltaX
).
toBe
(
-
100
)
expect
(
deltaY
).
toBe
(
0
)
expect
(
leftScrollInfo
.
currentTarget
).
not
.
toBeFalsy
();
expect
(
leftScrollInfo
.
target
).
not
.
toBeFalsy
();
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
expect
(
leftScrollInfo
.
timeStamp
).
toBeGreaterThan
(
0
)
expect
(
leftScrollDetail
.
scrollTop
).
toBe
(
0
)
expect
(
leftScrollDetail
.
scrollHeight
).
toBeGreaterThan
(
0
)
expect
(
leftScrollDetail
.
scrollWidth
).
toBeGreaterThan
(
0
)
expect
(
leftScrollDetail
.
deltaX
).
toBe
(
-
100
)
expect
(
leftScrollDetail
.
deltaY
).
toBe
(
0
)
}
expect
(
await
page
.
data
(
'
isScrollTest
'
)).
toBe
(
'
scroll:Success
'
)
})
it
(
'
Event scrolltolower-滚动到底部/右边
'
,
async
()
=>
{
// 滚动到底部scrollTop:300,
// 滚动到底部scrollTop:300,
是否触发scrolltolower事件
await
page
.
setData
({
scrollTop
:
300
})
await
page
.
waitFor
(
600
)
//设置top 是否触发scrolltolower事件
const
toLowerInfo
=
await
page
.
data
(
'
toLowerTest
'
)
expect
(
toLowerInfo
.
type
).
toBe
(
'
scrolltolower
'
)
expect
(
toLowerInfo
.
detail
.
direction
).
toBe
(
'
bottom
'
)
expect
(
toLowerInfo
.
currentTarget
).
not
.
toBeFalsy
();
expect
(
toLowerInfo
.
target
).
not
.
toBeFalsy
();
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
expect
(
toLowerInfo
.
timeStamp
).
toBeGreaterThan
(
0
)
}
expect
(
await
page
.
data
(
'
isScrolltolowerTest
'
)).
toBe
(
'
scrolltolower:Success-bottom
'
)
})
it
(
'
Event scrolltoupper-滚动到顶部/左边
'
,
async
()
=>
{
// 滚动到顶部scrollTop: 0,
//
await page.setData({scrollTop: 0})
await
page
.
callMethod
(
'
goTop
'
)
// 滚动到顶部scrollTop: 0,
是否触发scrolltoupper事件
await
page
.
setData
({
scrollTop
:
0
})
//
await page.callMethod('goTop')
await
page
.
waitFor
(
600
)
//设置top 是否触发scrolltoupper事件
const
toUpperInfo
=
await
page
.
data
(
'
toUpperTest
'
)
expect
(
toUpperInfo
.
type
).
toBe
(
'
scrolltoupper
'
)
expect
(
toUpperInfo
.
detail
.
direction
).
toBe
(
'
top
'
)
expect
(
toUpperInfo
.
currentTarget
).
not
.
toBeFalsy
();
expect
(
toUpperInfo
.
target
).
not
.
toBeFalsy
();
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
expect
(
toUpperInfo
.
timeStamp
).
toBeGreaterThan
(
0
)
}
expect
(
await
page
.
data
(
'
isScrolltoupperTest
'
)).
toBe
(
'
scrolltoupper:Success-top
'
)
})
if
(
!
process
.
env
.
UNI_UTS_PLATFORM
.
startsWith
(
'
web
'
)){
it
(
'
Event scrollend-滚动结束时触发仅App端支持
'
,
async
()
=>
{
const
endDetail
=
await
page
.
data
(
'
scrollEndDetailTest
'
)
expect
(
endDetail
.
scrollLeft
).
toBe
(
0
)
expect
(
endDetail
.
scrollTop
).
toBe
(
0
)
expect
(
endDetail
.
deltaY
).
toBe
(
0
)
expect
(
endDetail
.
deltaX
).
toBe
(
0
)
expect
(
endDetail
.
scrollHeight
).
toBeGreaterThan
(
0
)
expect
(
endDetail
.
scrollWidth
).
toBeGreaterThan
(
0
)
})
}
});
pages/component/scroll-view/scroll-view.uvue
浏览文件 @
9739c6b3
...
...
@@ -63,6 +63,12 @@
<!-- #endif -->
</template>
<script lang="uts">
type ScrollEventTest = {
type: string;
target: UniElement | null;
currentTarget: UniElement | null;
direction?:string
}
export default {
data() {
return {
...
...
@@ -71,26 +77,56 @@
scrollLeft:120,
showScrollbar: true,
// 自动化测试
scrollTest:null as ScrollEvent|null,
toUpperTest:null as ScrollToUpperEvent|null,
toLowerTest:null as ScrollToLowerEvent|null
isScrollTest:'',
isScrolltolowerTest:'',
isScrolltoupperTest:'',
// 在web端scroll事件event参数中detail类型报错,先条件编译处理
// #ifndef WEB
scrollDetailTest:null as UniScrollEventDetail|null,
scrollEndDetailTest:null as UniScrollEventDetail|null,
// #endif
}
},
methods: {
upper: function (e : UniScrollToUpperEvent) {
console.log('滚动到顶部/左边',e)
this.toUpperTest = e
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
direction:e.detail.direction,
} as ScrollEventTest,'scrolltoupper')
},
lower: function (e : UniScrollToLowerEvent) {
console.log('滚动到底部/右边',e)
this.toLowerTest = e
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
direction:e.detail.direction,
} as ScrollEventTest,'scrolltolower')
},
scroll: function (e : UniScrollEvent) {
this.scrollTest = e
// #ifndef WEB
this.scrollDetailTest = e.detail
// #endif
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget
} as ScrollEventTest,'scroll')
this.oldScrollTop = e.detail.scrollTop
},
end: function (e : UniScrollEvent){
console.log('滚动结束时触发',e)
// #ifndef WEB
this.scrollEndDetailTest = e.detail
// #endif
this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget
} as ScrollEventTest,'scrollend')
},
goTop: function () {
// 解决view层不同步的问题
...
...
@@ -102,8 +138,26 @@
icon: 'none',
title: '纵向滚动 scrollTop 值已被修改为 0',
})
},
// 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
checkEventTest(e:ScrollEventTest, eventName:String){
const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement;
const result = isPass ? `${eventName}:Success` : `${eventName}:Fail`;
switch (eventName){
case 'scroll':
this.isScrollTest = result
break;
case 'scrolltolower':
this.isScrolltolowerTest = result + `-${e.direction}`
break;
case 'scrolltoupper':
this.isScrolltoupperTest = result + `-${e.direction}`
break;
default:
break;
}
},
},
}
</script>
...
...
pages/component/swiper/swiper.test.js
浏览文件 @
9739c6b3
...
...
@@ -98,7 +98,7 @@ describe('test swiper', () => {
expect
(
transitionDetailInfo
.
dy
).
toBe
(
0
)
}
expect
(
transitionDetailInfo
.
dx
).
not
.
toBe
(
0
)
expect
(
await
page
.
data
(
'
isTransitionTest
'
)).
toBe
(
'
transition:
Pa
ss
'
)
expect
(
await
page
.
data
(
'
isTransitionTest
'
)).
toBe
(
'
transition:
Succe
ss
'
)
}
});
...
...
@@ -110,7 +110,7 @@ describe('test swiper', () => {
}
else
{
expect
(
changeDetailInfo
).
toEqual
(
appDetailRes
)
}
expect
(
await
page
.
data
(
'
isChangeTest
'
)).
toBe
(
'
change:
Pa
ss
'
)
expect
(
await
page
.
data
(
'
isChangeTest
'
)).
toBe
(
'
change:
Succe
ss
'
)
}
});
...
...
@@ -124,7 +124,7 @@ describe('test swiper', () => {
}
else
{
expect
(
animationfinishDetailInfo
).
toEqual
(
appDetailRes
)
}
expect
(
await
page
.
data
(
'
isAnimationfinishTest
'
)).
toBe
(
'
animationfinish:
Pa
ss
'
)
expect
(
await
page
.
data
(
'
isAnimationfinishTest
'
)).
toBe
(
'
animationfinish:
Succe
ss
'
)
}
});
});
pages/component/swiper/swiper.uvue
浏览文件 @
9739c6b3
...
...
@@ -129,24 +129,6 @@
}
},
methods: {
// 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
checkEventTest(e:SwiperEventTest, eventName:String){
const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement;
const result = isPass ? `${eventName}:Pass` : `${eventName}:NoPass`;
switch (eventName){
case 'change':
this.isChangeTest = result
break;
case 'transition':
this.isTransitionTest = result
break;
case 'animationfinish':
this.isAnimationfinishTest = result
break;
default:
break;
}
},
swiperChange: function (e : UniSwiperChangeEvent) {
// #ifndef APP-ANDROID
this.changeDetailTest = e.detail
...
...
@@ -191,7 +173,24 @@
console.log(e)
}
},
// 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
checkEventTest(e:SwiperEventTest, eventName:String){
const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement;
const result = isPass ? `${eventName}:Success` : `${eventName}:Fail`;
switch (eventName){
case 'change':
this.isChangeTest = result
break;
case 'transition':
this.isTransitionTest = result
break;
case 'animationfinish':
this.isAnimationfinishTest = result
break;
default:
break;
}
},
dotsChange: function (e : UniSwitchChangeEvent) {
this.dotsSelect = e.detail.value
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录