Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
ccb9fdfe
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6013
Star
91
Fork
164
代码
文件
提交
分支
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看板
提交
ccb9fdfe
编写于
11月 21, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(dialogPage): 补充 dialogPage 方法示例及测试
上级
0afab4b3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
214 addition
and
96 deletion
+214
-96
pages/API/dialog-page/dialog-1.uvue
pages/API/dialog-page/dialog-1.uvue
+59
-7
pages/API/dialog-page/dialog-page.test.js
pages/API/dialog-page/dialog-page.test.js
+68
-53
pages/API/dialog-page/dialog-page.uvue
pages/API/dialog-page/dialog-page.uvue
+87
-36
未找到文件。
pages/API/dialog-page/dialog-1.uvue
浏览文件 @
ccb9fdfe
<template>
<template>
<view id="dialog1" class="dialog-container">
<view id="dialog1" class="dialog-container">
<view class="dialog-content">
<view class="dialog-content">
<text>title: {{
title
}}</text>
<text>title: {{
title
}}</text>
<text class="mt-10">onBackPress return true</text>
<text class="mt-10">onBackPress return true</text>
<button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">go next page</button>
<button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">
<button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">openDialog2</button>
go next page
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">closeDialog</button>
</button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">closeThisDialog</button>
<button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">
openDialog2
</button>
<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>
<button class="mt-10" @click="checkGetParentPage">
check getParentPage
</button>
<button class="mt-10" @click="checkGetElementById">
check getElementById
</button>
<button class="mt-10" @click="toggleBackgroundColor">
toggleBackgroundColor
</button>
<button class="mt-10" id="dialog1-back" @click="back">back</button>
<button class="mt-10" id="dialog1-back" @click="back">back</button>
<input class="uni-common-mt" style="border-width: 1px;border-style: solid;" :focus="true" value="DialogPage中焦点测试"/>
<input class="uni-common-mt" style="border-width: 1px; border-style: solid" :focus="true"
value="DialogPage中焦点测试" />
</view>
</view>
</view>
</view>
</template>
</template>
...
@@ -23,6 +41,7 @@
...
@@ -23,6 +41,7 @@
data() {
data() {
return {
return {
title: 'dialog 1',
title: 'dialog 1',
backgroundColorContent: 'transparent'
}
}
},
},
onLoad(options : OnLoadOptions) {
onLoad(options : OnLoadOptions) {
...
@@ -137,6 +156,39 @@
...
@@ -137,6 +156,39 @@
}
}
})
})
},
},
checkGetParentPage() : boolean {
const parentPage = this.$page.getParentPage()
console.log('checkGetParentPage', parentPage)
const res = parentPage != null
uni.showToast(res ? {
title: 'check success'
} : {
title: 'check fail',
icon: 'error'
})
return res
},
checkGetElementById() : boolean {
const page = this.$page
const element = page.getElementById('dialog1-go-next-page')
let res = element != null
// #ifndef APP-ANDROID
if (res) {
const elPage = element!.getPage()
console.log('elPage', elPage)
res = elPage === page
}
// #endif
console.log('check getElementById', res)
uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
return res
},
toggleBackgroundColor() {
this.backgroundColorContent = this.backgroundColorContent == 'transparent' ? 'rgb(0, 122, 255)' : 'transparent'
this.$page.setPageStyle({
backgroundColorContent: this.backgroundColorContent
})
},
back() {
back() {
uni.navigateBack()
uni.navigateBack()
}
}
...
@@ -164,4 +216,4 @@
...
@@ -164,4 +216,4 @@
.mt-10 {
.mt-10 {
margin-top: 10px;
margin-top: 10px;
}
}
</style>
</style>
pages/API/dialog-page/dialog-page.test.js
浏览文件 @
ccb9fdfe
jest
.
setTimeout
(
20000
)
jest
.
setTimeout
(
20000
)
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
FIRST_PAGE_PATH
=
'
/pages/API/dialog-page/dialog-page
'
const
FIRST_PAGE_PATH
=
'
/pages/API/dialog-page/dialog-page
'
const
NEXT_PAGE_PATH
=
'
/pages/API/dialog-page/next-page
'
const
NEXT_PAGE_PATH
=
'
/pages/API/dialog-page/next-page
'
describe
(
'
dialog page
'
,
()
=>
{
describe
(
'
dialog page
'
,
()
=>
{
if
(
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
==
'
true
'
)
{
if
(
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
==
'
true
'
)
{
it
(
'
skip app-webview
'
,
()
=>
{
it
(
'
skip app-webview
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
expect
(
1
).
toBe
(
1
)
})
})
return
return
}
}
let
page
;
let
page
;
let
initLifeCycleNum
;
let
initLifeCycleNum
;
...
@@ -24,8 +24,8 @@ describe('dialog page', () => {
...
@@ -24,8 +24,8 @@ describe('dialog page', () => {
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
0
)
expect
(
lifecycleNum
).
toBe
(
0
)
});
});
it
(
'
open dialog1
'
,
async
()
=>
{
it
(
'
open dialog1
'
,
async
()
=>
{
await
page
.
callMethod
(
'
openDialog1
'
);
await
page
.
callMethod
(
'
openDialog1
'
);
// 无法通过获取 dom 元素来判断是否打开了 dialogPage
// 无法通过获取 dom 元素来判断是否打开了 dialogPage
...
@@ -48,6 +48,18 @@ describe('dialog page', () => {
...
@@ -48,6 +48,18 @@ describe('dialog page', () => {
expect
(
lifecycleNum
).
toBe
(
7
)
expect
(
lifecycleNum
).
toBe
(
7
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
});
});
it
(
'
check dialogPage methods
'
,
async
()
=>
{
expect
(
await
page
.
callMethod
(
'
dialogPageCheckGetDialogPages
'
)).
toBe
(
true
)
let
dialogPageStyle
=
await
page
.
callMethod
(
'
dialogPageGetPageStyle
'
)
expect
(
dialogPageStyle
.
backgroundColorContent
).
not
.
toBe
(
'
red
'
)
await
page
.
callMethod
(
'
dialogPageSetPageStyle
'
)
dialogPageStyle
=
await
page
.
callMethod
(
'
dialogPageGetPageStyle
'
)
expect
(
dialogPageStyle
.
backgroundColorContent
).
toBe
(
'
red
'
)
expect
(
await
page
.
callMethod
(
'
dialogPageCheckGetElementById
'
)).
toBe
(
true
)
expect
(
await
page
.
callMethod
(
'
dialogCheckGetAndroidView
'
)).
toBe
(
isAndroid
)
expect
(
await
page
.
callMethod
(
'
dialogCheckGetIOSView
'
)).
toBe
(
false
)
expect
(
await
page
.
callMethod
(
'
dialogCheckGetHTMLElement
'
)).
toBe
(
isWeb
)
})
it
(
'
closeDialogPage
'
,
async
()
=>
{
it
(
'
closeDialogPage
'
,
async
()
=>
{
await
page
.
callMethod
(
'
closeDialog
'
);
await
page
.
callMethod
(
'
closeDialog
'
);
...
@@ -281,51 +293,54 @@ describe('dialog page', () => {
...
@@ -281,51 +293,54 @@ describe('dialog page', () => {
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifecycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifecycleNum
).
toBe
(
2
)
expect
(
lifecycleNum
).
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
'
)
await
page
.
waitFor
(
2000
);
await
page
.
waitFor
(
2000
);
await
page
.
callMethod
(
'
jest_getTapPoint
'
)
await
page
.
callMethod
(
'
jest_getTapPoint
'
)
const
point_x
=
await
page
.
data
(
'
jest_click_x
'
);
const
point_x
=
await
page
.
data
(
'
jest_click_x
'
);
const
point_y
=
await
page
.
data
(
'
jest_click_y
'
);
const
point_y
=
await
page
.
data
(
'
jest_click_y
'
);
if
(
isAndroid
){
if
(
isAndroid
)
{
await
program
.
adbCommand
(
"
input tap
"
+
"
"
+
point_x
+
"
"
+
point_y
)
await
program
.
adbCommand
(
"
input tap
"
+
"
"
+
point_x
+
"
"
+
point_y
)
console
.
log
(
"
input tap
"
+
"
"
+
point_x
+
"
"
+
point_y
);
console
.
log
(
"
input tap
"
+
"
"
+
point_x
+
"
"
+
point_y
);
}
else
{
}
else
{
await
program
.
tap
({
x
:
point_x
,
y
:
point_y
})
await
program
.
tap
({
}
x
:
point_x
,
y
:
point_y
await
page
.
waitFor
(
1000
);
})
const
image
=
await
program
.
screenshot
({
}
deviceShot
:
true
,
area
:
{
await
page
.
waitFor
(
1000
);
x
:
0
,
const
image
=
await
program
.
screenshot
({
y
:
200
,
deviceShot
:
true
,
}
area
:
{
})
x
:
0
,
expect
(
image
).
toSaveImageSnapshot
()
y
:
200
,
await
page
.
waitFor
(
2000
);
}
await
page
.
callMethod
(
'
jest_CloseDialog1
'
)
})
})
expect
(
image
).
toSaveImageSnapshot
()
await
page
.
waitFor
(
2000
);
it
(
'
dialogPage hideStatusBar hideBottomNavigationIndicator
'
,
async
()
=>
{
await
page
.
callMethod
(
'
jest_CloseDialog1
'
)
if
(
isAndroid
)
{
})
await
page
.
callMethod
(
'
openDialog2ForTest
'
);
await
page
.
waitFor
(
1000
);
it
(
'
dialogPage hideStatusBar hideBottomNavigationIndicator
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setPageStyleForTest
'
,
{
if
(
isAndroid
)
{
hideStatusBar
:
true
,
await
page
.
callMethod
(
'
openDialog2ForTest
'
);
hideBottomNavigationIndicator
:
true
await
page
.
waitFor
(
1000
);
});
await
page
.
callMethod
(
'
setPageStyleForTest
'
,
{
await
page
.
waitFor
(
2000
);
hideStatusBar
:
true
,
const
image
=
await
program
.
screenshot
({
hideBottomNavigationIndicator
:
true
deviceShot
:
true
});
});
await
page
.
waitFor
(
2000
);
expect
(
image
).
toSaveImageSnapshot
();
const
image
=
await
program
.
screenshot
({
await
page
.
waitFor
(
2000
);
deviceShot
:
true
await
page
.
callMethod
(
'
closeDialog2ForTest
'
);
});
}
expect
(
image
).
toSaveImageSnapshot
();
});
await
page
.
waitFor
(
2000
);
await
page
.
callMethod
(
'
closeDialog2ForTest
'
);
}
});
afterAll
(
async
()
=>
{
afterAll
(
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifeCycleNum
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifeCycleNum
)
...
...
pages/API/dialog-page/dialog-page.uvue
浏览文件 @
ccb9fdfe
...
@@ -15,12 +15,12 @@
...
@@ -15,12 +15,12 @@
setLifeCycleNum
setLifeCycleNum
} from '@/store/index.uts'
} from '@/store/index.uts'
export default {
export default {
data() {
data() {
return {
return {
jest_click_x: -1,
jest_click_x: -1,
jest_click_y: -1
jest_click_y: -1
}
}
},
},
onLoad() {
onLoad() {
console.log('dialogPage parent onLoad')
console.log('dialogPage parent onLoad')
...
@@ -176,36 +176,87 @@
...
@@ -176,36 +176,87 @@
},
},
getLifeCycleNum(): number {
getLifeCycleNum(): number {
return state.lifeCycleNum
return state.lifeCycleNum
},
},
jest_OpenDialog1(){
jest_OpenDialog1() {
uni.openDialogPage({
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-1?name=dialog1'
url: '/pages/API/dialog-page/dialog-1?name=dialog1'
})
})
},
},
jest_CloseDialog1(){
jest_CloseDialog1() {
uni.closeDialogPage({})
uni.closeDialogPage({})
},
},
jest_getTapPoint(){
jest_getTapPoint() {
const systemInfo = uni.getSystemInfoSync()
const systemInfo = uni.getSystemInfoSync()
let ratio = 1
let ratio = 1
if (systemInfo.platform == 'android'){
if (systemInfo.platform == 'android') {
ratio = systemInfo.devicePixelRatio
ratio = systemInfo.devicePixelRatio
}
}
this.jest_click_x = systemInfo.screenWidth / 2 * ratio
this.jest_click_x = systemInfo.screenWidth / 2 * ratio
this.jest_click_y = systemInfo.statusBarHeight * ratio + 10
this.jest_click_y = systemInfo.statusBarHeight * ratio + 10
},
},
openDialog2ForTest() {
openDialog2ForTest() {
uni.openDialogPage({
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-2'
url: '/pages/API/dialog-page/dialog-2'
});
});
},
},
closeDialog2ForTest() {
closeDialog2ForTest() {
uni.closeDialogPage({});
uni.closeDialogPage({});
},
},
setPageStyleForTest(style : UTSJSONObject) {
setPageStyleForTest(style: UTSJSONObject) {
const pages = this.$page.getDialogPages();
const pages = this.$page.getDialogPages();
if (pages.length > 0) pages[pages.length - 1].setPageStyle(style);
if (pages.length > 0) pages[pages.length - 1].setPageStyle(style);
}
},
getDialogPage(): UniPage | null {
const dialogPages = this.$page.getDialogPages()
return dialogPages.length > 0 ? dialogPages[0] : null
},
dialogPageCheckGetDialogPages(): boolean {
const dialogPage = this.getDialogPage() !
const dialogPages = dialogPage.getDialogPages()
const res = dialogPages.length == 0
return res
},
dialogPageGetPageStyle(): UTSJSONObject {
const dialogPage = this.getDialogPage() !
return dialogPage.getPageStyle()
},
dialogPageSetPageStyle() {
const dialogPage = this.getDialogPage() !
dialogPage.setPageStyle({
backgroundColorContent: 'red'
})
},
dialogPageCheckGetElementById(): boolean {
const dialogPage = this.getDialogPage() !
const element = dialogPage.getElementById('dialog1-go-next-page')
let res = element != null
// #ifndef APP-ANDROID
if (res) {
const elPage = element!.getPage()
console.log('elPage', elPage)
res = elPage === dialogPage
}
// #endif
return res
},
dialogCheckGetAndroidView(): boolean {
const dialogPage = this.getDialogPage() !
const androidView = dialogPage.getAndroidView()
const res = androidView != null
return res
},
dialogCheckGetIOSView(): boolean {
const dialogPage = this.getDialogPage() !
const IOSView = dialogPage.getIOSView()
const res = IOSView != null
return res
},
dialogCheckGetHTMLElement(): boolean {
const dialogPage = this.getDialogPage() !
const HTMLView = dialogPage.getHTMLElement()
const res = HTMLView != null
return res
},
}
}
}
}
</script>
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录