提交 6db1c7cd 编写于 作者: Anne_LXM's avatar Anne_LXM

调整测试例:因事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取

上级 e864ba45
......@@ -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({
......
......@@ -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 : UniScrollToLowerEvent) {
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;
}
}
}
};
......
......@@ -19,98 +19,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)
})
}
});
......@@ -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>
......
......@@ -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:Pass')
expect(await page.data('isTransitionTest')).toBe('transition:Success')
}
});
......@@ -110,7 +110,7 @@ describe('test swiper', () => {
}else{
expect(changeDetailInfo).toEqual(appDetailRes)
}
expect(await page.data('isChangeTest')).toBe('change:Pass')
expect(await page.data('isChangeTest')).toBe('change:Success')
}
});
......@@ -124,7 +124,7 @@ describe('test swiper', () => {
}else{
expect(animationfinishDetailInfo).toEqual(appDetailRes)
}
expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Pass')
expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Success')
}
});
});
......@@ -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.
先完成此消息的编辑!
想要评论请 注册