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