提交 bc09763e 编写于 作者: H hdx

form组件: 添加自动化测试

上级 efdded6b
const PAGE_PATH = '/pages/component/form/form'
const DEFAULT_NICK_NAME = 'hello'
const DEFAULT_GENDER = '0'
const DEFAULT_AGE = 18
const DEFAULT_SWITCH = true
const CHANGE_NICK_NAME = 'hello'
const CHANGE_GENDER = '0'
const CHANGE_AGE = 50
const CHANGE_SWITCH = false
describe('form', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('submit', async () => {
await page.setData({
nickname: CHANGE_NICK_NAME,
age: CHANGE_AGE,
switch: CHANGE_SWITCH
})
await page.waitFor(200)
const btnSubmit = await page.$('.btn-l')
await btnSubmit.tap()
await page.waitFor(200)
const {
formData
} = await page.data()
// expect(formData['nickname']).toBe(CHANGE_NICK_NAME)
expect(formData['gender']).toBe(CHANGE_GENDER)
expect(formData['loves'][0]).toBe('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)
const btnReset = await page.$('.btn-r')
await btnReset.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)
})
})
......@@ -5,16 +5,16 @@
<form @submit="onFormSubmit" @reset="onFormReset">
<view class="uni-form-item">
<view class="title">姓名</view>
<!-- <input class="uni-input" name="nickname" placeholder="请输入姓名" /> -->
<!-- <input class="uni-input" name="nickname" :value="nickname" placeholder="请输入姓名" /> -->
</view>
<view class="uni-form-item">
<view class="title">性别</view>
<radio-group name="gender" class="flex-row">
<view class="group-item">
<radio value="0" /><text>男</text>
<radio value="0" :checked="gender=='0'" /><text>男</text>
</view>
<view class="group-item">
<radio value="1" /><text>女</text>
<radio value="1" :checked="gender=='1'" /><text>女</text>
</view>
</radio-group>
</view>
......@@ -31,12 +31,12 @@
</view>
<view class="uni-form-item">
<view class="title">年龄</view>
<slider :value="18" name="age" :show-value="true"></slider>
<slider name="age" :value="age" :show-value="true"></slider>
</view>
<view class="uni-form-item">
<view class="title">保留选项</view>
<view>
<switch :checked="true" name="switch" />
<switch name="switch" :checked="switch" />
</view>
</view>
<view class="uni-btn-v flex-row">
......@@ -55,6 +55,10 @@
export default {
data() {
return {
nickname: '',
gender: '0',
age: 18,
switch: true,
formData: {} as UTSJSONObject
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册