Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
062c0505
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
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看板
提交
062c0505
编写于
8月 26, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(API): dialogPage 补充 eventBus 示例及测试
上级
a60b721c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
122 addition
and
83 deletion
+122
-83
pages/API/dialog-page/dialog-1.uvue
pages/API/dialog-page/dialog-1.uvue
+10
-1
pages/API/dialog-page/dialog-page.test.js
pages/API/dialog-page/dialog-page.test.js
+27
-17
pages/API/dialog-page/dialog-page.uvue
pages/API/dialog-page/dialog-page.uvue
+85
-65
未找到文件。
pages/API/dialog-page/dialog-1.uvue
浏览文件 @
062c0505
...
...
@@ -54,7 +54,15 @@
) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
}
this.$dialogPage.$emit('fn1', {from: 'dialog1'})
this.$dialogPage.$emit('fn2', null)
this.$dialogPage.$off('fn2')
this.$dialogPage.$emit('fn1', {from: 'dialog1'})
this.$dialogPage.$emit('fn2', null)
this.$dialogPage.$emit('fnOnce', null)
this.$dialogPage.$emit('fnOnce', null)
},
onHide() {
console.log('dialog 1 onHide')
...
...
@@ -67,6 +75,7 @@
setLifeCycleNum(state.lifeCycleNum - 5)
},
onBackPress(options : OnBackPressOptions) : boolean | null {
console.log('dialogPage1 onBackPress', options)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
return true
...
...
pages/API/dialog-page/dialog-page.test.js
浏览文件 @
062c0505
...
...
@@ -35,9 +35,10 @@ describe('dialog page', () => {
expect
(
image
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
// 不应触发父页面的生命周期,应该触发:
// 1. openDialogPage sucess & complete callback
// 1. openDialogPage suc
c
ess & complete callback
// 2. dialog page 生命周期
expect
(
lifecycleNum
).
toBe
(
7
)
expect
(
lifecycleNum
).
toBe
(
13
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
});
it
(
'
closeDialogPage
'
,
async
()
=>
{
...
...
@@ -53,13 +54,15 @@ describe('dialog page', () => {
// closeDialogPage success & complete callback 应被触发
// dialogPage onUnload 应被触发
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
4
)
expect
(
lifecycleNum
).
toBe
(
-
3
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
openDialog with wrong path
'
,
async
()
=>
{
await
page
.
callMethod
(
'
openDialog1WrongPath
'
)
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
1
)
expect
(
lifecycleNum
).
toBe
(
-
3
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
navigateTo nextPage & open Dialog
'
,
async
()
=>
{
...
...
@@ -83,7 +86,8 @@ describe('dialog page', () => {
});
expect
(
image
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
-
3
)
expect
(
lifecycleNum
).
toBe
(
-
4
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
dialog1 navigateBack
'
,
async
()
=>
{
...
...
@@ -101,7 +105,8 @@ describe('dialog page', () => {
expect
(
image
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
// onBackPress 生命周期应该被触发
expect
(
lifecycleNum
).
toBe
(
-
2
)
expect
(
lifecycleNum
).
toBe
(
1
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
open dialog2
'
,
async
()
=>
{
...
...
@@ -112,7 +117,8 @@ describe('dialog page', () => {
}
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
// 应触发前一个 dialogPage 的 onHide
expect
(
lifecycleNum
).
toBe
(
2
)
expect
(
lifecycleNum
).
toBe
(
4
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
closeDialogPage
'
,
async
()
=>
{
...
...
@@ -120,7 +126,7 @@ describe('dialog page', () => {
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
// 应触发 success & complete 回调
// 应触发 dialogPage 的 unload,下层的 dialogPage 会先 show 再 unload
expect
(
lifecycleNum
).
toBe
(
-
5
)
expect
(
lifecycleNum
).
toBe
(
-
7
)
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
...
...
@@ -130,6 +136,7 @@ describe('dialog page', () => {
}
});
expect
(
image
).
toSaveImageSnapshot
();
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
open multiple dialog page
'
,
async
()
=>
{
...
...
@@ -147,7 +154,7 @@ describe('dialog page', () => {
});
expect
(
image1
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
-
1
)
expect
(
lifecycleNum
).
toBe
(
4
)
await
page
.
callMethod
(
'
openDialog2
'
)
await
page
.
waitFor
(
1000
)
...
...
@@ -163,7 +170,8 @@ describe('dialog page', () => {
});
expect
(
image2
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
3
)
expect
(
lifecycleNum
).
toBe
(
8
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
openDialogPage to home page
'
,
async
()
=>
{
...
...
@@ -173,7 +181,8 @@ describe('dialog page', () => {
await
page
.
waitFor
(
2000
)
}
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
7
)
expect
(
lifecycleNum
).
toBe
(
4
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
dialog2 navigateBack
'
,
async
()
=>
{
...
...
@@ -191,7 +200,8 @@ describe('dialog page', () => {
expect
(
image
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
// onBackPress 生命周期应该被触发
expect
(
lifecycleNum
).
toBe
(
9
)
expect
(
lifecycleNum
).
toBe
(
2
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
close specified dialogPage
'
,
async
()
=>
{
...
...
@@ -209,7 +219,7 @@ describe('dialog page', () => {
});
expect
(
image1
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
13
)
expect
(
lifecycleNum
).
toBe
(
4
)
await
page
.
callMethod
(
'
openDialog1
'
)
await
page
.
waitFor
(
1000
)
...
...
@@ -225,7 +235,7 @@ describe('dialog page', () => {
});
expect
(
image2
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
1
9
)
expect
(
lifecycleNum
).
toBe
(
1
6
)
await
page
.
callMethod
(
'
closeSpecifiedDialog
'
,
0
)
const
image3
=
await
program
.
screenshot
({
...
...
@@ -237,7 +247,7 @@ describe('dialog page', () => {
});
expect
(
image3
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
1
6
)
expect
(
lifecycleNum
).
toBe
(
1
3
)
await
page
.
callMethod
(
'
closeSpecifiedDialog
'
,
1
)
const
image4
=
await
program
.
screenshot
({
...
...
@@ -249,7 +259,7 @@ describe('dialog page', () => {
});
expect
(
image4
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
1
4
)
expect
(
lifecycleNum
).
toBe
(
1
1
)
await
page
.
callMethod
(
'
closeSpecifiedDialog
'
,
0
)
const
image5
=
await
program
.
screenshot
({
...
...
@@ -261,7 +271,7 @@ describe('dialog page', () => {
});
expect
(
image5
).
toSaveImageSnapshot
();
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
11
)
expect
(
lifecycleNum
).
toBe
(
8
)
})
...
...
pages/API/dialog-page/dialog-page.uvue
浏览文件 @
062c0505
<template>
<view class=
'uni-padding-wrap'
>
<view class=
"uni-padding-wrap"
>
<button class="uni-common-mt" id="go-next-page" @click="goNextPage">go next page</button>
<button class="uni-common-mt" id="open-dialog1" @click="openDialog1">open dialog 1</button>
<button class="uni-common-mt" id="open-dialog1-wrong-path" @click="openDialog1WrongPath">open dialog page 1 with
wrong path</button>
<button class="uni-common-mt" id="go-next-page-open-dialog1" @click="goNextPageOpenDialog1">go next page & open
dialog1</button>
<button class="uni-common-mt" id="go-next-page-open-dialog1" @click="goNextPageOpenDialog1">go next page & open
dialog1</button>
</view>
</template>
...
...
@@ -40,7 +40,7 @@
})
},
openDialog1() {
uni.openDialogPage({
const dialogPage =
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-1?name=dialog1',
success(res) {
console.log('openDialogPage1 success', res)
...
...
@@ -56,28 +56,48 @@
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})!
const fn1 = (options: any | null) => {
console.log('dialogPage1 be triggered fn1', options)
setLifeCycleNum(state.lifeCycleNum + 1)
}
const fn11 = (options: any | null) => {
console.log('dialogPage1 be triggered fn11', options)
setLifeCycleNum(state.lifeCycleNum + 1)
}
const fn2 = (options: any | null) => {
console.log('dialogPage1 be triggered fn2', options)
setLifeCycleNum(state.lifeCycleNum + 1)
}
const fnOnce = (options: any | null) => {
console.log('dialogPage1 be triggered fnOnce', options)
setLifeCycleNum(state.lifeCycleNum + 1)
}
dialogPage.$on('fn1', fn1)
dialogPage.$on('fn1', fn11)
dialogPage.$on('fn2', fn2)
dialogPage.$once('fnOnce', fnOnce)
},
openDialog2() {
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-2',
disableEscBack: true,
success(res) {
console.log('openDialog2 success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('openDialog2 fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('openDialog2 complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
openDialog2() {
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-2',
disableEscBack: true,
success(res) {
console.log('openDialog2 success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('openDialog2 fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('openDialog2 complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
openDialog1WrongPath() {
uni.openDialogPage({
...
...
@@ -124,46 +144,46 @@
}, 1000)
}
})
},
closeDialog() {
uni.closeDialogPage({
success(res) {
console.log('closeDialog success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('closeDialog fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('closeDialog complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
closeSpecifiedDialog(index: number) {
const dialogPages = this.$getDialogPages()
uni.closeDialogPage({
dialogPage: dialogPages[index],
success(res) {
console.log('closeSomeOneDialog success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('closeSomeOneDialog fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('closeSomeOneDialog complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
closeDialog() {
uni.closeDialogPage({
success(res) {
console.log('closeDialog success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('closeDialog fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('closeDialog complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
closeSpecifiedDialog(index: number) {
const dialogPages = this.$getDialogPages()
uni.closeDialogPage({
dialogPage: dialogPages[index],
success(res) {
console.log('closeSomeOneDialog success', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(err) {
console.log('closeSomeOneDialog fail', err)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 4)
},
complete(res) {
console.log('closeSomeOneDialog complete', res)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setLifeCycleNum(value: number) {
setLifeCycleNum(value)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录