Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
93ac4d81
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6018
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看板
提交
93ac4d81
编写于
8月 14, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(picker-view.test.js): 补充测试例
上级
3c8c63df
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
91 addition
and
54 deletion
+91
-54
pages/component/picker-view/picker-view.test.js
pages/component/picker-view/picker-view.test.js
+70
-48
pages/component/picker-view/picker-view.uvue
pages/component/picker-view/picker-view.uvue
+21
-6
未找到文件。
pages/component/picker-view/picker-view.test.js
浏览文件 @
93ac4d81
function
getData
(
key
=
''
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
data
=
await
page
.
data
()
resolve
(
key
?
data
[
key
]
:
data
)
})
}
const
PAGE_PATH
=
'
/pages/component/picker-view/picker-view
'
const
PAGE_PATH
=
'
/pages/component/picker-view/picker-view
'
let
page
,
pickerViewEl
;
let
page
describe
(
'
PickerView.uvue
'
,
()
=>
{
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
await
page
.
waitFor
(
'
view
'
)
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
})
pickerViewEl
=
await
page
.
$
(
'
.picker-view
'
)
})
afterEach
(
async
()
=>
{
afterEach
(
async
()
=>
{
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
})
})
async
function
toScreenshot
(
imgName
)
{
const
image
=
await
program
.
screenshot
();
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
await
page
.
waitFor
(
500
);
}
describe
(
'
PickerView.uvue
'
,
()
=>
{
it
(
'
value
'
,
async
()
=>
{
it
(
'
value
'
,
async
()
=>
{
const
el
=
await
page
.
$
(
'
.picker-view
'
)
await
page
.
callMethod
(
'
setValue
'
)
await
page
.
callMethod
(
'
setValue
'
)
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
1000
)
const
newValue1
=
await
e
l
.
property
(
'
value
'
)
const
newValue1
=
await
pickerViewE
l
.
property
(
'
value
'
)
// TODO
// TODO
expect
(
newValue1
.
toString
()).
toEqual
(
'
0,0,0
'
)
expect
(
newValue1
.
toString
()).
toEqual
(
'
0,0,0
'
)
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-android
'
)
{
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-android
'
)
{
expect
(
await
getD
ata
(
'
result
'
)).
toEqual
([
0
,
0
,
0
])
expect
(
await
page
.
d
ata
(
'
result
'
)).
toEqual
([
0
,
0
,
0
])
}
}
await
page
.
callMethod
(
'
setValue1
'
)
await
page
.
callMethod
(
'
setValue1
'
)
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
1000
)
const
newValue2
=
await
e
l
.
property
(
'
value
'
)
const
newValue2
=
await
pickerViewE
l
.
property
(
'
value
'
)
// TODO
// TODO
expect
(
newValue2
.
toString
()).
toEqual
(
'
10,10,10
'
)
expect
(
newValue2
.
toString
()).
toEqual
(
'
10,10,10
'
)
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-android
'
)
{
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-android
'
)
{
expect
(
await
getD
ata
(
'
result
'
)).
toEqual
([
10
,
10
,
10
])
expect
(
await
page
.
d
ata
(
'
result
'
)).
toEqual
([
10
,
10
,
10
])
}
}
})
})
...
@@ -46,27 +46,59 @@ describe('PickerView.uvue', () => {
...
@@ -46,27 +46,59 @@ describe('PickerView.uvue', () => {
const
els1
=
await
page
.
$$
(
'
.picker-view-column
'
)
const
els1
=
await
page
.
$$
(
'
.picker-view-column
'
)
expect
(
els1
.
length
).
toBe
(
3
)
expect
(
els1
.
length
).
toBe
(
3
)
})
})
it
(
'
indicator-style
'
,
async
()
=>
{
it
(
'
indicator-style
'
,
async
()
=>
{
const
el
=
await
page
.
$
(
'
.picker-view
'
)
// App端动态设置indicatorStyle无效
const
indicatorStyle
=
"
height: 50px;border:#ff5500 solid 1px;background:rgba(182, 179, 255, 0.4);
"
await
page
.
setData
({
await
page
.
setData
({
indicatorStyle
:
'
height: 100px;
'
,
indicatorStyle
})
})
await
page
.
waitFor
(
500
)
await
page
.
waitFor
(
500
)
expect
(
await
el
.
attribute
(
'
indicatorStyle
'
)).
toBe
(
'
height: 100px;
'
)
expect
(
await
pickerViewEl
.
attribute
(
'
indicatorStyle
'
)).
toBe
(
indicatorStyle
)
await
toScreenshot
(
'
indicator-style
'
)
})
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
// indicator-class、mask-style、mask-class 仅web支持
it
(
'
indicator-class
'
,
async
()
=>
{
await
page
.
setData
({
indicatorStyle
:
""
,
//清空indicatorStyle
indicatorClass
:
"
indicator-test
"
,
//设置indicatorClass为indicator-test
})
})
it
(
'
mask-top-style
'
,
async
()
=>
{
expect
(
await
pickerViewEl
.
attribute
(
'
indicatorClass
'
)).
toBe
(
"
indicator-test
"
)
const
el
=
await
page
.
$
(
'
.picker-view
'
)
await
toScreenshot
(
'
indicator-class
'
)
await
page
.
setData
({
await
page
.
setData
({
maskTopStyle
:
'
background: #ffffff;
'
,
indicatorClass
:
""
,
//清空indicatorClass
})
})
it
(
'
mask-style
'
,
async
()
=>
{
const
maskStyle
=
"
background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));
"
await
page
.
setData
({
maskStyle
})
expect
(
await
pickerViewEl
.
attribute
(
'
maskStyle
'
)).
toBe
(
maskStyle
)
await
toScreenshot
(
'
mask-style
'
)
})
})
expect
(
await
el
.
attribute
(
'
mask-top-style
'
)).
toBe
(
'
background: #ffffff;
'
)
it
(
'
mask-class
'
,
async
()
=>
{
await
page
.
setData
({
maskClass
:
"
mask-test
"
})
expect
(
await
pickerViewEl
.
attribute
(
'
maskClass
'
)).
toBe
(
"
mask-test
"
)
await
toScreenshot
(
'
mask-class
'
)
})
})
it
(
'
mask-bottom-style
'
,
async
()
=>
{
return
const
el
=
await
page
.
$
(
'
.picker-view
'
)
}
it
(
'
mask-top-bottom-style
'
,
async
()
=>
{
// App端动态设置mask-top-style、mask-bottom-style无效
const
linearToTop
=
"
background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));
"
const
linearToBottom
=
"
background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));
"
await
page
.
setData
({
await
page
.
setData
({
maskBottomStyle
:
'
background: #ffffff;
'
,
maskTopStyle
:
linearToTop
,
maskBottomStyle
:
linearToBottom
,
})
})
expect
(
await
el
.
attribute
(
'
mask-bottom-style
'
)).
toBe
(
'
background: #ffffff;
'
)
await
page
.
waitFor
(
500
)
expect
(
await
pickerViewEl
.
attribute
(
'
mask-top-style
'
)).
toBe
(
linearToTop
)
expect
(
await
pickerViewEl
.
attribute
(
'
mask-bottom-style
'
)).
toBe
(
linearToBottom
)
await
page
.
waitFor
(
2000
)
await
toScreenshot
(
'
mask-top-bottom-style
'
)
})
})
it
(
'
reopen-picker-view-page
'
,
async
()
=>
{
it
(
'
reopen-picker-view-page
'
,
async
()
=>
{
...
@@ -86,16 +118,6 @@ describe('PickerView.uvue', () => {
...
@@ -86,16 +118,6 @@ describe('PickerView.uvue', () => {
})
})
it
(
'
trigger UniPickerViewChangeEvent
'
,
async
()
=>
{
it
(
'
trigger UniPickerViewChangeEvent
'
,
async
()
=>
{
// if web skip todo
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
)
{
expect
(
1
).
toBe
(
1
)
return
}
const
el
=
await
page
.
$
(
'
.picker-view
'
)
await
page
.
callMethod
(
'
setValue
'
)
await
page
.
callMethod
(
'
setValue
'
)
await
page
.
waitFor
(
1500
)
await
page
.
waitFor
(
1500
)
const
eventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
const
eventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
...
...
pages/component/picker-view/picker-view.uvue
浏览文件 @
93ac4d81
...
@@ -6,8 +6,13 @@
...
@@ -6,8 +6,13 @@
日期:{{year}}年{{month}}月{{day}}日
日期:{{year}}年{{month}}月{{day}}日
</view>
</view>
</view>
</view>
<picker-view class="picker-view" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
<picker-view class="picker-view" :value="value" @change="bindChange"
:mask-top-style="maskTopStyle" :mask-bottom-style="maskBottomStyle">
:indicator-style="indicatorStyle"
:indicator-class="indicatorClass"
:mask-style="maskStyle"
:mask-class="maskClass"
:mask-top-style="maskTopStyle"
:mask-bottom-style="maskBottomStyle">
<picker-view-column class="picker-view-column">
<picker-view-column class="picker-view-column">
<view class="item" v-for="(item,index) in years" :key="index"><text class="text">{{item}}年</text></view>
<view class="item" v-for="(item,index) in years" :key="index"><text class="text">{{item}}年</text></view>
</picker-view-column>
</picker-view-column>
...
@@ -53,6 +58,10 @@
...
@@ -53,6 +58,10 @@
value: [_year - 2000, _month - 1, _day - 1] as number[],
value: [_year - 2000, _month - 1, _day - 1] as number[],
result: [] as number[],
result: [] as number[],
indicatorStyle: 'height: 50px;',
indicatorStyle: 'height: 50px;',
// 自动化测试
indicatorClass: '',
maskStyle: '',
maskClass: '',
maskTopStyle: '',
maskTopStyle: '',
maskBottomStyle: ''
maskBottomStyle: ''
}
}
...
@@ -75,7 +84,6 @@
...
@@ -75,7 +84,6 @@
if (e.type === 'change') {
if (e.type === 'change') {
this.setEventCallbackNum(state.eventCallbackNum + 2)
this.setEventCallbackNum(state.eventCallbackNum + 2)
}
}
const val = e.detail.value
const val = e.detail.value
this.result = val
this.result = val
this.year = this.years[val[0]]
this.year = this.years[val[0]]
...
@@ -98,13 +106,20 @@
...
@@ -98,13 +106,20 @@
height: 320px;
height: 320px;
margin-top: 10px;
margin-top: 10px;
}
}
.item {
.item {
height: 50px;
height: 50px;
}
}
.text {
.text {
line-height: 50px;
line-height: 50px;
text-align: center;
text-align: center;
}
}
/* 自动化测试 */
.indicator-test{
height: 50px;
border:#0055ff solid 1px;
background:rgba(0, 170, 0, 0.4);
}
.mask-test{
background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));
}
</style>
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录