提交 9739c6b3 编写于 作者: Anne_LXM's avatar Anne_LXM

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

上级 3bb18cf9
...@@ -12,14 +12,6 @@ describe('component-native-scroll-view-refresher', () => { ...@@ -12,14 +12,6 @@ describe('component-native-scroll-view-refresher', () => {
page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher'); page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher');
await page.waitFor(300); 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 () => { it('scroll-view-refresher-screenshot', async () => {
//禁止滚动条 //禁止滚动条
...@@ -39,12 +31,25 @@ describe('component-native-scroll-view-refresher', () => { ...@@ -39,12 +31,25 @@ describe('component-native-scroll-view-refresher', () => {
expect(await page.data('refresherrefreshTimes')).toBe(1) expect(await page.data('refresherrefreshTimes')).toBe(1)
// 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件 // 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件
if(process.env.uniTestPlatformInfo.startsWith('android')){ 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 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 () => { it('check_refresher_snapshot', async () => {
await page.setData({ await page.setData({
......
...@@ -13,6 +13,12 @@ ...@@ -13,6 +13,12 @@
</view> </view>
</template> </template>
<script> <script>
type RefresherEventTest = {
type: string;
target: UniElement | null;
currentTarget: UniElement | null;
dy:number;
}
export default { export default {
data() { data() {
return { return {
...@@ -21,11 +27,11 @@ ...@@ -21,11 +27,11 @@
refresherrefresh: false, refresherrefresh: false,
refresherrefreshTimes: 0, refresherrefreshTimes: 0,
showScrollbar: false, showScrollbar: false,
// 自动化测试 // 自动化测试使用
refresherrefreshTest:null as RefresherEvent|null, refresherrefreshTest:"",
onRefresherabortTest:null as RefresherEvent|null, onRefresherabortTest:"",
onRefresherrestoreTest:null as RefresherEvent|null, onRefresherrestoreTest:"",
onRefresherpullingTest:null as RefresherEvent|null onRefresherpullingTest:""
}; };
}, },
onLoad() { onLoad() {
...@@ -37,31 +43,72 @@ ...@@ -37,31 +43,72 @@
}, },
methods: { methods: {
onRefresherrefresh(e : RefresherEvent) { onRefresherrefresh(e : UniRefresherEvent)) {
this.refresherrefresh = true this.refresherrefresh = true
console.log("onRefresherrefresh--------------下拉刷新触发") console.log("onRefresherrefresh------下拉刷新触发")
this.refresherrefreshTest = e this.checkEventTest({
type:e.type,
target:e.target,
currentTarget:e.currentTarget,
dy:e.detail.dy,
} as RefresherEventTest,'refresherrefresh')
this.refresherTriggered = true this.refresherTriggered = true
this.refresherrefreshTimes++ this.refresherrefreshTimes++
setTimeout(() => { setTimeout(() => {
this.refresherTriggered = false this.refresherTriggered = false
}, 1500) }, 1500)
}, },
onRefresherabort(e : RefresherEvent) { onRefresherabort(e : UniRefresherEvent)) {
console.log("onRefresherabort------下拉刷新被中止") 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 this.refresherrefresh = false
console.log("onRefresherrestore------下拉刷新被复位") 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) 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) 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;
}
} }
} }
}; };
......
...@@ -27,98 +27,68 @@ describe('component-native-scroll-view', () => { ...@@ -27,98 +27,68 @@ describe('component-native-scroll-view', () => {
it('Event scroll-vertical',async()=>{ it('Event scroll-vertical',async()=>{
// 纵向滚动 // 纵向滚动
await page.setData({scrollTop: 100}) await page.setData({scrollTop: 100})
await page.waitFor(600) await page.waitFor(1000)
//设置top 是否触发scroll 事件 // bug:在web端scroll事件event参数中detail类型报错
const topScrollInfo = await page.data('scrollTest') if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
// const topScrollResult = { // 设置top 是否触发scroll 事件
// "scrollLeft": 0, const topScrollDetail = await page.data('scrollDetailTest')
// "scrollTop": 100, expect(topScrollDetail.scrollLeft).toBe(0)
// "scrollHeight": 450, // Android 差异scrollTop:99.809525
// "scrollWidth": 345, if(!process.env.uniTestPlatformInfo.startsWith('android')){
// "deltaX": 0, expect(topScrollDetail.scrollTop).toBe(100)
// "deltaY": -100 }
// } expect(topScrollDetail.scrollHeight).toBeGreaterThan(0)
const {scrollLeft,scrollTop,scrollHeight,scrollWidth,deltaX,deltaY} = topScrollInfo.detail expect(topScrollDetail.scrollWidth).toBeGreaterThan(0)
expect(topScrollInfo.type).toBe('scroll') expect(topScrollDetail.deltaX).toBe(0)
expect(scrollLeft).toBe(0) expect(topScrollDetail.deltaY).toBe(-100)
// Android 差异scrollTop:99.809525
if(!process.env.uniTestPlatformInfo.startsWith('android')){
expect(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(await page.data('isScrollTest')).toBe('scroll:Success')
}) })
it('Event scroll-horizontal',async()=>{ it('Event scroll-horizontal',async()=>{
// 横向滚动 // 横向滚动
console.log('scrollLeft',await page.data('scrollLeft'))
await page.setData({scrollLeft:220}) await page.setData({scrollLeft:220})
await page.waitFor(600) await page.waitFor(600)
//设置left 是否触发scroll 事件 if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
const leftScrollInfo = await page.data('scrollTest') //设置left 是否触发scroll 事件
// const leftScrollResult = { const leftScrollDetail = await page.data('scrollDetailTest')
// "scrollLeft": 220, // Android 差异scrollLeft:219.80952
// "scrollTop": 0, if(!process.env.uniTestPlatformInfo.startsWith('android')){
// "scrollHeight": 150, expect(leftScrollDetail.scrollLeft).toBe(220)
// "scrollWidth": 1036, }
// "deltaX": -100, expect(leftScrollDetail.scrollTop).toBe(0)
// "deltaY": 0 expect(leftScrollDetail.scrollHeight).toBeGreaterThan(0)
// } expect(leftScrollDetail.scrollWidth).toBeGreaterThan(0)
const {scrollLeft,scrollTop,scrollHeight,scrollWidth,deltaX,deltaY} = leftScrollInfo.detail expect(leftScrollDetail.deltaX).toBe(-100)
console.log('deltaX',deltaX) expect(leftScrollDetail.deltaY).toBe(0)
expect(leftScrollInfo.type).toBe('scroll')
// Android 差异scrollLeft:219.80952
if(!process.env.uniTestPlatformInfo.startsWith('android')){
expect(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(await page.data('isScrollTest')).toBe('scroll:Success')
}) })
it('Event scrolltolower-滚动到底部/右边',async()=>{ it('Event scrolltolower-滚动到底部/右边',async()=>{
// 滚动到底部scrollTop:300, // 滚动到底部scrollTop:300,是否触发scrolltolower事件
await page.setData({scrollTop: 300}) await page.setData({scrollTop: 300})
await page.waitFor(600) await page.waitFor(600)
//设置top 是否触发scrolltolower事件 expect(await page.data('isScrolltolowerTest')).toBe('scrolltolower:Success-bottom')
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)
}
}) })
it('Event scrolltoupper-滚动到顶部/左边',async()=>{ it('Event scrolltoupper-滚动到顶部/左边',async()=>{
// 滚动到顶部scrollTop: 0, // 滚动到顶部scrollTop: 0,是否触发scrolltoupper事件
// await page.setData({scrollTop: 0}) await page.setData({scrollTop: 0})
await page.callMethod('goTop') // await page.callMethod('goTop')
await page.waitFor(600) await page.waitFor(600)
//设置top 是否触发scrolltoupper事件 expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
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)
}
}) })
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 @@ ...@@ -63,6 +63,12 @@
<!-- #endif --> <!-- #endif -->
</template> </template>
<script lang="uts"> <script lang="uts">
type ScrollEventTest = {
type: string;
target: UniElement | null;
currentTarget: UniElement | null;
direction?:string
}
export default { export default {
data() { data() {
return { return {
...@@ -71,26 +77,56 @@ ...@@ -71,26 +77,56 @@
scrollLeft:120, scrollLeft:120,
showScrollbar: true, showScrollbar: true,
// 自动化测试 // 自动化测试
scrollTest:null as ScrollEvent|null, isScrollTest:'',
toUpperTest:null as ScrollToUpperEvent|null, isScrolltolowerTest:'',
toLowerTest:null as ScrollToLowerEvent|null isScrolltoupperTest:'',
// 在web端scroll事件event参数中detail类型报错,先条件编译处理
// #ifndef WEB
scrollDetailTest:null as UniScrollEventDetail|null,
scrollEndDetailTest:null as UniScrollEventDetail|null,
// #endif
} }
}, },
methods: { methods: {
upper: function (e : UniScrollToUpperEvent) { upper: function (e : UniScrollToUpperEvent) {
console.log('滚动到顶部/左边',e) 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) { lower: function (e : UniScrollToLowerEvent) {
console.log('滚动到底部/右边',e) 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) { 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 this.oldScrollTop = e.detail.scrollTop
}, },
end: function (e : UniScrollEvent){ end: function (e : UniScrollEvent){
console.log('滚动结束时触发',e) 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 () { goTop: function () {
// 解决view层不同步的问题 // 解决view层不同步的问题
...@@ -102,7 +138,25 @@ ...@@ -102,7 +138,25 @@
icon: 'none', icon: 'none',
title: '纵向滚动 scrollTop 值已被修改为 0', 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> </script>
......
...@@ -98,7 +98,7 @@ describe('test swiper', () => { ...@@ -98,7 +98,7 @@ describe('test swiper', () => {
expect(transitionDetailInfo.dy).toBe(0) expect(transitionDetailInfo.dy).toBe(0)
} }
expect(transitionDetailInfo.dx).not.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', () => { ...@@ -110,7 +110,7 @@ describe('test swiper', () => {
}else{ }else{
expect(changeDetailInfo).toEqual(appDetailRes) 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', () => { ...@@ -124,7 +124,7 @@ describe('test swiper', () => {
}else{ }else{
expect(animationfinishDetailInfo).toEqual(appDetailRes) expect(animationfinishDetailInfo).toEqual(appDetailRes)
} }
expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Pass') expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Success')
} }
}); });
}); });
...@@ -129,24 +129,6 @@ ...@@ -129,24 +129,6 @@
} }
}, },
methods: { 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) { swiperChange: function (e : UniSwiperChangeEvent) {
// #ifndef APP-ANDROID // #ifndef APP-ANDROID
this.changeDetailTest = e.detail this.changeDetailTest = e.detail
...@@ -191,7 +173,24 @@ ...@@ -191,7 +173,24 @@
console.log(e) 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) { dotsChange: function (e : UniSwitchChangeEvent) {
this.dotsSelect = e.detail.value this.dotsSelect = e.detail.value
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册