Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
14d13840
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
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看板
提交
14d13840
编写于
5月 31, 2024
作者:
辛宝Otto
🥊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 简化 radio/checkbox 事件测试方案
上级
a9b41a60
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
58 deletion
+33
-58
pages/component/checkbox/checkbox.test.js
pages/component/checkbox/checkbox.test.js
+2
-7
pages/component/checkbox/checkbox.uvue
pages/component/checkbox/checkbox.uvue
+12
-22
pages/component/radio/radio.test.js
pages/component/radio/radio.test.js
+9
-10
pages/component/radio/radio.uvue
pages/component/radio/radio.uvue
+10
-19
未找到文件。
pages/component/checkbox/checkbox.test.js
浏览文件 @
14d13840
...
...
@@ -11,11 +11,6 @@ let originEventCallbackNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/checkbox/checkbox
'
)
await
page
.
waitFor
(
2000
)
originEventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
})
beforeEach
(
async
()
=>
{
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
})
describe
(
'
Checkbox.uvue
'
,
()
=>
{
...
...
@@ -96,7 +91,7 @@ describe('Checkbox.uvue', () => {
const
element
=
await
page
.
$
(
'
.checkbox-item-0
'
)
await
element
.
tap
()
await
page
.
waitFor
(
1000
)
const
eventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
expect
(
eventCallbackNum
-
originEventCallbackNum
).
toBe
(
3
)
const
{
testEvent
}
=
await
page
.
data
(
)
expect
(
testEvent
).
toBe
(
true
)
})
})
pages/component/checkbox/checkbox.uvue
浏览文件 @
14d13840
<script>
import { state, setEventCallbackNum } from '@/store/index.uts'
type ItemType = {
value : string
name : string
...
...
@@ -40,15 +39,15 @@
checked: false,
},
] as ItemType[],
testEvent: false,
text: '未选中',
wrapText: 'uni-app x,终极跨平台方案\nuts,大一统语言',
value: [] as string[],
disabled: true,
checked: true,
color: '#007aff',
iconColor:
'#211cfe',
foreColor:'#ff0000',
color: '#007aff',
iconColor:
'#211cfe',
foreColor:
'#ff0000',
// 组件属性 autotest
checked_boolean: false,
disabled_boolean: false,
...
...
@@ -63,21 +62,10 @@
},
methods: {
// 自动化测试
getEventCallbackNum() : number {
return state.eventCallbackNum
},
// 自动化测试
setEventCallbackNum(num : number) {
setEventCallbackNum(num)
},
checkboxChange: function (e : UniCheckboxGroupChangeEvent) {
// 自动化测试
if ((e.target?.tagName ?? '') == 'CHECKBOX-GROUP') {
this.setEventCallbackNum(state.eventCallbackNum + 1)
}
if (e.type === 'change') {
this.setEventCallbackNum(state.eventCallbackNum + 2)
if ((e.target?.tagName ?? '') == 'CHECKBOX-GROUP' && e.type === 'change') {
this.testEvent = true
}
const selectedNames : string[] = []
...
...
@@ -152,8 +140,8 @@
</view>
<view>
<checkbox-group class="uni-flex uni-row checkbox-group" @change="testChange" style="flex-wrap: wrap">
<checkbox value="cb" :checked="checked" :color="color" :iconColor="iconColor"
:foreColor="foreColor"
style="margin-right: 15px" class="checkbox cb">选中
<checkbox value="cb" :checked="checked" :color="color" :iconColor="iconColor"
:foreColor="foreColor"
style="margin-right: 15px" class="checkbox cb">选中
</checkbox>
<checkbox value="cb1" style="margin-right: 15px" class="checkbox cb1">{{ text }}</checkbox>
<checkbox value="cb2" :disabled="disabled" class="checkbox cb2">禁用</checkbox>
...
...
@@ -183,8 +171,10 @@
<view class="uni-list uni-common-pl">
<checkbox-group @change="checkboxChange" class="checkbox-group" id="trigger-change">
<checkbox class="uni-list-cell uni-list-cell-pd checkbox" v-for="(item, index) in items" :key="item.value"
:value="item.value" :checked="item.checked"
:class="[index < items.length - 1 ? 'uni-list-cell-line' : '','checkbox-item-'+index]">
:value="item.value" :checked="item.checked" :class="[
index < items.length - 1 ? 'uni-list-cell-line' : '',
'checkbox-item-' + index,
]">
{{ item.name }}
</checkbox>
</checkbox-group>
...
...
pages/component/radio/radio.test.js
浏览文件 @
14d13840
...
...
@@ -10,10 +10,6 @@ let originEventCallbackNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/radio/radio
'
)
await
page
.
waitFor
(
2000
)
originEventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
})
beforeEach
(
async
()
=>
{
await
page
.
callMethod
(
'
setEventCallbackNum
'
,
0
)
})
describe
(
'
Radio.uvue
'
,
()
=>
{
...
...
@@ -71,11 +67,14 @@ describe('Radio.uvue', () => {
expect
(
await
radio
.
attribute
(
'
disabled
'
)).
toBe
(
false
+
''
)
})
it
(
'
trigger UniRadioGroupChangeEvent
'
,
async
()
=>
{
const
element
=
await
page
.
$
(
'
#trigger-change
'
)
await
element
.
tap
()
console
.
log
(
'
radio trigger change event
'
,
element
)
await
page
.
waitFor
(
1000
)
const
eventCallbackNum
=
await
page
.
callMethod
(
'
getEventCallbackNum
'
)
expect
(
eventCallbackNum
-
originEventCallbackNum
).
toBe
(
3
)
const
{
current
}
=
await
page
.
data
()
const
nextCurrent
=
current
==
0
?
1
:
0
const
elements
=
await
page
.
$$
(
'
.recommand
'
)
await
elements
[
nextCurrent
].
tap
()
await
page
.
waitFor
(
500
)
const
{
eventTest
}
=
await
page
.
data
()
expect
(
eventTest
).
toEqual
(
true
)
})
})
pages/component/radio/radio.uvue
浏览文件 @
14d13840
<script>
import { state, setEventCallbackNum } from '@/store/index.uts'
type ItemType = {
value : string
name : string
...
...
@@ -35,6 +34,7 @@
},
] as ItemType[],
current: 0,
eventTest: false,
value: '',
text: '未选中',
...
...
@@ -52,10 +52,17 @@
activeBorderColor_input: "",
iconColor_input: "#ffffff"
}
},
},
methods: {
radioChange(e : UniRadioGroupChangeEvent) {
// 自动化测试
console.log('test: radio event detail', e.target?.tagName, e.type)
if ((e.target?.tagName ?? '') == 'RADIO-GROUP' && e.type == 'change') {
this.eventTest = true
}
const selected = this.items.find((item) : boolean => {
return item.value == e.detail.value
})
...
...
@@ -64,23 +71,7 @@
title: '当前选中:' + selected?.name,
})
},
// 自动化测试
getEventCallbackNum() : number {
return state.eventCallbackNum
},
// 自动化测试
setEventCallbackNum(num : number) {
setEventCallbackNum(num)
},
testChange(e : UniRadioGroupChangeEvent) {
// 自动化测试
console.log('test: radio event detail', e.target?.tagName, e.type)
if ((e.target?.tagName ?? '') == 'RADIO-GROUP') {
this.setEventCallbackNum(state.eventCallbackNum + 1)
}
if (e.type === 'change') {
this.setEventCallbackNum(state.eventCallbackNum + 2)
}
this.value = e.detail.value
},
...
...
@@ -170,7 +161,7 @@
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChange" class="radio-group">
<radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.value"
<radio class="uni-list-cell uni-list-cell-pd radio
recommand
" v-for="(item, index) in items" :key="item.value"
:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
:checked="index === current">
{{ item.name }}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录