提交 99d19f1c 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

feat: 简化 radio/checkbox 事件测试方案

上级 39a4e932
...@@ -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)
}) })
}) })
<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>
......
...@@ -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)
}) })
}) })
<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.
先完成此消息的编辑!
想要评论请 注册