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

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

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