Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
8ddf83f2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6006
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看板
提交
8ddf83f2
编写于
8月 02, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新showToast示例
上级
a50bf236
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
156 addition
and
217 deletion
+156
-217
pages/API/show-toast/show-toast.test.js
pages/API/show-toast/show-toast.test.js
+35
-153
pages/API/show-toast/show-toast.uvue
pages/API/show-toast/show-toast.uvue
+121
-64
未找到文件。
pages/API/show-toast/show-toast.test.js
浏览文件 @
8ddf83f2
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe
(
'
API-toast
'
,
()
=>
{
let
page
;
const
isApp
=
process
.
env
.
UNI_OS_NAME
===
"
android
"
||
process
.
env
.
UNI_OS_NAME
===
"
ios
"
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/API/show-toast/show-toast
'
)
await
page
.
waitFor
(
600
);
await
page
.
waitFor
(
"
view
"
);
});
it
(
"
onload-toast-test
"
,
async
()
=>
{
async
function
toScreenshot
(
imgName
)
{
if
(
isApp
)
{
await
page
.
waitFor
(
500
);
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
...
...
@@ -31,163 +23,53 @@ describe('API-toast', () => {
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
();
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
()
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
}
})
await
page
.
waitFor
(
500
);
}
it
(
"
btn-toast-default-1
"
,
async
()
=>
{
const
btnToastDefaultButton
=
await
page
.
$
(
'
#btn-toast-default
'
)
await
btnToastDefaultButton
.
tap
()
await
page
.
waitFor
(
200
)
if
(
isApp
)
{
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
200
,
height
:
windowHeight
-
200
,
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
();
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
()
}
it
(
"
onload-toast-test
"
,
async
()
=>
{
await
toScreenshot
(
'
toast-onload
'
)
})
it
(
"
btn-toast-duration-1
"
,
async
()
=>
{
const
btnToastDurationButton
=
await
page
.
$
(
'
#btn-toast-duration
'
)
await
btnToastDurationButton
.
tap
()
await
page
.
waitFor
(
2000
)
if
(
isApp
)
{
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
200
,
height
:
windowHeight
-
200
,
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
();
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
()
it
(
"
icon-toast-test
"
,
async
()
=>
{
const
icons
=
await
page
.
$$
(
'
.radio-icon
'
)
for
(
let
i
=
0
;
i
<
icons
.
length
;
i
++
)
{
await
icons
[
i
].
tap
()
const
iconText
=
await
icons
[
i
].
text
()
await
page
.
callMethod
(
'
toast1Tap
'
)
await
page
.
waitFor
(
100
);
await
toScreenshot
(
`
${
iconText
}
`
)
}
})
it
(
"
btn-toast-errorIcon-1
"
,
async
()
=>
{
const
btnToastErrorIconButton
=
await
page
.
$
(
'
#btn-toast-errorIcon
'
)
await
btnToastErrorIconButton
.
tap
()
await
page
.
waitFor
(
200
)
if
(
isApp
)
{
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
200
,
height
:
windowHeight
-
200
,
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
();
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
()
}
it
(
"
image-toast-test
"
,
async
()
=>
{
await
page
.
setData
({
imageSelect
:
true
})
await
page
.
waitFor
(
300
);
await
page
.
callMethod
(
'
toast1Tap
'
)
await
page
.
waitFor
(
300
);
await
toScreenshot
(
'
toast-image
'
)
})
it
(
"
btn-toast-loading-1
"
,
async
()
=>
{
const
btnToastLoadingButton
=
await
page
.
$
(
'
#btn-toast-loading
'
)
await
btnToastLoadingButton
.
tap
()
await
page
.
waitFor
(
200
)
const
btnToastHideButton
=
await
page
.
$
(
'
#btn-toast-hide
'
)
await
btnToastHideButton
.
tap
()
await
page
.
waitFor
(
1000
)
if
(
isApp
)
{
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
200
,
height
:
windowHeight
-
200
,
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
();
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
()
}
it
(
"
duration-toast-test
"
,
async
()
=>
{
await
page
.
setData
({
intervalSelect
:
4000
})
await
page
.
callMethod
(
'
toast1Tap
'
)
await
page
.
waitFor
(
2000
);
await
toScreenshot
(
'
toast-duration-2000
'
)
await
page
.
waitFor
(
1000
);
await
page
.
callMethod
(
'
hideToast
'
)
await
page
.
waitFor
(
300
);
await
toScreenshot
(
'
toast-duration-end
'
)
})
// it("btn-toast-postion-bottom-1", async () => {
// const btnToastButton = await page.$('#btn-toast-postion-bottom')
// await btnToastButton.tap()
// await page.waitFor(200)
// if (isApp) {
// const windowHeight = uni.getWindowInfo().windowHeight;
// const windowWidth = uni.getWindowInfo().windowWidth;
// const image = await program.screenshot({
// deviceShot: true,
// area: {
// x: 0,
// y: 200,
// height: windowHeight,
// width:windowWidth
// },
// });
// expect(image).toSaveImageSnapshot();
// }else{
// const image = await program.screenshot({
// deviceShot: true,
// fullPage: true
// });
// expect(image).toSaveImageSnapshot()
// }
// })
});
pages/API/show-toast/show-toast.uvue
浏览文件 @
8ddf83f2
<template>
<view>
<!-- #ifdef APP -->
<scroll-view direction="vertical" style="flex:1">
<!-- #endif -->
<page-head :title="title"></page-head>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap">
<text class="uni-title-text uni-common-mb">设置icon</text>
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChangeIcon">
<radio class="uni-list-cell uni-list-cell-pd radio-icon" v-for="(icon, index) in icon_enum" :key="icon.value"
:class="index < icon_enum.length - 1 ? 'uni-list-cell-line' : ''" :value="icon.value"
:checked="index === icon_current">{{icon.name}}</radio>
</radio-group>
</view>
<view class="uni-list-cell uni-list-cell-padding">
<view class="uni-list-cell-db">是否显示自定义图标</view>
<switch :checked="imageSelect" @change="change_image_boolean" />
</view>
<view class="uni-list-cell uni-list-cell-padding">
<view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
<switch :checked="maskSelect" @change="change_mask_boolean" />
</view>
<view class="uni-title uni-list-cell-padding">提示的延迟时间,默认:1500(单位毫秒)</view>
<view class="uni-list-cell-padding">
<slider @change="sliderChange" foreColor="#007AFF" :value="intervalSelect" :min="1500" :max="5000" :show-value="true" />
</view>
<view class="uni-btn-v">
<button class="uni-btn-v" type="default" @tap="toast1Tap" id="btn-toast-default" >点击弹出默认toast</button>
<button class="uni-btn-v" type="default" @tap="toastTapIconError" id="btn-toast-errorIcon">点击弹出设置icon的toast</button>
<button class="uni-btn-v" type="default" @tap="toast2Tap" id="btn-toast-duration">点击弹出设置duration的toast</button>
<button class="uni-btn-v" type="default" @tap="toast3Tap" id="btn-toast-loading">点击弹出显示loading的toast</button>
<!-- #ifndef MP-ALIPAY -->
<button class="uni-btn-v" type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
<!-- #endif -->
<!-- #ifdef APP -->
<button class="uni-btn-v" type="default" @tap="toast5Tap" id="btn-toast-postion-bottom">点击显示无图标的居底toast</button>
<!-- #endif -->
<button class="uni-btn-v" type="default" @tap="toast1Tap" id="btn-toast-default">点击弹出toast</button>
<button class="uni-btn-v" type="default" @tap="hideToast" id="btn-toast-hide">点击隐藏toast</button>
</view>
<!-- #ifdef APP -->
<view class="uni-padding-wrap uni-common-mt">
<text class="uni-title-text uni-common-mb"> 设置position,仅App生效 </text>
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChangePosition">
<radio class="uni-list-cell uni-list-cell-pd radio-position" v-for="(position, index) in position_enum" :key="position.value"
:class="index < position_enum.length - 1 ? 'uni-list-cell-line' : ''" :value="position.value"
:checked="index === position_current">{{position.name}}</radio>
</radio-group>
</view>
<button class="uni-btn uni-btn-v uni-common-mb" type="default" @tap="toast2Tap">点击弹出设置position的toast</button>
<!-- #endif -->
<text>{{exeRet}}</text>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
<script lang="uts">
type IconItemType = {
value : "success" | "error" | "fail" | "exception" | "loading" | "none";
name : string
}
type PositionItemType = {
value : "top" | "center" | "bottom";
name : string
}
export default {
data() {
return {
title: 'toast',
exeRet: ''
exeRet: '',
imageSelect:false,
maskSelect: false,
intervalSelect: 1500,
position_current:0,
position_enum: [
{ "value": "top", "name": "top: 居上显示" },
{ "value": "center", "name": "center: 居中显示" },
{ "value": "bottom", "name": "bottom: 居底显示" },
] as PositionItemType[],
icon_current:0,
icon_enum: [
{
value: 'success',
name: '显示成功图标',
},
{
value: 'error',
name: '显示错误图标',
},
// {
// value: 'fail',
// name: '显示错误图标',
// },
// {
// value: 'exception',
// name: '显示异常图标,此时title文本无长度显示',
// },
{
value: 'loading',
name: '显示加载图标',
},
{
value: 'none',
name: '不显示图标',
},
] as IconItemType[],
}
},
onLoad() {
...
...
@@ -41,59 +115,40 @@
jest_getWindowInfo() : GetWindowInfoResult {
return uni.getWindowInfo();
},
toast1Tap: function () {
uni.showToast({
title: "默认",
success: (res) => {
this.exeRet = "success:" + JSON.stringify(res)
},
fail: (res) => {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
radioChangeIcon(e : UniRadioGroupChangeEvent) {
for (let i = 0; i < this.icon_enum.length; i++) {
if (this.icon_enum[i].value === e.detail.value) {
this.icon_current = i;
break;
}
}
},
toastTapIconError: function () {
uni.showToast({
title: "默认",
icon: 'error',
success: (res) => {
this.exeRet = "success:" + JSON.stringify(res)
},
fail: (res) => {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
change_image_boolean: function (e : UniSwitchChangeEvent) {
this.imageSelect = e.detail.value
},
toast2Tap: function () {
uni.showToast({
title: "duration 3000",
duration: 3000,
success: (res) => {
this.exeRet = "success:" + JSON.stringify(res)
},
fail: (res) => {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
change_mask_boolean: function (e : UniSwitchChangeEvent) {
this.maskSelect = e.detail.value
},
toast3Tap: function () {
uni.showToast({
title: "loading",
icon: "loading",
duration: 5000,
success: (res) => {
this.exeRet = "success:" + JSON.stringify(res)
},
fail: (res) => {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
sliderChange(e : UniSliderChangeEvent) {
this.intervalSelect = e.detail.value
},
radioChangePosition(e : UniRadioGroupChangeEvent) {
for (let i = 0; i < this.position_enum.length; i++) {
if (this.position_enum[i].value === e.detail.value) {
this.position_current = i;
break;
}
}
},
toast
4
Tap: function () {
toast
1
Tap: function () {
uni.showToast({
title: "logo",
image: "/static/uni.png",
title: "默认",
icon: this.icon_enum[this.icon_current].value,
duration: this.intervalSelect,
image: this.imageSelect? "/static/uni.png" : null ,
mask: this.maskSelect,
success: (res) => {
console.log('success:',res)
this.exeRet = "success:" + JSON.stringify(res)
},
fail: (res) => {
...
...
@@ -102,10 +157,11 @@
})
},
// #ifdef APP
toast5Tap: function () {
toast2Tap: function () {
let positionValue = this.position_enum[this.position_current].value
uni.showToast({
title: "显示一段轻提示
"
,
position:
'bottom'
,
title: "显示一段轻提示
,position:" + positionValue
,
position:
positionValue
,
success: (res) => {
this.exeRet = "success:" + JSON.stringify(res)
},
...
...
@@ -121,3 +177,4 @@
}
}
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录