提交 c7636102 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

增加 touch preventDefault、stopPropagation 测试例

上级 6e3ae8b1
......@@ -499,6 +499,12 @@
"navigationBarTitleText": "Touch Events bubbles"
}
},
{
"path": "pages/component/global-events/touch-events-case",
"style": {
"navigationBarTitleText": "Touch Events case"
}
},
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/nested-scroll-header/nested-scroll-header",
......
const PAGE_PATH = '/pages/component/global-events/touch-events-case'
describe('touch-events-test', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
if (
isWeb ||
isMP
) {
it('other platform', () => {
expect(1).toBe(1)
})
return
}
if (process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('跳过横屏模式', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500);
})
it('touch-event-preventDefault', async () => {
let x = 25
let y = 150
// 滑动事件
await program.swipe({
startPoint: {x: x, y: y},
endPoint: {x: x+200,y: y},
duration: 300
})
await page.waitFor(1500);
const ret = await page.callMethod('isPassTest1')
expect(ret).toBe(true)
})
it('touch-event-stopPropagation', async () => {
const ret = await page.callMethod('isPassTest2')
expect(ret).toBe(true)
})
})
<template>
<view>
<swiper ref="header" indicator-dots="true" circular="true" @change="swiperChange" @touchstart="swiperTouchStart">
<swiper-item v-for="i in 3" :item-id="i" @touchstart="swiperItemTouchStart">
<view class="header-tiem" @touchstart="viewTouchStart">
<text @touchstart="textTouchStart">{{ i }}</text>
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
swiperChangeEvent: false,
viewTouchEvent: false,
swiperItemTouchEvent: false,
swiperTouchEvent: false
}
},
methods: {
swiperChange(e: UniSwiperChangeEvent) {
console.log("swiperChange", e.detail.current)
this.swiperChangeEvent = true
},
viewTouchStart(e: UniTouchEvent) {
console.log("viewTouchStart")
this.viewTouchEvent = true
e.preventDefault()
},
swiperItemTouchStart(e: UniTouchEvent) {
console.log("swiperItemTouchStart")
this.swiperItemTouchEvent = true
e.stopPropagation()
},
swiperTouchStart(e: UniTouchEvent) {
console.log("swiperTouchStart")
this.swiperTouchEvent = true
},
isPassTest1() {
console.log("swiperChangeEvent:", this.swiperChangeEvent)
return this.swiperChangeEvent == false
},
isPassTest2() {
console.log("viewTouchEvent:", this.viewTouchEvent)
console.log("swiperItemTouchEvent:", this.swiperItemTouchEvent)
console.log("swiperTouchEvent:", this.swiperTouchEvent)
return this.viewTouchEvent == true && this.swiperItemTouchEvent == true && this.swiperTouchEvent == false
}
}
}
</script>
<style>
.header-tiem {
height: 300px;
background-color: #89ff8d;
align-items: center;
justify-content: center;
}
</style>
......@@ -7,6 +7,7 @@ const sortTestFilePaths = [
"pages/component/scroll-view/scroll-view-refresher.test.js",
"pages/component/global-events/touch-events.test.js",
"pages/component/global-events/touch-events-bubbles.test.js",
"pages/component/global-events/touch-events-case.test.js",
"pages/component/swiper/swiper2.test.js",
"pages/component/slider/slider-maxValue.test.js",
"pages/CSS/overflow/overflow-visible-event.test.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册