提交 f869f612 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(dialogPage): 补充 triggerParentHide 参数示例及测试

上级 33c5b17c
...@@ -1507,6 +1507,14 @@ ...@@ -1507,6 +1507,14 @@
"navigationBarTitleText": "dialogPage3" "navigationBarTitleText": "dialogPage3"
} }
}, },
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/dialog-page/dialog-4",
"style": {
"navigationBarTitleText": "dialogPage4"
}
},
// #endif // #endif
// #ifdef APP-ANDROID || APP-IOS || MP-WEIXIN // #ifdef APP-ANDROID || APP-IOS || MP-WEIXIN
{ {
......
<template>
<view class="dialog-container">
<view class="dialog-content">
<text>title: {{ title }}</text>
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">
closeDialog
</button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">
closeThisDialog
</button>
</view>
</view>
</template>
<script>
import {
state,
setLifeCycleNum
} from '@/store/index.uts'
export default {
data() {
return {
title: 'dialog 4'
}
},
onShow() {
console.log('dialog 4 onShow')
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
onUnload() {
console.log('dialog 4 onUnload')
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 5)
},
methods: {
closeDialog() {
uni.closeDialogPage({
success(res) {
console.log('closeDialog success', res)
},
fail(err) {
console.log('closeDialog fail', err)
},
complete(res) {
console.log('closeDialog complete', res)
}
})
},
closeThisDialog() {
uni.closeDialogPage({
dialogPage: this.$page,
success(res) {
console.log('closeThisDialog success', res)
},
fail(err) {
console.log('closeThisDialog fail', err)
},
complete(res) {
console.log('closeThisDialog complete', res)
}
})
}
}
}
</script>
<style>
.dialog-container {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
}
.dialog-content {
width: 80%;
padding: 10px;
background-color: #fff;
border-radius: 6px;
}
.mt-10 {
margin-top: 10px;
}
</style>
jest.setTimeout(20000) jest.setTimeout(50000)
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isWeb = platformInfo.startsWith('web') const isWeb = platformInfo.startsWith('web')
...@@ -202,6 +202,7 @@ describe('dialog page', () => { ...@@ -202,6 +202,7 @@ describe('dialog page', () => {
}) })
it('openDialogPage to home page', async () => { it('openDialogPage to home page', async () => {
// 本测试例中是在 FIRST_PAGE_PATH 中打开
await page.callMethod('openDialogPage1ToHomePage') await page.callMethod('openDialogPage1ToHomePage')
await page.waitFor(1000) await page.waitFor(1000)
if (isWeb) { if (isWeb) {
...@@ -215,7 +216,6 @@ describe('dialog page', () => { ...@@ -215,7 +216,6 @@ describe('dialog page', () => {
it('dialog2 navigateBack', async () => { it('dialog2 navigateBack', async () => {
await program.navigateBack() await program.navigateBack()
page = await program.currentPage() page = await program.currentPage()
// dialogPage onBackPress 返回 true, 应可以拦截 navigateBack
expect(page.path).toBe(FIRST_PAGE_PATH.substring(1)) expect(page.path).toBe(FIRST_PAGE_PATH.substring(1))
const image = await program.screenshot({ const image = await program.screenshot({
deviceShot: true, deviceShot: true,
...@@ -226,7 +226,7 @@ describe('dialog page', () => { ...@@ -226,7 +226,7 @@ describe('dialog page', () => {
}); });
expect(image).toSaveImageSnapshot(); expect(image).toSaveImageSnapshot();
lifecycleNum = await page.callMethod('getLifeCycleNum') lifecycleNum = await page.callMethod('getLifeCycleNum')
// onBackPress 生命周期应该被触发 // dialogPage2 onBackPress +1 dialogPage1 show +1 dialogPage unload -5*2 firstPage show +10
expect(lifecycleNum).toBe(2) expect(lifecycleNum).toBe(2)
await page.callMethod('setLifeCycleNum', 0) await page.callMethod('setLifeCycleNum', 0)
}) })
...@@ -299,8 +299,109 @@ describe('dialog page', () => { ...@@ -299,8 +299,109 @@ describe('dialog page', () => {
expect(image5).toSaveImageSnapshot(); expect(image5).toSaveImageSnapshot();
lifecycleNum = await page.callMethod('getLifeCycleNum') lifecycleNum = await page.callMethod('getLifeCycleNum')
expect(lifecycleNum).toBe(2) expect(lifecycleNum).toBe(2)
await page.callMethod('setLifeCycleNum', 0)
}) })
it('check triggerParentHide', async () => {
// no triggerParentHide should not trigger parent hide
await page.callMethod('openDialog4')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// dialog4 show +1
expect(await page.callMethod('getLifeCycleNum')).toBe(1)
await page.callMethod('closeDialog')
await page.waitFor(200)
// dialog4 unload -5 closeDialog callback +2
expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
// triggerParentHide should trigger parent hide
await page.callMethod('openDialogWithTriggerParentHide')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// openDialog callback +2 dialog4 show +1 parent hide -10
expect(await page.callMethod('getLifeCycleNum')).toBe(-9)
await page.callMethod('closeDialog')
await page.waitFor(200)
// dialog4 unload -5 parent show +10 closeDialog callback +2
expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
// triggerParentHide should trigger parent hide
await page.callMethod('openDialogWithTriggerParentHide')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// openDialog callback +2 dialog4 show +1 parent hide -10
expect(await page.callMethod('getLifeCycleNum')).toBe(-9)
// second triggerParentHide should not trigger parent hide
await page.callMethod('openDialogWithTriggerParentHide')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// openDialog callback +2 dialog4 show +1
expect(await page.callMethod('getLifeCycleNum')).toBe(-6)
await page.callMethod('closeSpecifiedDialog', 1)
await page.waitFor(200)
// close not last triggerParentHide should not trigger parent show
// close callback +2 dialog4 unload -5 dialog4 show +1
expect(await page.callMethod('getLifeCycleNum')).toBe(-8)
await page.callMethod('closeSpecifiedDialog', 0)
await page.waitFor(200)
// close last triggerParentHide should trigger parent show
// close callback +2 dialog4 unload -5 parent show +10
expect(await page.callMethod('getLifeCycleNum')).toBe(-1)
// no triggerParentHide should not trigger parent hide
await page.callMethod('openDialog4')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// dialog4 show +1
expect(await page.callMethod('getLifeCycleNum')).toBe(0)
// triggerParentHide should trigger parent hide
await page.callMethod('openDialogWithTriggerParentHide')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// openDialog callback +2 dialog4 show +1 parent hide -10
expect(await page.callMethod('getLifeCycleNum')).toBe(-7)
// second triggerParentHide should not trigger parent hide
await page.callMethod('openDialogWithTriggerParentHide')
await page.waitFor(1000)
if (isWeb) {
await page.waitFor(2000)
}
// openDialog callback +2 dialog4 show +1
expect(await page.callMethod('getLifeCycleNum')).toBe(-4)
// close middle triggerParentHide dialogPage
await page.callMethod('closeSpecifiedDialog', 1)
await page.waitFor(200)
// close callback +2 dialog4 unload -5
expect(await page.callMethod('getLifeCycleNum')).toBe(-7)
// close last triggerParentHide dialogPage shoud trigger parent show
await page.callMethod('closeSpecifiedDialog', 1)
await page.waitFor(200)
// close callback +2 dialog4 unload -5 dialog4 show +1 parent show +10
expect(await page.callMethod('getLifeCycleNum')).toBe(1)
await page.callMethod('closeDialog')
await page.waitFor(200)
// close callback +2 dialog4 unload -5
expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
})
it('input-hold-keyboard in dialog', async () => { it('input-hold-keyboard in dialog', async () => {
await page.callMethod('jest_OpenDialog1') await page.callMethod('jest_OpenDialog1')
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<button class="uni-common-mt" id="open-dialog1" @click="openDialog3"> <button class="uni-common-mt" id="open-dialog1" @click="openDialog3">
open dialog 3 test page style open dialog 3 test page style
</button> </button>
<button class="uni-common-mt" id="open-dialog4" @click="openDialogWithTriggerParentHide">
openDialog with triggerParentHide
</button>
<text class="uni-common-mt choose-open-animation-type-title">choose open dialogPage animationType</text> <text class="uni-common-mt choose-open-animation-type-title">choose open dialogPage animationType</text>
<radio-group class="choose-open-animation-type-radio-group" @change="handleOpenAnimationType"> <radio-group class="choose-open-animation-type-radio-group" @change="handleOpenAnimationType">
<radio class="ml-10 uni-common-mt" v-for="item in openAnimationTypeList" :key="item" :value="item" <radio class="ml-10 uni-common-mt" v-for="item in openAnimationTypeList" :key="item" :value="item"
...@@ -212,6 +215,33 @@ ...@@ -212,6 +215,33 @@
} }
}) })
}, },
// 自动化测试
openDialog4() {
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-4',
})
},
openDialogWithTriggerParentHide() {
uni.openDialogPage({
url: `/pages/API/dialog-page/dialog-4?tag=${Date.now()}`,
triggerParentHide: true,
success(res) {
console.log('openDialogWithTriggerParentHide success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('openDialogWithTriggerParentHide fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('openDialogWithTriggerParentHide complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setLifeCycleNum(value : number) { setLifeCycleNum(value : number) {
setLifeCycleNum(value) setLifeCycleNum(value)
}, },
...@@ -329,4 +359,4 @@ ...@@ -329,4 +359,4 @@
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
} }
</style> </style>style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册