Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
56ec9a7b
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看板
提交
56ec9a7b
编写于
11月 09, 2023
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
form组件:补充详细的自动化测试
上级
83d7497a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
32 deletion
+40
-32
pages/component/form/form.test.js
pages/component/form/form.test.js
+30
-23
pages/component/form/form.uvue
pages/component/form/form.uvue
+10
-9
未找到文件。
pages/component/form/form.test.js
浏览文件 @
56ec9a7b
const
PAGE_PATH
=
'
/pages/component/form/form
'
const
DEFAULT_NICK_NAME
=
'
hello
'
const
DEFAULT_NICK_NAME
=
''
const
DEFAULT_GENDER
=
'
0
'
const
DEFAULT_LOVES
=
[
'
0
'
]
const
DEFAULT_AGE
=
18
const
DEFAULT_SWITCH
=
true
const
CHANGE_NICK_NAME
=
'
hello
'
const
CHANGE_GENDER
=
'
0
'
const
CHANGE_GENDER
=
'
1
'
const
CHANGE_LOVES
=
[
'
0
'
,
'
1
'
]
const
CHANGE_AGE
=
50
const
CHANGE_SWITCH
=
false
...
...
@@ -17,14 +19,9 @@ describe('form', () => {
await
page
.
waitFor
(
500
)
})
it
(
'
submit
'
,
async
()
=>
{
await
page
.
setData
({
nickname
:
CHANGE_NICK_NAME
,
age
:
CHANGE_AGE
,
switch
:
CHANGE_SWITCH
})
await
page
.
waitFor
(
200
)
await
changeData
(
page
)
const
btnSubmit
=
await
page
.
$
(
'
.btn-
l
'
)
const
btnSubmit
=
await
page
.
$
(
'
.btn-
submit
'
)
await
btnSubmit
.
tap
()
await
page
.
waitFor
(
200
)
...
...
@@ -34,31 +31,41 @@ describe('form', () => {
expect
(
formData
[
'
nickname
'
]).
toBe
(
CHANGE_NICK_NAME
)
expect
(
formData
[
'
gender
'
]).
toBe
(
CHANGE_GENDER
)
expect
(
formData
[
'
loves
'
][
0
]).
toBe
(
'
1
'
)
expect
(
formData
[
'
loves
'
][
0
]).
toBe
(
CHANGE_LOVES
[
0
])
expect
(
formData
[
'
loves
'
][
1
]).
toBe
(
CHANGE_LOVES
[
1
])
expect
(
formData
[
'
age
'
]).
toBe
(
CHANGE_AGE
)
expect
(
formData
[
'
switch
'
]).
toBe
(
CHANGE_SWITCH
)
})
it
(
'
reset
'
,
async
()
=>
{
await
page
.
setData
({
nickname
:
CHANGE_NICK_NAME
,
age
:
CHANGE_AGE
,
switch
:
CHANGE_SWITCH
})
await
page
.
waitFor
(
100
)
await
changeData
(
page
)
const
btnReset
=
await
page
.
$
(
'
.btn-r
'
)
const
btnReset
=
await
page
.
$
(
'
.btn-r
eset
'
)
await
btnReset
.
tap
()
await
page
.
waitFor
(
100
)
const
btnSubmit
=
await
page
.
$
(
'
.btn-submit
'
)
await
btnSubmit
.
tap
()
await
page
.
waitFor
(
100
)
const
{
formData
}
=
await
page
.
data
()
// TODO
// expect(formData['nickname']).toBe(DEFAULT_NICK_NAME)
// expect(formData['gender']).toBe(undefined)
// expect(formData['loves'][0]).toBe(undefined)
// expect(formData['age']).toBe(undefined)
// expect(formData['switch']).toBe(undefined)
expect
(
formData
[
'
nickname
'
]).
toBe
(
DEFAULT_NICK_NAME
)
expect
(
formData
[
'
gender
'
]).
toBe
(
DEFAULT_GENDER
)
expect
(
formData
[
'
loves
'
][
0
]).
toBe
(
DEFAULT_LOVES
[
0
])
expect
(
formData
[
'
age
'
]).
toBe
(
DEFAULT_AGE
)
expect
(
formData
[
'
switch
'
]).
toBe
(
DEFAULT_SWITCH
)
})
})
async
function
changeData
(
page
)
{
await
page
.
setData
({
nickname
:
CHANGE_NICK_NAME
,
gender
:
CHANGE_GENDER
,
loves
:
CHANGE_LOVES
,
age
:
CHANGE_AGE
,
switch
:
CHANGE_SWITCH
})
await
page
.
waitFor
(
100
)
}
pages/component/form/form.uvue
浏览文件 @
56ec9a7b
...
...
@@ -11,10 +11,10 @@
<view class="title">性别</view>
<radio-group name="gender" class="flex-row">
<view class="group-item">
<radio
value="0" :checked="gender=='0'
" /><text>男</text>
<radio
:value="0" :checked="gender==0
" /><text>男</text>
</view>
<view class="group-item">
<radio
value="1" :checked="gender=='1'
" /><text>女</text>
<radio
:value="1" :checked="gender==1
" /><text>女</text>
</view>
</radio-group>
</view>
...
...
@@ -22,10 +22,10 @@
<view class="title">爱好</view>
<checkbox-group name="loves" class="flex-row">
<view class="group-item">
<checkbox value="0" /><text>读书</text>
<checkbox value="0"
:checked="loves.indexOf('0')>-1"
/><text>读书</text>
</view>
<view class="group-item">
<checkbox value="1" :checked="
true
" /><text>写字</text>
<checkbox value="1" :checked="
loves.indexOf('1')>-1
" /><text>写字</text>
</view>
</checkbox-group>
</view>
...
...
@@ -40,8 +40,8 @@
</view>
</view>
<view class="uni-btn-v flex-row">
<button class="btn btn-
l
" form-type="submit" type="primary">Submit</button>
<button class="btn btn-r" type="default" form-type="reset">Reset</button>
<button class="btn btn-
submit
" form-type="submit" type="primary">Submit</button>
<button class="btn btn-r
eset
" type="default" form-type="reset">Reset</button>
</view>
</form>
<view class="result">提交的表单数据</view>
...
...
@@ -56,8 +56,9 @@
data() {
return {
nickname: '',
gender:
'0'
,
gender:
0
,
age: 18,
loves: ['0'],
switch: true,
formData: {} as UTSJSONObject
}
...
...
@@ -105,11 +106,11 @@
flex: 1;
}
.btn-
l
{
.btn-
submit
{
margin-right: 5px;
}
.btn-r {
.btn-r
eset
{
margin-left: 5px;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录